Changeset 56c0930 in mainline for uspace/drv/bus/usb/ar9271/htc.c
- Timestamp:
- 2015-02-20T14:33:29Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4cb0148
- Parents:
- ab365c4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ar9271/htc.c
rab365c4 r56c0930 39 39 #include "wmi.h" 40 40 #include "htc.h" 41 #include "nic/nic.h" 42 #include "ar9271.h" 41 43 42 44 /** … … 64 66 } 65 67 66 /** 67 * Send HTC message to USB device. 68 int htc_init_new_vif(htc_device_t *htc_device) 69 { 70 htc_vif_msg_t vif_msg; 71 htc_sta_msg_t sta_msg; 72 73 nic_address_t addr; 74 nic_t *nic = nic_get_from_ddf_dev(htc_device->ieee80211_dev->ddf_dev); 75 nic_query_address(nic, &addr); 76 77 memcpy(&vif_msg.addr, &addr.address, ETH_ADDR); 78 memcpy(&sta_msg.addr, &addr.address, ETH_ADDR); 79 80 ieee80211_operating_mode_t op_mode = 81 htc_device->ieee80211_dev->current_op_mode; 82 83 switch(op_mode) { 84 case IEEE80211_OPMODE_ADHOC: 85 vif_msg.op_mode = HTC_OPMODE_ADHOC; 86 break; 87 case IEEE80211_OPMODE_AP: 88 vif_msg.op_mode = HTC_OPMODE_AP; 89 break; 90 case IEEE80211_OPMODE_MESH: 91 vif_msg.op_mode = HTC_OPMODE_MESH; 92 break; 93 case IEEE80211_OPMODE_STATION: 94 vif_msg.op_mode = HTC_OPMODE_STATION; 95 break; 96 } 97 98 vif_msg.index = 0; 99 vif_msg.rts_thres = host2uint16_t_be(HTC_RTS_THRESHOLD); 100 101 int rc = wmi_send_command(htc_device, WMI_VAP_CREATE, 102 (uint8_t *) &vif_msg, sizeof(vif_msg), NULL); 103 if(rc != EOK) { 104 usb_log_error("Failed to send VAP create command.\n"); 105 return rc; 106 } 107 108 sta_msg.is_vif_sta = 1; 109 sta_msg.max_ampdu = host2uint16_t_be(HTC_MAX_AMPDU); 110 sta_msg.sta_index = 0; 111 sta_msg.vif_index = 0; 112 113 rc = wmi_send_command(htc_device, WMI_NODE_CREATE, 114 (uint8_t *) &sta_msg, sizeof(sta_msg), NULL); 115 if(rc != EOK) { 116 usb_log_error("Failed to send NODE create command.\n"); 117 return rc; 118 } 119 120 /* Write first 4 bytes of MAC address. */ 121 uint32_t id0; 122 memcpy(&id0, &addr.address, 4); 123 id0 = host2uint32_t_le(id0); 124 rc = wmi_reg_write(htc_device, AR9271_STATION_ID0, id0); 125 if(rc != EOK) 126 return rc; 127 128 /* Write last 2 bytes of MAC address (and preserve existing data). */ 129 uint32_t id1; 130 rc = wmi_reg_read(htc_device, AR9271_STATION_ID1, &id1); 131 if(rc != EOK) 132 return rc; 133 uint16_t id1_addr; 134 memcpy(&id1_addr, &addr.address[4], 2); 135 id1 = (id1 & ~AR9271_STATION_ID1_MASK) | host2uint16_t_le(id1_addr); 136 rc = wmi_reg_write(htc_device, AR9271_STATION_ID1, id1); 137 if(rc != EOK) 138 return rc; 139 140 /* TODO: Set BSSID mask for AP mode. */ 141 142 return EOK; 143 } 144 145 static void htc_config_frame_header(htc_frame_header_t *header, 146 size_t buffer_size, uint8_t endpoint_id) 147 { 148 header->endpoint_id = endpoint_id; 149 header->flags = 0; 150 header->payload_length = 151 host2uint16_t_be(buffer_size - sizeof(htc_frame_header_t)); 152 153 header->control_bytes[0] = 0x02; 154 header->control_bytes[1] = 0x88; 155 header->control_bytes[2] = 0xFF; 156 header->control_bytes[3] = 0xFF; 157 } 158 159 /** 160 * Send control HTC message to USB device. 68 161 * 69 162 * @param htc_device HTC device structure. … … 75 168 * @return EOK if succeed, negative error code otherwise. 76 169 */ 77 int htc_send_ message(htc_device_t *htc_device, void *buffer,170 int htc_send_control_message(htc_device_t *htc_device, void *buffer, 78 171 size_t buffer_size, uint8_t endpoint_id) 79 172 { 80 htc_frame_header_t *htc_header = (htc_frame_header_t *) buffer; 81 htc_header->endpoint_id = endpoint_id; 82 htc_header->flags = 0; 83 htc_header->payload_length = 84 host2uint16_t_be(buffer_size - sizeof(htc_frame_header_t)); 85 86 htc_header->control_bytes[0] = 0x02; 87 htc_header->control_bytes[1] = 0x88; 88 htc_header->control_bytes[2] = 0xFF; 89 htc_header->control_bytes[3] = 0xFF; 173 htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size, 174 endpoint_id); 90 175 91 176 ath_t *ath_device = htc_device->ath_device; … … 96 181 97 182 /** 98 * Read HTC message from USB device. 183 * Send data HTC message to USB device. 184 * 185 * @param htc_device HTC device structure. 186 * @param buffer Buffer with data to be sent to USB device (without HTC frame 187 * header). 188 * @param buffer_size Size of buffer (including HTC frame header). 189 * @param endpoint_id Destination endpoint. 190 * 191 * @return EOK if succeed, negative error code otherwise. 192 */ 193 int htc_send_data_message(htc_device_t *htc_device, void *buffer, 194 size_t buffer_size, uint8_t endpoint_id) 195 { 196 htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size, 197 endpoint_id); 198 199 ath_t *ath_device = htc_device->ath_device; 200 201 return ath_device->ops->send_data_message(ath_device, buffer, 202 buffer_size); 203 } 204 205 /** 206 * Read HTC data message from USB device. 99 207 * 100 208 * @param htc_device HTC device structure. … … 105 213 * @return EOK if succeed, negative error code otherwise. 106 214 */ 107 int htc_read_message(htc_device_t *htc_device, void *buffer, 215 int htc_read_data_message(htc_device_t *htc_device, void *buffer, 216 size_t buffer_size, size_t *transferred_size) 217 { 218 ath_t *ath_device = htc_device->ath_device; 219 220 return ath_device->ops->read_data_message(ath_device, buffer, 221 buffer_size, transferred_size); 222 } 223 224 /** 225 * Read HTC control message from USB device. 226 * 227 * @param htc_device HTC device structure. 228 * @param buffer Buffer where data from USB device will be stored. 229 * @param buffer_size Size of buffer. 230 * @param transferred_size Real size of read data. 231 * 232 * @return EOK if succeed, negative error code otherwise. 233 */ 234 int htc_read_control_message(htc_device_t *htc_device, void *buffer, 108 235 size_t buffer_size, size_t *transferred_size) 109 236 { … … 145 272 146 273 /* Send HTC message. */ 147 int rc = htc_send_ message(htc_device, buffer, buffer_size,274 int rc = htc_send_control_message(htc_device, buffer, buffer_size, 148 275 htc_device->endpoints.ctrl_endpoint); 149 276 if(rc != EOK) { … … 155 282 free(buffer); 156 283 157 buffer_size = MAX_RESPONSE_LENGTH;284 buffer_size = htc_device->ath_device->ctrl_response_length; 158 285 buffer = malloc(buffer_size); 159 286 160 287 /* Read response from device. */ 161 rc = htc_read_ message(htc_device, buffer, buffer_size, NULL);288 rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL); 162 289 if(rc != EOK) { 163 290 free(buffer); … … 208 335 209 336 /* Send HTC message. */ 210 int rc = htc_send_ message(htc_device, buffer, buffer_size,337 int rc = htc_send_control_message(htc_device, buffer, buffer_size, 211 338 htc_device->endpoints.ctrl_endpoint); 212 339 if(rc != EOK) { … … 219 346 free(buffer); 220 347 221 buffer_size = MAX_RESPONSE_LENGTH;348 buffer_size = htc_device->ath_device->ctrl_response_length; 222 349 buffer = malloc(buffer_size); 223 350 224 351 /* Check response from device. */ 225 rc = htc_read_ message(htc_device, buffer, buffer_size, NULL);352 rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL); 226 353 if(rc != EOK) { 227 354 usb_log_error("Failed to receive HTC config response message. " … … 254 381 255 382 /* Send HTC message. */ 256 int rc = htc_send_ message(htc_device, buffer, buffer_size,383 int rc = htc_send_control_message(htc_device, buffer, buffer_size, 257 384 htc_device->endpoints.ctrl_endpoint); 258 385 if(rc != EOK) { … … 277 404 static int htc_check_ready(htc_device_t *htc_device) 278 405 { 279 size_t buffer_size = MAX_RESPONSE_LENGTH;406 size_t buffer_size = htc_device->ath_device->ctrl_response_length; 280 407 void *buffer = malloc(buffer_size); 281 408 282 409 /* Read response from device. */ 283 int rc = htc_read_message(htc_device, buffer, buffer_size, NULL); 410 int rc = htc_read_control_message(htc_device, buffer, buffer_size, 411 NULL); 284 412 if(rc != EOK) { 285 413 free(buffer); … … 310 438 * @return EOK if succeed, negative error code otherwise. 311 439 */ 312 int htc_device_init(ath_t *ath_device, htc_device_t *htc_device) 313 { 314 if(ath_device == NULL || htc_device == NULL) { 315 return EINVAL; 316 } 317 440 int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev, 441 htc_device_t *htc_device) 442 { 318 443 fibril_mutex_initialize(&htc_device->rx_lock); 319 444 fibril_mutex_initialize(&htc_device->tx_lock); … … 322 447 323 448 htc_device->ath_device = ath_device; 449 htc_device->ieee80211_dev = ieee80211_dev; 324 450 325 451 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.