Ignore:
Timestamp:
2010-10-22T14:57:03Z (16 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a7bfeb3
Parents:
954ea70
Message:

VHCD handles new methods

Not completely, though. Will finish later.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hw/bus/usb/hcd/virtual/connhost.c

    r954ea70 rb8a3cda  
    8484            &answer_data);
    8585       
    86         rc = async_data_write_start(trans->phone, buffer, len);
    87         if (rc != EOK) {
    88                 async_wait_for(req, NULL);
    89                 goto leave;
     86        if (len > 0) {
     87                rc = async_data_write_start(trans->phone, buffer, len);
     88                if (rc != EOK) {
     89                        async_wait_for(req, NULL);
     90                        goto leave;
     91                }
    9092        }
    9193       
     
    98100leave:
    99101        free(trans);
    100         free(buffer);
     102        if (buffer != NULL) {
     103                free(buffer);
     104        }
    101105}
    102106
    103107/** Handle data from host to function.
    104108 */
    105 static void handle_data_to_function(ipc_callid_t iid, ipc_call_t icall, int callback_phone)
    106 {
    107         usb_transfer_type_t transf_type = IPC_GET_ARG3(icall);
     109static void handle_data_to_function(ipc_callid_t iid, ipc_call_t icall,
     110    bool setup_transaction, int callback_phone)
     111{
     112        size_t expected_len = IPC_GET_ARG3(icall);
    108113        usb_target_t target = {
    109114                .address = IPC_GET_ARG1(icall),
     
    111116        };
    112117       
    113         dprintf("pretending transfer to function (dev=%d:%d, type=%s)",
    114             target.address, target.endpoint,
    115             usb_str_transfer_type(transf_type));
     118        dprintf("pretending transfer to function (dev=%d:%d)",
     119            target.address, target.endpoint);
    116120       
    117121        if (callback_phone == -1) {
     
    123127            = create_transaction_handle(callback_phone);
    124128       
    125         size_t len;
    126         void * buffer;
    127         int rc = async_data_write_accept(&buffer, false,
    128             1, USB_MAX_PAYLOAD_SIZE,
    129             0, &len);
    130        
    131         if (rc != EOK) {
    132                 ipc_answer_0(iid, rc);
    133                 return;
     129        size_t len = 0;
     130        void * buffer = NULL;
     131        if (expected_len > 0) {
     132                int rc = async_data_write_accept(&buffer, false,
     133                    1, USB_MAX_PAYLOAD_SIZE,
     134                    0, &len);
     135               
     136                if (rc != EOK) {
     137                        ipc_answer_0(iid, rc);
     138                        return;
     139                }
    134140        }
    135141       
     
    139145       
    140146        dprintf("adding transaction to HC", NAME);
    141         hc_add_transaction_to_device(transf_type, target,
     147        hc_add_transaction_to_device(setup_transaction, target,
    142148            buffer, len,
    143149            out_callback, trans);
     
    151157static void handle_data_from_function(ipc_callid_t iid, ipc_call_t icall, int callback_phone)
    152158{
    153         usb_transfer_type_t transf_type = IPC_GET_ARG3(icall);
    154159        usb_target_t target = {
    155160                .address = IPC_GET_ARG1(icall),
    156161                .endpoint = IPC_GET_ARG2(icall)
    157162        };
    158         size_t len = IPC_GET_ARG4(icall);
    159        
    160         dprintf("pretending transfer from function (dev=%d:%d, type=%s)",
    161             target.address, target.endpoint,
    162             usb_str_transfer_type(transf_type));
     163        size_t len = IPC_GET_ARG3(icall);
     164       
     165        dprintf("pretending transfer from function (dev=%d:%d)",
     166            target.address, target.endpoint);
    163167       
    164168        if (callback_phone == -1) {
     
    170174            = create_transaction_handle(callback_phone);
    171175       
    172         void * buffer = malloc(len);
     176        void * buffer = NULL;
     177        if (len > 0) {
     178                buffer = malloc(len);
     179        }
    173180       
    174181        transaction_details_t * trans = malloc(sizeof(transaction_details_t));
     
    177184       
    178185        dprintf("adding transaction to HC", NAME);
    179         hc_add_transaction_from_device(transf_type, target,
     186        hc_add_transaction_from_device(target,
    180187            buffer, len,
    181188            in_callback, trans);
     
    219226                       
    220227                        case IPC_M_USB_HCD_SEND_DATA:
    221                                 handle_data_to_function(callid, call, host_phone);
     228                                handle_data_to_function(callid, call,
     229                                    false, host_phone);
    222230                                break;
    223231                       
     
    230238                                break;
    231239                       
     240                       
     241                        case IPC_M_USB_HCD_INTERRUPT_OUT:
     242                                handle_data_to_function(callid, call,
     243                                    false, host_phone);
     244                                break;
     245                               
     246                        case IPC_M_USB_HCD_INTERRUPT_IN:
     247                                handle_data_from_function(callid, call, host_phone);
     248                                break;
     249                       
     250                        case IPC_M_USB_HCD_CONTROL_WRITE_SETUP:
     251                                handle_data_to_function(callid, call,
     252                                    true, host_phone);
     253                                break;
     254                               
     255                        case IPC_M_USB_HCD_CONTROL_WRITE_DATA:
     256                                handle_data_to_function(callid, call,
     257                                    false, host_phone);
     258                                break;
     259                               
     260                        case IPC_M_USB_HCD_CONTROL_WRITE_STATUS:
     261                                handle_data_from_function(callid, call, host_phone);
     262                                break;
     263                       
     264                        case IPC_M_USB_HCD_CONTROL_READ_SETUP:
     265                                handle_data_to_function(callid, call,
     266                                    true, host_phone);
     267                                break;
     268                               
     269                        case IPC_M_USB_HCD_CONTROL_READ_DATA:
     270                        case IPC_M_USB_HCD_CONTROL_READ_STATUS:
     271                       
    232272                        default:
    233273                                ipc_answer_0(callid, EINVAL);
Note: See TracChangeset for help on using the changeset viewer.