Changeset 8a64320e in mainline for uspace/drv/nic/ar9271/ath_usb.c
- Timestamp:
- 2015-04-23T23:40:14Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- dcba819
- Parents:
- 09044cb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/ar9271/ath_usb.c
r09044cb r8a64320e 36 36 #include <usb/debug.h> 37 37 #include <malloc.h> 38 39 38 #include "ath_usb.h" 40 39 41 static int ath_usb_send_ctrl_message(ath_t *ath, void *buffer, 42 size_t buffer_size); 43 44 static int ath_usb_read_ctrl_message(ath_t *ath, void *buffer, 45 size_t buffer_size, size_t *transferred_size); 46 47 static int ath_usb_send_data_message(ath_t *ath, void *buffer, 48 size_t buffer_size); 49 50 static int ath_usb_read_data_message(ath_t *ath, void *buffer, 51 size_t buffer_size, size_t *transferred_size); 40 static int ath_usb_send_ctrl_message(ath_t *, void *, size_t); 41 static int ath_usb_read_ctrl_message(ath_t *, void *, size_t, size_t *); 42 static int ath_usb_send_data_message(ath_t *, void *, size_t); 43 static int ath_usb_read_data_message(ath_t *, void *, size_t, size_t *); 52 44 53 45 static ath_ops_t ath_usb_ops = { … … 58 50 }; 59 51 60 /** 61 * Initialize Atheros WiFi USB device. 62 * 52 /** Initialize Atheros WiFi USB device. 53 * 63 54 * @param ath Generic Atheros WiFi device structure. 64 * @param usb_device Connected USB device.65 * 55 * @param usb_device Connected USB device. 56 * 66 57 * @return EOK if succeed, negative error code otherwise. 58 * 67 59 */ 68 60 int ath_usb_init(ath_t *ath, usb_device_t *usb_device) … … 92 84 } 93 85 94 /** 95 * Send control message. 96 * 97 * @param ath Generic Atheros WiFi device structure. 98 * @param buffer Buffer with data to send. 86 /** Send control message. 87 * 88 * @param ath Generic Atheros WiFi device structure. 89 * @param buffer Buffer with data to send. 99 90 * @param buffer_size Buffer size. 100 * 91 * 101 92 * @return EOK if succeed, negative error code otherwise. 93 * 102 94 */ 103 static int ath_usb_send_ctrl_message(ath_t *ath, void *buffer, 104 95 static int ath_usb_send_ctrl_message(ath_t *ath, void *buffer, 96 size_t buffer_size) 105 97 { 106 98 ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data; 107 usb_pipe_t *pipe = 108 &ath_usb->usb_device->pipes[ath_usb->output_ctrl_pipe_number]. 109 pipe; 99 usb_pipe_t *pipe = 100 &ath_usb->usb_device->pipes[ath_usb->output_ctrl_pipe_number].pipe; 110 101 111 102 return usb_pipe_write(pipe, buffer, buffer_size); 112 103 } 113 104 114 /** 115 * Read control message. 116 * 117 * @param ath Generic Atheros WiFi device structure. 118 * @param buffer Buffer with data to send. 119 * @param buffer_size Buffer size. 105 /** Read control message. 106 * 107 * @param ath Generic Atheros WiFi device structure. 108 * @param buffer Buffer with data to send. 109 * @param buffer_size Buffer size. 120 110 * @param transferred_size Real size of read data. 121 * 111 * 122 112 * @return EOK if succeed, negative error code otherwise. 113 * 123 114 */ 124 static int ath_usb_read_ctrl_message(ath_t *ath, void *buffer, 125 115 static int ath_usb_read_ctrl_message(ath_t *ath, void *buffer, 116 size_t buffer_size, size_t *transferred_size) 126 117 { 127 118 ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data; 128 usb_pipe_t *pipe = 129 &ath_usb->usb_device->pipes[ath_usb->input_ctrl_pipe_number]. 130 pipe; 119 usb_pipe_t *pipe = 120 &ath_usb->usb_device->pipes[ath_usb->input_ctrl_pipe_number].pipe; 131 121 132 122 return usb_pipe_read(pipe, buffer, buffer_size, transferred_size); 133 123 } 134 124 135 /** 136 * Send data message. 137 * 138 * @param ath Generic Atheros WiFi device structure. 139 * @param buffer Buffer with data to send. 125 /** Send data message. 126 * 127 * @param ath Generic Atheros WiFi device structure. 128 * @param buffer Buffer with data to send. 140 129 * @param buffer_size Buffer size. 141 * 130 * 142 131 * @return EOK if succeed, negative error code otherwise. 132 * 143 133 */ 144 static int ath_usb_send_data_message(ath_t *ath, void *buffer, 145 134 static int ath_usb_send_data_message(ath_t *ath, void *buffer, 135 size_t buffer_size) 146 136 { 147 size_t complete_buffer_size = buffer_size + 148 137 size_t complete_buffer_size = buffer_size + 138 sizeof(ath_usb_data_header_t); 149 139 void *complete_buffer = malloc(complete_buffer_size); 150 memcpy(complete_buffer + sizeof(ath_usb_data_header_t), 151 140 memcpy(complete_buffer + sizeof(ath_usb_data_header_t), 141 buffer, buffer_size); 152 142 153 ath_usb_data_header_t *data_header = 154 143 ath_usb_data_header_t *data_header = 144 (ath_usb_data_header_t *) complete_buffer; 155 145 data_header->length = host2uint16_t_le(buffer_size); 156 146 data_header->tag = host2uint16_t_le(TX_TAG); 157 147 158 148 ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data; 159 usb_pipe_t *pipe = 160 &ath_usb->usb_device->pipes[ath_usb->output_data_pipe_number]. 161 pipe; 149 usb_pipe_t *pipe = 150 &ath_usb->usb_device->pipes[ath_usb->output_data_pipe_number].pipe; 162 151 163 int ret_val = usb_pipe_write(pipe, complete_buffer, 164 152 int ret_val = usb_pipe_write(pipe, complete_buffer, 153 complete_buffer_size); 165 154 166 155 free(complete_buffer); … … 169 158 } 170 159 171 /** 172 * Read data message. 173 * 174 * @param ath Generic Atheros WiFi device structure. 175 * @param buffer Buffer with data to send. 176 * @param buffer_size Buffer size. 160 /** Read data message. 161 * 162 * @param ath Generic Atheros WiFi device structure. 163 * @param buffer Buffer with data to send. 164 * @param buffer_size Buffer size. 177 165 * @param transferred_size Real size of read data. 178 * 166 * 179 167 * @return EOK if succeed, negative error code otherwise. 168 * 180 169 */ 181 static int ath_usb_read_data_message(ath_t *ath, void *buffer, 182 170 static int ath_usb_read_data_message(ath_t *ath, void *buffer, 171 size_t buffer_size, size_t *transferred_size) 183 172 { 184 173 ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data; 185 usb_pipe_t *pipe = 186 &ath_usb->usb_device->pipes[ath_usb->input_data_pipe_number]. 187 pipe; 174 usb_pipe_t *pipe = 175 &ath_usb->usb_device->pipes[ath_usb->input_data_pipe_number].pipe; 188 176 189 return usb_pipe_read(pipe, buffer, buffer_size, 190 177 return usb_pipe_read(pipe, buffer, buffer_size, 178 transferred_size); 191 179 }
Note:
See TracChangeset
for help on using the changeset viewer.