Changeset 56c0930 in mainline for uspace/drv/bus/usb/ar9271/htc.c


Ignore:
Timestamp:
2015-02-20T14:33:29Z (9 years ago)
Author:
Jan Kolarik <kolarik@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4cb0148
Parents:
ab365c4
Message:

Started writing TX and RX handlers, VIF init, setting RX filter, PLL init and calibration, some corrections. Added HW values array initialization, registered diagnostic polling fibril. But still not receiving any packets…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ar9271/htc.c

    rab365c4 r56c0930  
    3939#include "wmi.h"
    4040#include "htc.h"
     41#include "nic/nic.h"
     42#include "ar9271.h"
    4143
    4244/**
     
    6466}
    6567
    66 /**
    67  * Send HTC message to USB device.
     68int 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
     145static 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.
    68161 *
    69162 * @param htc_device HTC device structure.
     
    75168 * @return EOK if succeed, negative error code otherwise.
    76169 */
    77 int htc_send_message(htc_device_t *htc_device, void *buffer,
     170int htc_send_control_message(htc_device_t *htc_device, void *buffer,
    78171        size_t buffer_size, uint8_t endpoint_id)
    79172{
    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);
    90175       
    91176        ath_t *ath_device = htc_device->ath_device;
     
    96181
    97182/**
    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 */
     193int 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.
    99207 *
    100208 * @param htc_device HTC device structure.
     
    105213 * @return EOK if succeed, negative error code otherwise.
    106214 */
    107 int htc_read_message(htc_device_t *htc_device, void *buffer,
     215int 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 */
     234int htc_read_control_message(htc_device_t *htc_device, void *buffer,
    108235        size_t buffer_size, size_t *transferred_size)
    109236{
     
    145272       
    146273        /* 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,
    148275                htc_device->endpoints.ctrl_endpoint);
    149276        if(rc != EOK) {
     
    155282        free(buffer);
    156283       
    157         buffer_size = MAX_RESPONSE_LENGTH;
     284        buffer_size = htc_device->ath_device->ctrl_response_length;
    158285        buffer = malloc(buffer_size);
    159286       
    160287        /* 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);
    162289        if(rc != EOK) {
    163290                free(buffer);
     
    208335
    209336        /* 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,
    211338                htc_device->endpoints.ctrl_endpoint);
    212339        if(rc != EOK) {
     
    219346        free(buffer);
    220347       
    221         buffer_size = MAX_RESPONSE_LENGTH;
     348        buffer_size = htc_device->ath_device->ctrl_response_length;
    222349        buffer = malloc(buffer_size);
    223350
    224351        /* 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);
    226353        if(rc != EOK) {
    227354                usb_log_error("Failed to receive HTC config response message. "
     
    254381
    255382        /* 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,
    257384                htc_device->endpoints.ctrl_endpoint);
    258385        if(rc != EOK) {
     
    277404static int htc_check_ready(htc_device_t *htc_device)
    278405{
    279         size_t buffer_size = MAX_RESPONSE_LENGTH;
     406        size_t buffer_size = htc_device->ath_device->ctrl_response_length;
    280407        void *buffer = malloc(buffer_size);
    281408
    282409        /* 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);
    284412        if(rc != EOK) {
    285413                free(buffer);
     
    310438 * @return EOK if succeed, negative error code otherwise.
    311439 */
    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        
     440int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev,
     441        htc_device_t *htc_device)
     442{
    318443        fibril_mutex_initialize(&htc_device->rx_lock);
    319444        fibril_mutex_initialize(&htc_device->tx_lock);
     
    322447       
    323448        htc_device->ath_device = ath_device;
     449        htc_device->ieee80211_dev = ieee80211_dev;
    324450       
    325451        return EOK;
Note: See TracChangeset for help on using the changeset viewer.