Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset a91fbb1 in mainline


Ignore:
Timestamp:
2011-04-15T20:53:17Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
2c2cbcf
Parents:
27b85d9 (diff), 8595577b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge development/ changes

Location:
uspace
Files:
2 added
18 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/batch.c

    r27b85d9 ra91fbb1  
    147147            data->ed->next);
    148148        size_t i = 0;
     149        instance->transfered_size = instance->buffer_size;
    149150        for (; i < tds; ++i) {
    150151                assert(data->tds[i] != NULL);
     
    156157                }
    157158                instance->error = td_error(data->tds[i]);
    158                 /* FIXME: calculate real transfered size */
    159                 instance->transfered_size = instance->buffer_size;
    160159                if (instance->error != EOK) {
    161160                        usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
     
    174173        assert(hcd_ep);
    175174        hcd_ep->td = data->tds[i];
     175        if (i > 0)
     176                instance->transfered_size -= td_remain_size(data->tds[i - 1]);
     177
    176178        /* Clear possible ED HALT */
    177179        data->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG;
     
    238240{
    239241        assert(instance);
    240         instance->next_step = usb_transfer_batch_call_in_and_dispose;
     242        /* We are data out, we are supposed to provide data */
     243        memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
     244        instance->next_step = usb_transfer_batch_call_out_and_dispose;
    241245        batch_data(instance);
    242         usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     246        usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance);
    243247}
    244248/*----------------------------------------------------------------------------*/
  • uspace/drv/ohci/hw_struct/transfer_descriptor.c

    r27b85d9 ra91fbb1  
    5252                instance->status |= togg[toggle] << TD_STATUS_T_SHIFT;
    5353        }
     54        if (dir == USB_DIRECTION_IN) {
     55                instance->status |= TD_STATUS_ROUND_FLAG;
     56        }
    5457        if (buffer != NULL) {
    5558                assert(size != 0);
  • uspace/drv/ohci/hw_struct/transfer_descriptor.h

    r27b85d9 ra91fbb1  
    5959#define TD_STATUS_T_0 (0x2)
    6060#define TD_STATUS_T_1 (0x3)
     61#define TD_STATUS_T_ED (0)
    6162#define TD_STATUS_EC_MASK (0x3) /* error count */
    6263#define TD_STATUS_EC_SHIFT (26)
     
    102103        return cc_to_rc(cc);
    103104}
     105
     106static inline size_t td_remain_size(td_t *instance)
     107{
     108        assert(instance);
     109        if (instance->cbp == 0)
     110                return 0;
     111        return instance->be - instance->cbp + 1;
     112}
    104113#endif
    105114/**
  • uspace/drv/ohci/root_hub.c

    r27b85d9 ra91fbb1  
    198198static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request);
    199199
    200 
     200static int process_interrupt(rh_t *instance, usb_transfer_batch_t * request,
     201    void * change_buffer, size_t buffe_size);
     202
     203static bool is_zeros(void * buffer, size_t size);
    201204
    202205
     
    213216        // set port power mode to no-power-switching
    214217        instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
    215 
     218        instance->unfinished_interrupt_transfer = NULL;
    216219        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
    217220        return EOK;
     
    233236                usb_log_info("Root hub got CONTROL packet\n");
    234237                opResult = process_ctrl_request(instance, request);
     238                usb_transfer_batch_finish_error(request, opResult);
    235239        } else if (request->ep->transfer_type == USB_TRANSFER_INTERRUPT) {
    236240                usb_log_info("Root hub got INTERRUPT packet\n");
    237241                void * buffer;
     242                size_t buffer_size;
    238243                create_interrupt_mask(instance, &buffer,
    239                         &(request->transfered_size));
    240                 memcpy(request->data_buffer, buffer,
    241                         request->transfered_size);
     244                        &buffer_size);
     245                if(is_zeros(buffer,buffer_size)){
     246                        usb_log_debug("no changes..");
     247                        instance->unfinished_interrupt_transfer=
     248                            request;
     249                        //will be finished later
     250                }else{
     251                        usb_log_debug("processing changes..");
     252                        process_interrupt(instance, request,
     253                            buffer, buffer_size);
     254                }
     255                free(buffer);
    242256                opResult = EOK;
    243257        } else {
    244258                opResult = EINVAL;
    245         }
    246         usb_transfer_batch_finish_error(request, opResult);
     259                usb_transfer_batch_finish_error(request, opResult);
     260        }
    247261        return EOK;
    248262}
     
    252266
    253267void rh_interrupt(rh_t *instance) {
    254         usb_log_info("Whoa whoa wait, I`m not supposed to receive any "
    255                 "interrupts, am I?\n");
    256         /* TODO: implement? */
     268        //usb_log_info("Whoa whoa wait, I`m not supposed to receive any "
     269        //      "interrupts, am I?\n");
     270        if(!instance->unfinished_interrupt_transfer){
     271                return;
     272        }
     273        size_t size;
     274        void * buffer;
     275        create_interrupt_mask(instance, &buffer,
     276                        &size);
     277        process_interrupt(instance,instance->unfinished_interrupt_transfer,
     278            buffer,size);
     279        free(buffer);
    257280}
    258281/*----------------------------------------------------------------------------*/
     
    859882        return opResult;
    860883}
     884/*----------------------------------------------------------------------------*/
     885
     886/**
     887 * process hanging interrupt request
     888 *
     889 * If an interrupt transfer has been received and there was no change,
     890 * the driver stores the transfer information and waits for change to occcur.
     891 * This routine is called when that happens and it finalizes the interrupt
     892 * transfer.
     893 *
     894 * @param instance hub instance
     895 * @param request batch request to be processed
     896 * @param change_buffer chages on hub
     897 * @param buffer_size size of change buffer
     898 *
     899 * @return
     900 */
     901static int process_interrupt(rh_t *instance, usb_transfer_batch_t * request,
     902    void * change_buffer, size_t buffe_size){
     903        create_interrupt_mask(instance, &change_buffer,
     904            &(request->transfered_size));
     905        memcpy(request->data_buffer, change_buffer,request->transfered_size);
     906        instance->unfinished_interrupt_transfer = NULL;
     907        usb_transfer_batch_finish_error(request, EOK);
     908        return EOK;
     909}
     910
     911/*----------------------------------------------------------------------------*/
     912
     913/**
     914 * return whether the buffer is full of zeros
     915 *
     916 * Convenience function.
     917 * @param buffer
     918 * @param size
     919 * @return
     920 */
     921static bool is_zeros(void * buffer, size_t size){
     922        if(!buffer) return true;
     923        if(!size) return true;
     924        size_t i;
     925        for(i=0;i<size;++i){
     926                if(((char*)buffer)[i])
     927                        return false;
     928        }
     929        return true;
     930}
    861931
    862932/**
  • uspace/drv/ohci/root_hub.h

    r27b85d9 ra91fbb1  
    5454        /** hubs descriptors */
    5555        usb_device_descriptors_t descriptors;
     56        /** interrupt transfer waiting for an actual interrupt to occur */
     57        usb_transfer_batch_t * unfinished_interrupt_transfer;
    5658} rh_t;
    5759
  • uspace/drv/usbhid/Makefile

    r27b85d9 ra91fbb1  
    4646        generic/hiddev.c \
    4747        mouse/mousedev.c \
     48        lgtch-ultrax/lgtch-ultrax.c \
    4849        $(STOLEN_LAYOUT_SOURCES)
    4950
  • uspace/drv/usbhid/kbd/kbddev.c

    r27b85d9 ra91fbb1  
    176176
    177177/*----------------------------------------------------------------------------*/
     178
     179static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
     180    uint8_t report_id, void *arg);
     181
     182static const usb_hid_report_in_callbacks_t usb_kbd_parser_callbacks = {
     183        .keyboard = usb_kbd_process_keycodes
     184};
     185
     186/*----------------------------------------------------------------------------*/
    178187/* Keyboard layouts                                                           */
    179188/*----------------------------------------------------------------------------*/
     
    630639{
    631640        assert(hid_dev->parser != NULL);
    632        
    633         usb_hid_report_in_callbacks_t *callbacks =
    634             (usb_hid_report_in_callbacks_t *)malloc(
    635                 sizeof(usb_hid_report_in_callbacks_t));
    636        
    637         callbacks->keyboard = usb_kbd_process_keycodes;
    638641
    639642        usb_log_debug("Calling usb_hid_parse_report() with "
     
    644647        usb_hid_report_path_t *path = usb_hid_report_path();
    645648        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    646         usb_hid_report_path_set_report_id(path, 0);
     649        //usb_hid_report_path_set_report_id(path, 0);
    647650       
    648651        int rc = usb_hid_parse_report(hid_dev->parser, buffer,
    649652            actual_size, path,
    650653            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    651             callbacks, hid_dev);
     654            &usb_kbd_parser_callbacks, hid_dev);
    652655
    653656        usb_hid_report_path_free(path);
  • uspace/drv/usbhid/main.c

    r27b85d9 ra91fbb1  
    7575static int usb_hid_try_add_device(usb_device_t *dev)
    7676{
     77        assert(dev != NULL);
     78       
    7779        /*
    7880         * Initialize device (get and process descriptors, get address, etc.)
     
    178180        usb_log_debug("usb_hid_add_device()\n");
    179181       
     182        if (dev == NULL) {
     183                usb_log_warning("Wrong parameter given for add_device().\n");
     184                return EINVAL;
     185        }
     186       
    180187        if (dev->interface_no < 0) {
    181188                usb_log_warning("Device is not a supported HID device.\n");
  • uspace/drv/usbhid/mouse/mousedev.c

    r27b85d9 ra91fbb1  
    157157static void usb_mouse_free(usb_mouse_t **mouse_dev)
    158158{
    159         if (mouse_dev == NULL || *mouse_dev == NULL) {
    160                 return;
    161         }
     159        assert(mouse_dev != NULL && *mouse_dev != NULL);
    162160       
    163161        // hangup phone to the console
    164         async_hangup((*mouse_dev)->console_phone);
     162        if ((*mouse_dev)->console_phone >= 0) {
     163                async_hangup((*mouse_dev)->console_phone);
     164        }
    165165       
    166166        free(*mouse_dev);
  • uspace/drv/usbhid/subdrivers.c

    r27b85d9 ra91fbb1  
    3737#include "usb/classes/hidut.h"
    3838
    39 static usb_hid_subdriver_usage_t path_kbd[] = {{USB_HIDUT_PAGE_KEYBOARD, 0}};
     39#include "lgtch-ultrax/lgtch-ultrax.h"
     40
     41static usb_hid_subdriver_usage_t path_kbd[] = {
     42        {USB_HIDUT_PAGE_KEYBOARD, 0},
     43        {0, 0}
     44};
     45
     46static usb_hid_subdriver_usage_t lgtch_path[] = {
     47        {0xc, 0},
     48        {0, 0}
     49};
    4050
    4151const usb_hid_subdriver_mapping_t usb_hid_subdrivers[] = {
    4252        {
    4353                path_kbd,
     54                -1,
     55                USB_HID_PATH_COMPARE_END
     56                | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     57                0,
     58                0,
     59                {
     60                        .init = usb_kbd_init,
     61                        .deinit = usb_kbd_deinit,
     62                        .poll = usb_kbd_polling_callback,
     63                        .poll_end = NULL
     64                },
     65               
     66        },
     67        {
     68                lgtch_path,
    4469                1,
    4570                USB_HID_PATH_COMPARE_END
    4671                | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    47                 NULL,
    48                 NULL,
     72                0x046d,
     73                0xc30e,
    4974                {
    50                         usb_kbd_init,
    51                         usb_kbd_deinit,
    52                         usb_kbd_polling_callback,
    53                         NULL
    54                 },
    55                
     75                        .init = NULL,
     76                        .deinit = NULL,
     77                        .poll = usb_lgtch_polling_callback,
     78                        .poll_end = NULL
     79                }
    5680        },
    57         {NULL, 0, 0, NULL, NULL, {NULL, NULL, NULL, NULL}}
     81        {NULL, -1, 0, 0, 0, {NULL, NULL, NULL, NULL}}
    5882};
    5983
  • uspace/drv/usbhid/subdrivers.h

    r27b85d9 ra91fbb1  
    5454typedef struct usb_hid_subdriver_mapping {
    5555        const usb_hid_subdriver_usage_t *usage_path;
    56         int path_size;
     56        int report_id;
    5757        int compare;
    58         const char *vendor_id;
    59         const char *product_id;
     58        uint16_t vendor_id;
     59        uint16_t product_id;
    6060        usb_hid_subdriver_t subdriver;
    6161} usb_hid_subdriver_mapping_t;
  • uspace/drv/usbhid/usbhid.c

    r27b85d9 ra91fbb1  
    6767static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev)
    6868{
    69         assert(hid_dev->subdriver_count == 0);
     69        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    7070       
    7171        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     
    9797static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev)
    9898{
    99         assert(hid_dev->subdriver_count == 0);
     99        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    100100       
    101101        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     
    127127static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev)
    128128{
    129         assert(hid_dev->subdriver_count == 0);
     129        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    130130       
    131131        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     
    164164
    165165static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
    166     const usb_hid_subdriver_usage_t *path, int path_size, int compare)
     166    const usb_hid_subdriver_mapping_t *mapping)
    167167{
    168168        assert(hid_dev != NULL);
    169         assert(path != NULL);
     169        assert(mapping != NULL);
    170170       
    171171        usb_hid_report_path_t *usage_path = usb_hid_report_path();
     
    174174                return false;
    175175        }
    176         int i;
    177         for (i = 0; i < path_size; ++i) {
     176        int i = 0;
     177        while (mapping->usage_path[i].usage != 0
     178            || mapping->usage_path[i].usage_page != 0) {
    178179                if (usb_hid_report_path_append_item(usage_path,
    179                     path[i].usage_page, path[i].usage) != EOK) {
     180                    mapping->usage_path[i].usage_page,
     181                    mapping->usage_path[i].usage) != EOK) {
    180182                        usb_log_debug("Failed to append to usage path.\n");
    181183                        usb_hid_report_path_free(usage_path);
    182184                        return false;
    183185                }
     186                ++i;
     187        }
     188       
     189        if (mapping->report_id >= 0) {
     190                usb_hid_report_path_set_report_id(usage_path,
     191                    mapping->report_id);
    184192        }
    185193       
    186194        assert(hid_dev->parser != NULL);
    187195       
    188         usb_log_debug("Compare flags: %d\n", compare);
     196        usb_log_debug("Compare flags: %d\n", mapping->compare);
    189197        size_t size = usb_hid_report_input_length(hid_dev->parser, usage_path,
    190             compare);
     198            mapping->compare);
    191199        usb_log_debug("Size of the input report: %d\n", size);
    192200       
     
    231239static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev)
    232240{
     241        assert(hid_dev != NULL);
     242       
    233243        const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS];
    234244       
    235245        int i = 0, count = 0;
    236246        const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i];
     247
     248        bool ids_matched;
     249        bool matched;
    237250       
    238251        while (count < USB_HID_MAX_SUBDRIVERS &&
    239252            (mapping->usage_path != NULL
    240             || mapping->vendor_id != NULL
    241             || mapping->product_id != NULL)) {
     253            || mapping->vendor_id != 0 || mapping->product_id != 0)) {
    242254                // check the vendor & product ID
    243                 if (mapping->vendor_id != NULL && mapping->product_id == NULL) {
    244                         usb_log_warning("Missing Product ID for Vendor ID %s\n",
     255                if (mapping->vendor_id != 0 && mapping->product_id == 0) {
     256                        usb_log_warning("Missing Product ID for Vendor ID %u\n",
    245257                            mapping->vendor_id);
    246258                        return EINVAL;
    247259                }
    248                 if (mapping->product_id != NULL && mapping->vendor_id == NULL) {
    249                         usb_log_warning("Missing Vendor ID for Product ID %s\n",
     260                if (mapping->product_id != 0 && mapping->vendor_id == 0) {
     261                        usb_log_warning("Missing Vendor ID for Product ID %u\n",
    250262                            mapping->product_id);
    251263                        return EINVAL;
    252264                }
    253265               
    254                 if (mapping->vendor_id != NULL) {
    255                         assert(mapping->product_id != NULL);
    256                         usb_log_debug("Comparing device against vendor ID %s"
    257                             " and product ID %s.\n", mapping->vendor_id,
     266                ids_matched = false;
     267                matched = false;
     268               
     269                if (mapping->vendor_id != 0) {
     270                        assert(mapping->product_id != 0);
     271                        usb_log_debug("Comparing device against vendor ID %u"
     272                            " and product ID %u.\n", mapping->vendor_id,
    258273                            mapping->product_id);
    259274                        if (usb_hid_ids_match(hid_dev, mapping)) {
    260                                 usb_log_debug("Matched.\n");
    261                                 subdrivers[count++] = &mapping->subdriver;
    262                                 // skip the checking of usage path
    263                                 goto next;
     275                                usb_log_debug("IDs matched.\n");
     276                                ids_matched = true;
    264277                        }
    265278                }
     
    267280                if (mapping->usage_path != NULL) {
    268281                        usb_log_debug("Comparing device against usage path.\n");
    269                         if (usb_hid_path_matches(hid_dev,
    270                             mapping->usage_path, mapping->path_size,
    271                             mapping->compare)) {
    272                                 subdrivers[count++] = &mapping->subdriver;
    273                         } else {
    274                                 usb_log_debug("Not matched.\n");
     282                        if (usb_hid_path_matches(hid_dev, mapping)) {
     283                                // does not matter if IDs were matched
     284                                matched = true;
    275285                        }
    276                 }
    277         next:
     286                } else {
     287                        // matched only if IDs were matched and there is no path
     288                        matched = ids_matched;
     289                }
     290               
     291                if (matched) {
     292                        subdrivers[count++] = &mapping->subdriver;
     293                }
     294               
    278295                mapping = &usb_hid_subdrivers[++i];
    279296        }
     
    287304static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
    288305{
     306        assert(hid_dev != NULL && dev != NULL);
     307       
    289308        int rc = EOK;
    290309       
     
    360379        rc = usb_hid_check_pipes(hid_dev, dev);
    361380        if (rc != EOK) {
    362                 usb_hid_free(&hid_dev);
     381                //usb_hid_free(&hid_dev);
    363382                return rc;
    364383        }
     
    368387        if (rc != EOK) {
    369388                usb_log_error("Failed to initialize report parser.\n");
    370                 usb_hid_free(&hid_dev);
     389                //usb_hid_free(&hid_dev);
    371390                return rc;
    372391        }
     
    386405                            " device.\n");
    387406                        fallback = true;
     407                        assert(hid_dev->subdrivers == NULL);
     408                        assert(hid_dev->subdriver_count == 0);
    388409                }
    389410        } else {
     
    426447                usb_log_error("No subdriver for handling this device could be"
    427448                    " initialized: %s.\n", str_error(rc));
    428                 usb_hid_free(&hid_dev);
     449                usb_log_debug("Subdriver count: %d\n",
     450                    hid_dev->subdriver_count);
     451                //usb_hid_free(&hid_dev);
    429452        } else {
    430453                bool ok = false;
     
    550573        }
    551574       
     575        usb_log_debug("Subdrivers: %p, subdriver count: %d\n",
     576            (*hid_dev)->subdrivers, (*hid_dev)->subdriver_count);
     577       
    552578        assert((*hid_dev)->subdrivers != NULL
    553579            || (*hid_dev)->subdriver_count == 0);
  • uspace/drv/usbhub/usbhub.c

    r27b85d9 ra91fbb1  
    105105        }
    106106
    107         usb_pipe_start_session(hub_info->control_pipe);
     107        //usb_pipe_start_session(hub_info->control_pipe);
    108108        //set hub configuration
    109109        opResult = usb_hub_set_configuration(hub_info);
     
    122122                return opResult;
    123123        }
    124         usb_pipe_end_session(hub_info->control_pipe);
    125 
    126         /// \TODO what is this?
    127         usb_log_debug("Creating `hub' function.\n");
     124        //usb_pipe_end_session(hub_info->control_pipe);
     125
     126
     127        usb_log_debug("Creating 'hub' function in DDF.\n");
    128128        ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
    129129            fun_exposed, "hub");
     
    153153bool hub_port_changes_callback(usb_device_t *dev,
    154154    uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) {
     155        usb_log_debug("hub_port_changes_callback\n");
    155156        usb_hub_info_t *hub = (usb_hub_info_t *) arg;
    156157
     
    217218        // get hub descriptor
    218219        usb_log_debug("creating serialized descriptor\n");
    219         void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
     220        //void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
     221        uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE];
    220222        usb_hub_descriptor_t * descriptor;
    221223        int opResult;
     
    235237        }
    236238        usb_log_debug2("deserializing descriptor\n");
    237         descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
     239        descriptor = usb_create_deserialized_hub_desriptor(
     240            serialized_descriptor);
    238241        if (descriptor == NULL) {
    239242                usb_log_warning("could not deserialize descriptor \n");
    240                 return opResult;
     243                return ENOMEM;
    241244        }
    242245        usb_log_debug("setting port count to %d\n", descriptor->ports_count);
    243246        hub_info->port_count = descriptor->ports_count;
    244247        /// \TODO this is not semantically correct
     248        bool is_power_switched =
     249            ((descriptor->hub_characteristics & 1) ==0);
     250        bool has_individual_port_powering =
     251            ((descriptor->hub_characteristics & 1) !=0);
    245252        hub_info->ports = malloc(
    246253            sizeof (usb_hub_port_t) * (hub_info->port_count + 1));
     
    249256                usb_hub_port_init(&hub_info->ports[port]);
    250257        }
    251         for (port = 0; port < hub_info->port_count; port++) {
    252                 opResult = usb_hub_set_port_feature(hub_info->control_pipe,
    253                     port+1, USB_HUB_FEATURE_PORT_POWER);
    254                 if (opResult != EOK) {
    255                         usb_log_error("cannot power on port %d;  %d\n",
    256                             port+1, opResult);
    257                 }
     258        if(is_power_switched){
     259                usb_log_debug("is_power_switched\n");
     260                if(has_individual_port_powering){
     261                        usb_log_debug("has_individual_port_powering\n");
     262                        for (port = 0; port < hub_info->port_count; port++) {
     263                                opResult = usb_hub_set_port_feature(hub_info->control_pipe,
     264                                    port+1, USB_HUB_FEATURE_PORT_POWER);
     265                                if (opResult != EOK) {
     266                                        usb_log_error("cannot power on port %d;  %d\n",
     267                                            port+1, opResult);
     268                                }
     269                        }
     270                }else{
     271                        usb_log_debug("!has_individual_port_powering\n");
     272                        opResult = usb_hub_set_feature(hub_info->control_pipe,
     273                            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
     274                        if (opResult != EOK) {
     275                                usb_log_error("cannot power hub;  %d\n",
     276                                  opResult);
     277                        }
     278                }
     279        }else{
     280                usb_log_debug("!is_power_switched\n");
    258281        }
    259282        usb_log_debug2("freeing data\n");
    260         free(serialized_descriptor);
    261         free(descriptor->devices_removable);
     283        //free(serialized_descriptor);
     284        //free(descriptor->devices_removable);
    262285        free(descriptor);
    263286        return EOK;
     
    321344         * auto destruction, this could work better.
    322345         */
    323         int rc = usb_pipe_start_session(hub_info->control_pipe);
     346        int rc = usb_hc_connection_open(&hub_info->connection);
    324347        if (rc != EOK) {
    325                 usb_log_error("Failed to start session on control pipe: %s.\n",
    326                     str_error(rc));
    327                 return rc;
    328         }
    329         rc = usb_hc_connection_open(&hub_info->connection);
    330         if (rc != EOK) {
    331                 usb_pipe_end_session(hub_info->control_pipe);
     348                //usb_pipe_end_session(hub_info->control_pipe);
    332349                usb_log_error("Failed to open connection to HC: %s.\n",
    333350                    str_error(rc));
  • uspace/drv/usbhub/usbhub_private.h

    r27b85d9 ra91fbb1  
    113113
    114114        usb_device_request_setup_packet_t clear_request = {
    115                 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
     115                .request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE,
    116116                .request = USB_DEVREQ_SET_FEATURE,
    117117                .length = 0,
     
    166166}
    167167
    168 /**
    169  * create uint8_t array with serialized descriptor
    170  *
    171  * @param descriptor
    172  * @return newly created serializd descriptor pointer
    173  */
    174 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor);
    175168
    176 /**
    177  * create deserialized desriptor structure out of serialized descriptor
    178  *
    179  * The serialized descriptor must be proper usb hub descriptor,
    180  * otherwise an eerror might occur.
    181  *
    182  * @param sdescriptor serialized descriptor
    183  * @return newly created deserialized descriptor pointer
    184  */
    185 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
     169void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t * descriptor);
     170
     171void usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor,
     172    void * serialized_descriptor);
     173
     174usb_hub_descriptor_t * usb_create_deserialized_hub_desriptor(
     175    void * serialized_descriptor);
     176
     177void usb_deserialize_hub_desriptor(void * serialized_descriptor,
     178    usb_hub_descriptor_t * descriptor);
    186179
    187180
  • uspace/drv/usbhub/utils.c

    r27b85d9 ra91fbb1  
    5656//hub descriptor utils
    5757
    58 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) {
     58/**
     59 * create uint8_t array with serialized descriptor
     60 *
     61 * @param descriptor
     62 * @return newly created serializd descriptor pointer
     63 */
     64void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t * descriptor) {
    5965        //base size
    6066        size_t size = 7;
     
    6470        uint8_t * result = malloc(size);
    6571        //size
    66         result[0] = size;
     72        if(result)
     73                usb_serialize_hub_descriptor(descriptor,result);
     74        return result;
     75}
     76
     77/**
     78 * serialize descriptor into given buffer
     79 *
     80 * The buffer size is not checked.
     81 * @param descriptor
     82 * @param serialized_descriptor
     83 */
     84void usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor,
     85    void * serialized_descriptor) {
     86        //base size
     87        uint8_t * sdescriptor = serialized_descriptor;
     88        size_t size = 7;
     89        //variable size according to port count
     90        size_t var_size = (descriptor->ports_count+7)/8;
     91        size += 2 * var_size;
     92        //size
     93        sdescriptor[0] = size;
    6794        //descriptor type
    68         result[1] = USB_DESCTYPE_HUB;
    69         result[2] = descriptor->ports_count;
     95        sdescriptor[1] = USB_DESCTYPE_HUB;
     96        sdescriptor[2] = descriptor->ports_count;
    7097        /// @fixme handling of endianness??
    71         result[3] = descriptor->hub_characteristics / 256;
    72         result[4] = descriptor->hub_characteristics % 256;
    73         result[5] = descriptor->pwr_on_2_good_time;
    74         result[6] = descriptor->current_requirement;
     98        sdescriptor[3] = descriptor->hub_characteristics / 256;
     99        sdescriptor[4] = descriptor->hub_characteristics % 256;
     100        sdescriptor[5] = descriptor->pwr_on_2_good_time;
     101        sdescriptor[6] = descriptor->current_requirement;
    75102
    76103        size_t i;
    77104        for (i = 0; i < var_size; ++i) {
    78                 result[7 + i] = descriptor->devices_removable[i];
     105                sdescriptor[7 + i] = descriptor->devices_removable[i];
    79106        }
    80107        for (i = 0; i < var_size; ++i) {
    81                 result[7 + var_size + i] = 255;
     108                sdescriptor[7 + var_size + i] = 255;
    82109        }
    83         return result;
    84110}
    85111
    86 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(
     112
     113/**
     114 * create deserialized desriptor structure out of serialized descriptor
     115 *
     116 * The serialized descriptor must be proper usb hub descriptor,
     117 * otherwise an eerror might occur.
     118 *
     119 * @param sdescriptor serialized descriptor
     120 * @return newly created deserialized descriptor pointer
     121 */
     122usb_hub_descriptor_t * usb_create_deserialized_hub_desriptor(
    87123void * serialized_descriptor) {
    88124        uint8_t * sdescriptor = serialized_descriptor;
     
    95131
    96132        usb_hub_descriptor_t * result = malloc(sizeof(usb_hub_descriptor_t));
    97        
     133        if(result)
     134                usb_deserialize_hub_desriptor(serialized_descriptor,result);
     135        return result;
     136}
    98137
    99         result->ports_count = sdescriptor[2];
     138/**
     139 * deserialize descriptor into given pointer
     140 *
     141 * @param serialized_descriptor
     142 * @param descriptor
     143 * @return
     144 */
     145void usb_deserialize_hub_desriptor(
     146void * serialized_descriptor, usb_hub_descriptor_t * descriptor) {
     147        uint8_t * sdescriptor = serialized_descriptor;
     148        descriptor->ports_count = sdescriptor[2];
    100149        /// @fixme handling of endianness??
    101         result->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3];
    102         result->pwr_on_2_good_time = sdescriptor[5];
    103         result->current_requirement = sdescriptor[6];
    104         size_t var_size = (result->ports_count+7) / 8;
    105         result->devices_removable = (uint8_t*) malloc(var_size);
     150        descriptor->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3];
     151        descriptor->pwr_on_2_good_time = sdescriptor[5];
     152        descriptor->current_requirement = sdescriptor[6];
     153        size_t var_size = (descriptor->ports_count+7) / 8;
     154        //descriptor->devices_removable = (uint8_t*) malloc(var_size);
    106155
    107156        size_t i;
    108157        for (i = 0; i < var_size; ++i) {
    109                 result->devices_removable[i] = sdescriptor[7 + i];
     158                descriptor->devices_removable[i] = sdescriptor[7 + i];
    110159        }
    111         return result;
    112160}
    113 
    114 
    115161
    116162/**
  • uspace/lib/usb/include/usb/classes/hub.h

    r27b85d9 ra91fbb1  
    152152            maximum of 255 ports).
    153153     */
    154     uint8_t * devices_removable;
     154    uint8_t devices_removable[32];
    155155
    156156    /**
  • uspace/lib/usb/src/hidreport.c

    r27b85d9 ra91fbb1  
    119119        uint16_t length =  hid_desc->report_desc_info.length;
    120120        size_t actual_size = 0;
    121        
    122         /*
    123          * Start session for the control transfer.
    124          */
    125         int sess_rc = usb_pipe_start_session(&dev->ctrl_pipe);
    126         if (sess_rc != EOK) {
    127                 usb_log_warning("Failed to start a session: %s.\n",
    128                     str_error(sess_rc));
    129                 return sess_rc;
    130         }
    131121
    132122        /*
     
    162152                    "%u)\n", actual_size, length);
    163153                return EINVAL;
    164         }
    165        
    166         /*
    167          * End session for the control transfer.
    168          */
    169         sess_rc = usb_pipe_end_session(&dev->ctrl_pipe);
    170         if (sess_rc != EOK) {
    171                 usb_log_warning("Failed to end a session: %s.\n",
    172                     str_error(sess_rc));
    173                 free(*report_desc);
    174                 *report_desc = NULL;
    175                 return sess_rc;
    176154        }
    177155       
  • uspace/lib/usb/src/hidreq.c

    r27b85d9 ra91fbb1  
    5656 * @retval EOK if successful.
    5757 * @retval EINVAL if no HID device is given.
    58  * @return Other value inherited from one of functions
    59  *         usb_pipe_start_session(), usb_pipe_end_session(),
    60  *         usb_control_request_set().
     58 * @return Other value inherited from function usb_control_request_set().
    6159 */
    6260int usbhid_req_set_report(usb_pipe_t *ctrl_pipe, int iface_no,
     
    7977         */
    8078       
    81         int rc, sess_rc;
    82        
    83         sess_rc = usb_pipe_start_session(ctrl_pipe);
    84         if (sess_rc != EOK) {
    85                 usb_log_warning("Failed to start a session: %s.\n",
    86                     str_error(sess_rc));
    87                 return sess_rc;
    88         }
     79        int rc;
    8980       
    9081        uint16_t value = 0;
     
    9788            USB_HIDREQ_SET_REPORT, value, iface_no, buffer, buf_size);
    9889
    99         sess_rc = usb_pipe_end_session(ctrl_pipe);
    100 
    101         if (rc != EOK) {
    102                 usb_log_warning("Error sending output report to the keyboard: "
    103                     "%s.\n", str_error(rc));
    104                 return rc;
    105         }
    106 
    107         if (sess_rc != EOK) {
    108                 usb_log_warning("Error closing session: %s.\n",
    109                     str_error(sess_rc));
    110                 return sess_rc;
     90        if (rc != EOK) {
     91                usb_log_warning("Error sending output report to the keyboard: "
     92                    "%s.\n", str_error(rc));
     93                return rc;
    11194        }
    11295       
     
    123106 * @retval EOK if successful.
    124107 * @retval EINVAL if no HID device is given.
    125  * @return Other value inherited from one of functions
    126  *         usb_pipe_start_session(), usb_pipe_end_session(),
    127  *         usb_control_request_set().
     108 * @return Other value inherited from function usb_control_request_set().
    128109 */
    129110int usbhid_req_set_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
     
    146127         */
    147128       
    148         int rc, sess_rc;
    149        
    150         sess_rc = usb_pipe_start_session(ctrl_pipe);
    151         if (sess_rc != EOK) {
    152                 usb_log_warning("Failed to start a session: %s.\n",
    153                     str_error(sess_rc));
    154                 return sess_rc;
    155         }
     129        int rc;
    156130
    157131        usb_log_debug("Sending Set_Protocol request to the device ("
     
    162136            USB_HIDREQ_SET_PROTOCOL, protocol, iface_no, NULL, 0);
    163137
    164         sess_rc = usb_pipe_end_session(ctrl_pipe);
    165 
    166         if (rc != EOK) {
    167                 usb_log_warning("Error sending output report to the keyboard: "
    168                     "%s.\n", str_error(rc));
    169                 return rc;
    170         }
    171 
    172         if (sess_rc != EOK) {
    173                 usb_log_warning("Error closing session: %s.\n",
    174                     str_error(sess_rc));
    175                 return sess_rc;
     138        if (rc != EOK) {
     139                usb_log_warning("Error sending output report to the keyboard: "
     140                    "%s.\n", str_error(rc));
     141                return rc;
    176142        }
    177143       
     
    189155 * @retval EOK if successful.
    190156 * @retval EINVAL if no HID device is given.
    191  * @return Other value inherited from one of functions
    192  *         usb_pipe_start_session(), usb_pipe_end_session(),
    193  *         usb_control_request_set().
     157 * @return Other value inherited from function usb_control_request_set().
    194158 */
    195159int usbhid_req_set_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t duration)
     
    211175         */
    212176       
    213         int rc, sess_rc;
    214        
    215         sess_rc = usb_pipe_start_session(ctrl_pipe);
    216         if (sess_rc != EOK) {
    217                 usb_log_warning("Failed to start a session: %s.\n",
    218                     str_error(sess_rc));
    219                 return sess_rc;
    220         }
     177        int rc;
    221178
    222179        usb_log_debug("Sending Set_Idle request to the device ("
     
    229186            USB_HIDREQ_SET_IDLE, value, iface_no, NULL, 0);
    230187
    231         sess_rc = usb_pipe_end_session(ctrl_pipe);
    232 
    233         if (rc != EOK) {
    234                 usb_log_warning("Error sending output report to the keyboard: "
    235                     "%s.\n", str_error(rc));
    236                 return rc;
    237         }
    238 
    239         if (sess_rc != EOK) {
    240                 usb_log_warning("Error closing session: %s.\n",
    241                     str_error(sess_rc));
    242                 return sess_rc;
     188        if (rc != EOK) {
     189                usb_log_warning("Error sending output report to the keyboard: "
     190                    "%s.\n", str_error(rc));
     191                return rc;
    243192        }
    244193       
     
    259208 * @retval EOK if successful.
    260209 * @retval EINVAL if no HID device is given.
    261  * @return Other value inherited from one of functions
    262  *         usb_pipe_start_session(), usb_pipe_end_session(),
    263  *         usb_control_request_set().
     210 * @return Other value inherited from function usb_control_request_set().
    264211 */
    265212int usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no,
     
    283230         */
    284231       
    285         int rc, sess_rc;
    286        
    287         sess_rc = usb_pipe_start_session(ctrl_pipe);
    288         if (sess_rc != EOK) {
    289                 usb_log_warning("Failed to start a session: %s.\n",
    290                     str_error(sess_rc));
    291                 return sess_rc;
    292         }
     232        int rc;
    293233
    294234        uint16_t value = 0;
     
    302242            actual_size);
    303243
    304         sess_rc = usb_pipe_end_session(ctrl_pipe);
    305 
    306         if (rc != EOK) {
    307                 usb_log_warning("Error sending output report to the keyboard: "
    308                     "%s.\n", str_error(rc));
    309                 return rc;
    310         }
    311 
    312         if (sess_rc != EOK) {
    313                 usb_log_warning("Error closing session: %s.\n",
    314                     str_error(sess_rc));
    315                 return sess_rc;
     244        if (rc != EOK) {
     245                usb_log_warning("Error sending output report to the keyboard: "
     246                    "%s.\n", str_error(rc));
     247                return rc;
    316248        }
    317249       
     
    328260 * @retval EOK if successful.
    329261 * @retval EINVAL if no HID device is given.
    330  * @return Other value inherited from one of functions
    331  *         usb_pipe_start_session(), usb_pipe_end_session(),
    332  *         usb_control_request_set().
     262 * @return Other value inherited from function usb_control_request_set().
    333263 */
    334264int usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
     
    351281         */
    352282       
    353         int rc, sess_rc;
    354        
    355         sess_rc = usb_pipe_start_session(ctrl_pipe);
    356         if (sess_rc != EOK) {
    357                 usb_log_warning("Failed to start a session: %s.\n",
    358                     str_error(sess_rc));
    359                 return sess_rc;
    360         }
     283        int rc;
    361284
    362285        usb_log_debug("Sending Get_Protocol request to the device ("
     
    370293            USB_HIDREQ_GET_PROTOCOL, 0, iface_no, buffer, 1, &actual_size);
    371294
    372         sess_rc = usb_pipe_end_session(ctrl_pipe);
    373 
    374         if (rc != EOK) {
    375                 usb_log_warning("Error sending output report to the keyboard: "
    376                     "%s.\n", str_error(rc));
    377                 return rc;
    378         }
    379 
    380         if (sess_rc != EOK) {
    381                 usb_log_warning("Error closing session: %s.\n",
    382                     str_error(sess_rc));
    383                 return sess_rc;
     295        if (rc != EOK) {
     296                usb_log_warning("Error sending output report to the keyboard: "
     297                    "%s.\n", str_error(rc));
     298                return rc;
    384299        }
    385300       
     
    427342         */
    428343       
    429         int rc, sess_rc;
    430        
    431         sess_rc = usb_pipe_start_session(ctrl_pipe);
    432         if (sess_rc != EOK) {
    433                 usb_log_warning("Failed to start a session: %s.\n",
    434                     str_error(sess_rc));
    435                 return sess_rc;
    436         }
     344        int rc;
    437345
    438346        usb_log_debug("Sending Get_Idle request to the device ("
     
    448356            &actual_size);
    449357
    450         sess_rc = usb_pipe_end_session(ctrl_pipe);
    451 
    452         if (rc != EOK) {
    453                 usb_log_warning("Error sending output report to the keyboard: "
    454                     "%s.\n", str_error(rc));
    455                 return rc;
    456         }
    457 
    458         if (sess_rc != EOK) {
    459                 usb_log_warning("Error closing session: %s.\n",
    460                     str_error(sess_rc));
    461                 return sess_rc;
     358        if (rc != EOK) {
     359                usb_log_warning("Error sending output report to the keyboard: "
     360                    "%s.\n", str_error(rc));
     361                return rc;
    462362        }
    463363       
Note: See TracChangeset for help on using the changeset viewer.