Changeset 9e5a51c in mainline for uspace/drv/bus/usb/ar9271/ar9271.c


Ignore:
Timestamp:
2015-03-08T22:20:34Z (9 years ago)
Author:
Jan Kolarik <kolarik@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
864762a
Parents:
4cb0148
Message:

Fixed PLL initialization value that blocked communication with external devices. Started implementing IEEE802.11 scanning and authentication functions.

File:
1 edited

Legend:

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

    r4cb0148 r9e5a51c  
    9999static int ar9271_add_device(ddf_dev_t *);
    100100
    101 /* IEEE802.11 callbacks */
     101/* IEEE 802.11 callbacks */
    102102static int ar9271_ieee80211_start(ieee80211_dev_t *ieee80211_dev);
    103103static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
    104104        void *buffer, size_t buffer_size);
     105static int ar9271_ieee80211_set_freq(ieee80211_dev_t *ieee80211_dev,
     106        uint16_t freq);
    105107
    106108static driver_ops_t ar9271_driver_ops = {
     
    115117static ieee80211_ops_t ar9271_ieee80211_ops = {
    116118        .start = ar9271_ieee80211_start,
    117         .tx_handler = ar9271_ieee80211_tx_handler
    118 };
    119 
    120 static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
    121         void *buffer, size_t buffer_size)
    122 {
    123         /* TODO: Process TX message properly */
    124        
    125         size_t complete_size, offset;
    126         void *complete_buffer;
    127         int endpoint;
    128        
    129         ar9271_t *ar9271 = (ar9271_t *) ieee80211_dev->driver_data;
    130        
    131         ieee80211_header_t *ieee80211_header = (ieee80211_header_t *) buffer;
    132        
    133         if(ieee80211_is_data_frame(ieee80211_header)) {
    134                 offset = sizeof(htc_frame_header_t);
    135                 complete_size = buffer_size + offset;
    136                 complete_buffer = malloc(complete_size);
    137                 endpoint = ar9271->htc_device->endpoints.data_be_endpoint;
    138         } else {
    139                 offset = sizeof(htc_tx_management_header_t) +
    140                         sizeof(htc_frame_header_t);
    141                 complete_size = buffer_size + offset;
    142                 complete_buffer = malloc(complete_size);
    143                 endpoint = ar9271->htc_device->endpoints.mgmt_endpoint;
    144         }
    145        
    146         /* Copy IEEE802.11 data to new allocated buffer with HTC headers. */
    147         memcpy(complete_buffer + offset, buffer, buffer_size);
    148        
    149         htc_send_data_message(ar9271->htc_device, complete_buffer,
    150                 complete_size, endpoint);
    151        
    152         free(complete_buffer);
    153        
    154         return EOK;
    155 }
     119        .tx_handler = ar9271_ieee80211_tx_handler,
     120        .set_freq = ar9271_ieee80211_set_freq
     121};
    156122
    157123static int ar9271_data_polling(void *arg)
     
    162128       
    163129        while(true) {
    164                 int rc =
    165130                htc_read_data_message(ar9271->htc_device, buffer, buffer_size,
    166131                        NULL);
    167                 usb_log_info("XXXXXXXXXXXXXXXXXXXXXXXXXXXX RC is %d.\n", rc);
     132                usb_log_info("Incoming data message.\n");
    168133               
    169134                /* TODO: Process RX message */
     
    173138}
    174139
     140/*
    175141static int ar9271_diag_polling(void *arg)
    176142{
     
    183149                wmi_reg_read(ar9271->htc_device, 0x782C, &result);
    184150                usb_log_info("0x782C: %x\n", result);
    185                 wmi_reg_read(ar9271->htc_device, 0x8048, &result);
     151                wmi_reg_read(ar9271->htc_device, AR9271_DIAG, &result);
    186152                usb_log_info("Diag reg.: %x\n", result);
    187153                wmi_reg_read(ar9271->htc_device, 0x8088, &result);
     
    204170        return EOK;
    205171}
     172 */
    206173
    207174static int ar9271_register_polling_fibrils(ar9271_t *ar9271)
     
    215182       
    216183        /* Add debug polling fibril. */
     184        /*
    217185        fibril = fibril_create(ar9271_diag_polling, ar9271);
    218186        if (fibril == 0) {
     
    220188        }
    221189        fibril_add_ready(fibril);
     190         */
     191       
     192        return EOK;
     193}
     194
     195/**
     196 * IEEE 802.11 handlers.
     197 */
     198
     199static int ar9271_ieee80211_set_freq(ieee80211_dev_t *ieee80211_dev,
     200        uint16_t freq)
     201{
     202        ar9271_t *ar9271 = (ar9271_t *) ieee80211_dev->driver_data;
     203       
     204        wmi_send_command(ar9271->htc_device, WMI_DISABLE_INTR, NULL, 0, NULL);
     205        wmi_send_command(ar9271->htc_device, WMI_DRAIN_TXQ_ALL, NULL, 0, NULL);
     206        wmi_send_command(ar9271->htc_device, WMI_STOP_RECV, NULL, 0, NULL);
     207       
     208        int rc = hw_freq_switch(ar9271, freq);
     209        if(rc != EOK) {
     210                usb_log_error("Failed to HW switch frequency.\n");
     211                return rc;
     212        }
     213       
     214        wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL);
     215       
     216        rc = hw_rx_init(ar9271);
     217        if(rc != EOK) {
     218                usb_log_error("Failed to initialize RX.\n");
     219                return rc;
     220        }
     221       
     222        uint16_t htc_mode = host2uint16_t_be(1);
     223        wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
     224                (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
     225        wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL);
     226       
     227        return EOK;
     228}
     229
     230static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
     231        void *buffer, size_t buffer_size)
     232{
     233        size_t complete_size, offset;
     234        void *complete_buffer;
     235        int endpoint;
     236       
     237        ar9271_t *ar9271 = (ar9271_t *) ieee80211_dev->driver_data;
     238       
     239        uint16_t frame_ctrl = uint16_t_le2host(*((uint16_t *) buffer));
     240        if(frame_ctrl & IEEE80211_DATA_FRAME) {
     241                offset = sizeof(htc_frame_header_t);
     242                complete_size = buffer_size + offset;
     243                complete_buffer = malloc(complete_size);
     244                endpoint = ar9271->htc_device->endpoints.data_be_endpoint;
     245        } else {
     246                offset = sizeof(htc_tx_management_header_t) +
     247                        sizeof(htc_frame_header_t);
     248                complete_size = buffer_size + offset;
     249                complete_buffer = malloc(complete_size);
     250                memset(complete_buffer, 0, complete_size);
     251               
     252                htc_tx_management_header_t *mgmt_header =
     253                        (htc_tx_management_header_t *)
     254                        (complete_buffer + sizeof(htc_frame_header_t));
     255                mgmt_header->keyix = 0xFF;
     256               
     257                endpoint = ar9271->htc_device->endpoints.mgmt_endpoint;
     258        }
     259       
     260        /* Copy IEEE802.11 data to new allocated buffer with HTC headers. */
     261        memcpy(complete_buffer + offset, buffer, buffer_size);
     262       
     263        htc_send_data_message(ar9271->htc_device, complete_buffer,
     264                complete_size, endpoint);
     265       
     266        free(complete_buffer);
    222267       
    223268        return EOK;
     
    228273        ar9271_t *ar9271 = (ar9271_t *) ieee80211_dev->driver_data;
    229274       
    230         int rc = wmi_send_command(ar9271->htc_device, WMI_FLUSH_RECV, NULL, 0,
    231                 NULL);
    232         if(rc != EOK) {
    233                 usb_log_error("Failed to flush receiving buffer.\n");
    234                 return rc;
    235         }
    236        
    237         rc = hw_reset(ar9271);
     275        wmi_send_command(ar9271->htc_device, WMI_FLUSH_RECV, NULL, 0, NULL);
     276       
     277        int rc = hw_reset(ar9271);
    238278        if(rc != EOK) {
    239279                usb_log_error("Failed to do HW reset.\n");
     
    242282       
    243283        uint16_t htc_mode = host2uint16_t_be(1);
    244         rc = wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
     284        wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
    245285                (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
    246         if(rc != EOK) {
    247                 usb_log_error("Failed to set HTC mode.\n");
    248                 return rc;
    249         }
    250        
    251         rc = wmi_send_command(ar9271->htc_device, WMI_ATH_INIT, NULL, 0,
    252                 NULL);
    253         if(rc != EOK) {
    254                 usb_log_error("Failed to send ath init command.\n");
    255                 return rc;
    256         }
    257        
    258         rc = wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0,
    259                 NULL);
    260         if(rc != EOK) {
    261                 usb_log_error("Failed to send receiving init command.\n");
    262                 return rc;
    263         }
     286        wmi_send_command(ar9271->htc_device, WMI_ATH_INIT, NULL, 0, NULL);
     287        wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL);
     288        wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL);
    264289       
    265290        rc = hw_rx_init(ar9271);
     
    269294        }
    270295       
     296        /* Send capability message to target. */
     297        htc_cap_msg_t cap_msg;
     298        cap_msg.ampdu_limit = host2uint32_t_be(0xFFFF);
     299        cap_msg.ampdu_subframes = 0xFF;
     300        cap_msg.enable_coex = 0;
     301        cap_msg.tx_chainmask = 0x1;
     302       
     303        wmi_send_command(ar9271->htc_device, WMI_TARGET_IC_UPDATE,
     304                (uint8_t *) &cap_msg, sizeof(cap_msg), NULL);
     305       
    271306        rc = htc_init_new_vif(ar9271->htc_device);
    272307        if(rc != EOK) {
     
    281316        }
    282317       
     318        ar9271->starting_up = false;
     319       
    283320        return EOK;
    284321}
     
    286323static int ar9271_init(ar9271_t *ar9271, usb_device_t *usb_device)
    287324{
     325        ar9271->starting_up = true;
    288326        ar9271->usb_device = usb_device;
    289327       
Note: See TracChangeset for help on using the changeset viewer.