Changeset 8a64320e in mainline for uspace/drv/nic/ar9271/ar9271.c


Ignore:
Timestamp:
2015-04-23T23:40:14Z (9 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dcba819
Parents:
09044cb
Message:

pre-merge coding style cleanup and code review

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/ar9271/ar9271.c

    r09044cb r8a64320e  
    4242#include <nic.h>
    4343#include <macros.h>
    44 
    4544#include "ath_usb.h"
    4645#include "wmi.h"
     
    4847#include "ar9271.h"
    4948
    50 #define NAME "ar9271"
    51 #define FIRMWARE_FILENAME "/drv/ar9271/ar9271.fw"
     49#define NAME  "ar9271"
     50#define FIRMWARE_FILENAME  "/drv/ar9271/ar9271.fw"
    5251
    5352const usb_endpoint_description_t usb_ar9271_out_bulk_endpoint_description = {
     
    9190        &usb_ar9271_out_bulk_endpoint_description,
    9291        &usb_ar9271_in_bulk_endpoint_description,
    93         &usb_ar9271_in_int_endpoint_description,
    94         &usb_ar9271_out_int_endpoint_description,
     92        &usb_ar9271_in_int_endpoint_description,
     93        &usb_ar9271_out_int_endpoint_description,
    9594        NULL
    9695};
     
    10099
    101100/* IEEE 802.11 callbacks */
    102 static int ar9271_ieee80211_start(ieee80211_dev_t *ieee80211_dev);
    103 static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
    104         void *buffer, size_t buffer_size);
    105 static int ar9271_ieee80211_set_freq(ieee80211_dev_t *ieee80211_dev,
    106         uint16_t freq);
    107 static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *ieee80211_dev,
    108         bool connected);
    109 static int ar9271_ieee80211_key_config(ieee80211_dev_t *ieee80211_dev,
    110         ieee80211_key_config_t *key_conf, bool insert);
     101static int ar9271_ieee80211_start(ieee80211_dev_t *);
     102static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *, void *, size_t);
     103static int ar9271_ieee80211_set_freq(ieee80211_dev_t *, uint16_t);
     104static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *, bool);
     105static int ar9271_ieee80211_key_config(ieee80211_dev_t *, ieee80211_key_config_t *,
     106    bool);
    111107
    112108static driver_ops_t ar9271_driver_ops = {
     
    129125static ieee80211_iface_t ar9271_ieee80211_iface;
    130126
    131 static int ar9271_get_device_info(ddf_fun_t *dev, nic_device_info_t *info);
     127static int ar9271_get_device_info(ddf_fun_t *, nic_device_info_t *);
    132128static int ar9271_get_cable_state(ddf_fun_t *, nic_cable_state_t *);
    133 static int ar9271_get_operation_mode(ddf_fun_t *, int *,
    134         nic_channel_mode_t *, nic_role_t *);
     129static int ar9271_get_operation_mode(ddf_fun_t *, int *, nic_channel_mode_t *,
     130    nic_role_t *);
    135131
    136132static nic_iface_t ar9271_ieee80211_nic_iface = {
     
    142138static ddf_dev_ops_t ar9271_ieee80211_dev_ops;
    143139
    144 /**
    145  * Get device information.
     140/** Get device information.
    146141 *
    147142 */
     
    153148        memset(info, 0, sizeof(nic_device_info_t));
    154149       
    155         info->vendor_id = 0x0CF3;
     150        info->vendor_id = 0x0cf3;
    156151        info->device_id = 0x9271;
    157152        str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH,
     
    163158}
    164159
    165 /**
    166  * Get cable state.
     160/** Get cable state.
    167161 *
    168162 */
     
    174168}
    175169
    176 /**
    177  * Get operation mode of the device.
     170/** Get operation mode of the device.
    178171 *
    179172 */
     
    188181}
    189182
    190 /**
    191  * Set multicast frames acceptance mode.
    192  *
    193  */
    194 static int ar9271_on_multicast_mode_change(nic_t *nic,
    195         nic_multicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt)
    196 {
    197         /*
    198         ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *)
    199                 nic_get_specific(nic);
    200         ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    201          */
    202        
     183/** Set multicast frames acceptance mode.
     184 *
     185 */
     186static int ar9271_on_multicast_mode_change(nic_t *nic,
     187    nic_multicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt)
     188{
    203189        switch (mode) {
    204                 case NIC_MULTICAST_BLOCKED:
    205                         /* TODO */
    206                         break;
    207                 case NIC_MULTICAST_LIST:
    208                         /* TODO */
    209                         break;
    210                 case NIC_MULTICAST_PROMISC:
    211                         /* TODO */
    212                         break;
    213                 default:
    214                         return ENOTSUP;
    215         }
    216        
    217         return EOK;
    218 }
    219 
    220 /**
    221  * Set unicast frames acceptance mode.
     190        case NIC_MULTICAST_BLOCKED:
     191                /* TODO */
     192                break;
     193        case NIC_MULTICAST_LIST:
     194                /* TODO */
     195                break;
     196        case NIC_MULTICAST_PROMISC:
     197                /* TODO */
     198                break;
     199        default:
     200                return ENOTSUP;
     201        }
     202       
     203        return EOK;
     204}
     205
     206/** Set unicast frames acceptance mode.
    222207 *
    223208 */
     
    225210    const nic_address_t *addr, size_t addr_cnt)
    226211{
    227         /*
    228         ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *)
    229                 nic_get_specific(nic);
    230         ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    231          */
    232        
    233212        switch (mode) {
    234                 case NIC_UNICAST_BLOCKED:
    235                         /* TODO */
    236                         break;
    237                 case NIC_UNICAST_DEFAULT:
    238                         /* TODO */
    239                         break;
    240                 case NIC_UNICAST_LIST:
    241                         /* TODO */
    242                         break;
    243                 case NIC_UNICAST_PROMISC:
    244                         /* TODO */
    245                         break;
    246                 default:
    247                         return ENOTSUP;
    248         }
    249        
    250         return EOK;
    251 }
    252 
    253 /**
    254  * Set broadcast frames acceptance mode.
    255  *
    256  */
    257 static int ar9271_on_broadcast_mode_change(nic_t *nic,
    258         nic_broadcast_mode_t mode)
    259 {
    260         /*
    261         ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *)
    262                 nic_get_specific(nic);
    263         ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    264          */
    265        
     213        case NIC_UNICAST_BLOCKED:
     214                /* TODO */
     215                break;
     216        case NIC_UNICAST_DEFAULT:
     217                /* TODO */
     218                break;
     219        case NIC_UNICAST_LIST:
     220                /* TODO */
     221                break;
     222        case NIC_UNICAST_PROMISC:
     223                /* TODO */
     224                break;
     225        default:
     226                return ENOTSUP;
     227        }
     228       
     229        return EOK;
     230}
     231
     232/** Set broadcast frames acceptance mode.
     233 *
     234 */
     235static int ar9271_on_broadcast_mode_change(nic_t *nic,
     236    nic_broadcast_mode_t mode)
     237{
    266238        switch (mode) {
    267                 case NIC_BROADCAST_BLOCKED:
    268                         /* TODO */
    269                         break;
    270                 case NIC_BROADCAST_ACCEPTED:
    271                         /* TODO */
    272                         break;
    273                 default:
    274                         return ENOTSUP;
     239        case NIC_BROADCAST_BLOCKED:
     240                /* TODO */
     241                break;
     242        case NIC_BROADCAST_ACCEPTED:
     243                /* TODO */
     244                break;
     245        default:
     246                return ENOTSUP;
    275247        }
    276248       
     
    292264        void *buffer = malloc(buffer_size);
    293265       
    294         while(true) {
     266        while (true) {
    295267                size_t transferred_size;
    296                 if(htc_read_data_message(ar9271->htc_device,
    297                         buffer, buffer_size, &transferred_size) == EOK) {
    298                         size_t strip_length = 
    299                                 sizeof(ath_usb_data_header_t) +
    300                                 sizeof(htc_frame_header_t) +
    301                                 sizeof(htc_rx_status_t);
    302                        
    303                         if(transferred_size < strip_length)
     268                if (htc_read_data_message(ar9271->htc_device,
     269                    buffer, buffer_size, &transferred_size) == EOK) {
     270                        size_t strip_length =
     271                            sizeof(ath_usb_data_header_t) +
     272                            sizeof(htc_frame_header_t) +
     273                            sizeof(htc_rx_status_t);
     274                       
     275                        if (transferred_size < strip_length)
    304276                                continue;
    305 
    306                         ath_usb_data_header_t *data_header = 
    307                                 (ath_usb_data_header_t *) buffer;
    308 
     277                       
     278                        ath_usb_data_header_t *data_header =
     279                            (ath_usb_data_header_t *) buffer;
     280                       
    309281                        /* Invalid packet. */
    310                         if(data_header->tag != uint16_t_le2host(RX_TAG))
     282                        if (data_header->tag != uint16_t_le2host(RX_TAG))
    311283                                continue;
    312284                       
    313285                        htc_rx_status_t *rx_status =
    314                                 (htc_rx_status_t *) ((void *) buffer +
    315                                 sizeof(ath_usb_data_header_t) +
    316                                 sizeof(htc_frame_header_t));
     286                            (htc_rx_status_t *) ((void *) buffer +
     287                            sizeof(ath_usb_data_header_t) +
     288                            sizeof(htc_frame_header_t));
    317289                       
    318290                        uint16_t data_length =
    319                                 uint16_t_be2host(rx_status->data_length);
    320                        
    321                         int16_t payload_length = 
    322                                 transferred_size - strip_length;
    323                        
    324                         if(payload_length - data_length < 0)
     291                            uint16_t_be2host(rx_status->data_length);
     292                       
     293                        int16_t payload_length =
     294                            transferred_size - strip_length;
     295                       
     296                        if (payload_length - data_length < 0)
    325297                                continue;
    326298                       
    327                         if(ar9271_rx_status_error(rx_status->status))
     299                        if (ar9271_rx_status_error(rx_status->status))
    328300                                continue;
    329301                       
    330302                        void *strip_buffer = buffer + strip_length;
    331 
     303                       
    332304                        ieee80211_rx_handler(ar9271->ieee80211_dev,
    333                                 strip_buffer,
    334                                 payload_length);
     305                            strip_buffer,
     306                            payload_length);
    335307                }
    336308        }
     
    341313}
    342314
    343 /**
    344  * IEEE 802.11 handlers.
    345  */
    346 
     315/** IEEE 802.11 handlers.
     316 *
     317 */
    347318static int ar9271_ieee80211_set_freq(ieee80211_dev_t *ieee80211_dev,
    348         uint16_t freq)
     319    uint16_t freq)
    349320{
    350321        assert(ieee80211_dev);
     
    357328       
    358329        int rc = hw_freq_switch(ar9271, freq);
    359         if(rc != EOK) {
     330        if (rc != EOK) {
    360331                usb_log_error("Failed to HW switch frequency.\n");
    361332                return rc;
     
    365336       
    366337        rc = hw_rx_init(ar9271);
    367         if(rc != EOK) {
     338        if (rc != EOK) {
    368339                usb_log_error("Failed to initialize RX.\n");
    369340                return rc;
     
    371342       
    372343        uint16_t htc_mode = host2uint16_t_be(1);
    373         wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 
    374                 (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
     344        wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
     345            (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
    375346        wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL);
    376347       
     
    379350
    380351static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *ieee80211_dev,
    381         bool connected)
     352    bool connected)
    382353{
    383354        assert(ieee80211_dev);
    384355       
    385356        ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    386 
    387         if(connected) {
     357       
     358        if (connected) {
    388359                nic_address_t bssid;
    389360                ieee80211_query_bssid(ieee80211_dev, &bssid);
    390 
     361               
    391362                htc_sta_msg_t sta_msg;
    392363                memset(&sta_msg, 0, sizeof(htc_sta_msg_t));
    393364                sta_msg.is_vif_sta = 0;
    394                 sta_msg.max_ampdu = 
    395                         host2uint16_t_be(1 << IEEE80211_MAX_AMPDU_FACTOR);
     365                sta_msg.max_ampdu =
     366                    host2uint16_t_be(1 << IEEE80211_MAX_AMPDU_FACTOR);
    396367                sta_msg.sta_index = 1;
    397368                sta_msg.vif_index = 0;
    398369                memcpy(&sta_msg.addr, bssid.address, ETH_ADDR);
    399 
    400                 wmi_send_command(ar9271->htc_device, WMI_NODE_CREATE, 
    401                         (uint8_t *) &sta_msg, sizeof(sta_msg), NULL);
    402 
     370               
     371                wmi_send_command(ar9271->htc_device, WMI_NODE_CREATE,
     372                    (uint8_t *) &sta_msg, sizeof(sta_msg), NULL);
     373               
    403374                htc_rate_msg_t rate_msg;
    404375                memset(&rate_msg, 0, sizeof(htc_rate_msg_t));
    405376                rate_msg.sta_index = 1;
    406377                rate_msg.is_new = 1;
    407                 rate_msg.legacy_rates_count =
    408                         ARRAY_SIZE(ieee80211bg_data_rates);
    409                 memcpy(&rate_msg.legacy_rates,
    410                         ieee80211bg_data_rates,
    411                         ARRAY_SIZE(ieee80211bg_data_rates));
    412 
    413                 wmi_send_command(ar9271->htc_device, WMI_RC_RATE_UPDATE,
    414                         (uint8_t *) &rate_msg, sizeof(rate_msg), NULL);
    415 
     378                rate_msg.legacy_rates_count = ARRAY_SIZE(ieee80211bg_data_rates);
     379                memcpy(&rate_msg.legacy_rates,
     380                    ieee80211bg_data_rates,
     381                    ARRAY_SIZE(ieee80211bg_data_rates));
     382               
     383                wmi_send_command(ar9271->htc_device, WMI_RC_RATE_UPDATE,
     384                    (uint8_t *) &rate_msg, sizeof(rate_msg), NULL);
     385               
    416386                hw_set_rx_filter(ar9271, true);
    417387        } else {
    418388                uint8_t station_id = 1;
    419389                wmi_send_command(ar9271->htc_device, WMI_NODE_REMOVE,
    420                         &station_id, sizeof(station_id), NULL);
     390                    &station_id, sizeof(station_id), NULL);
    421391               
    422392                hw_set_rx_filter(ar9271, false);
     
    429399
    430400static int ar9271_ieee80211_key_config(ieee80211_dev_t *ieee80211_dev,
    431         ieee80211_key_config_t *key_conf, bool insert)
     401    ieee80211_key_config_t *key_conf, bool insert)
    432402{
    433403        assert(ieee80211_dev);
     
    446416                ieee80211_query_bssid(ieee80211_dev, &bssid);
    447417               
    448                 switch(key_conf->suite) {
    449                         case IEEE80211_SECURITY_SUITE_WEP40:
    450                                 key_type = AR9271_KEY_TABLE_TYPE_WEP40;
    451                                 break;
    452                         case IEEE80211_SECURITY_SUITE_WEP104:
    453                                 key_type = AR9271_KEY_TABLE_TYPE_WEP104;
    454                                 break;
    455                         case IEEE80211_SECURITY_SUITE_TKIP:
    456                                 key_type = AR9271_KEY_TABLE_TYPE_TKIP;
    457                                 break;
    458                         case IEEE80211_SECURITY_SUITE_CCMP:
    459                                 key_type = AR9271_KEY_TABLE_TYPE_CCMP;
    460                                 break;
    461                         default:
    462                                 key_type = -1;
     418                switch (key_conf->suite) {
     419                case IEEE80211_SECURITY_SUITE_WEP40:
     420                        key_type = AR9271_KEY_TABLE_TYPE_WEP40;
     421                        break;
     422                case IEEE80211_SECURITY_SUITE_WEP104:
     423                        key_type = AR9271_KEY_TABLE_TYPE_WEP104;
     424                        break;
     425                case IEEE80211_SECURITY_SUITE_TKIP:
     426                        key_type = AR9271_KEY_TABLE_TYPE_TKIP;
     427                        break;
     428                case IEEE80211_SECURITY_SUITE_CCMP:
     429                        key_type = AR9271_KEY_TABLE_TYPE_CCMP;
     430                        break;
     431                default:
     432                        key_type = -1;
    463433                }
    464434               
    465                 uint8_t key_id = 
    466                         (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) ?
    467                                 AR9271_STA_KEY_INDEX : key_conf->id;
     435                uint8_t key_id =
     436                    (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) ?
     437                    AR9271_STA_KEY_INDEX : key_conf->id;
    468438               
    469439                reg_ptr = AR9271_KEY_TABLE(key_id);
     
    471441                data_start = (void *) key_conf->data;
    472442               
    473                 key[0] = uint32_t_le2host(
    474                         *((uint32_t *) data_start));
    475                 key[1] = uint16_t_le2host(
    476                         *((uint16_t *) (data_start + 4)));
    477                 key[2] = uint32_t_le2host(
    478                         *((uint32_t *) (data_start + 6)));
    479                 key[3] = uint16_t_le2host(
    480                         *((uint16_t *) (data_start + 10)));
    481                 key[4] = uint32_t_le2host(
    482                         *((uint32_t *) (data_start + 12)));
    483 
    484                 if(key_conf->suite == IEEE80211_SECURITY_SUITE_WEP40 ||
    485                    key_conf->suite == IEEE80211_SECURITY_SUITE_WEP104) {
     443                key[0] = uint32_t_le2host(*((uint32_t *) data_start));
     444                key[1] = uint16_t_le2host(*((uint16_t *) (data_start + 4)));
     445                key[2] = uint32_t_le2host(*((uint32_t *) (data_start + 6)));
     446                key[3] = uint16_t_le2host(*((uint16_t *) (data_start + 10)));
     447                key[4] = uint32_t_le2host(*((uint32_t *) (data_start + 12)));
     448               
     449                if ((key_conf->suite == IEEE80211_SECURITY_SUITE_WEP40) ||
     450                    (key_conf->suite == IEEE80211_SECURITY_SUITE_WEP104))
    486451                        key[4] &= 0xFF;
    487                 }
    488452               
    489453                wmi_reg_write(ar9271->htc_device, reg_ptr + 0, key[0]);
     
    494458                wmi_reg_write(ar9271->htc_device, reg_ptr + 20, key_type);
    495459               
    496                 uint32_t macL, macH;
    497                 if(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) {
     460                uint32_t macl;
     461                uint32_t mach;
     462                if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) {
    498463                        data_start = (void *) bssid.address;
    499                         macL = uint32_t_le2host(*((uint32_t *) data_start));
    500                         macH = uint16_t_le2host(*((uint16_t *)
    501                                 (data_start + 4)));
     464                        macl = uint32_t_le2host(*((uint32_t *) data_start));
     465                        mach = uint16_t_le2host(*((uint16_t *) (data_start + 4)));
    502466                } else {
    503                         macL = macH = 0;
     467                        macl = 0;
     468                        mach = 0;
    504469                }
    505470               
    506                 macL >>= 1;
    507                 macL |= (macH & 1) << 31;
    508                 macH >>= 1;
    509                 macH |= 0x8000;
    510                
    511                 wmi_reg_write(ar9271->htc_device, reg_ptr + 24, macL);
    512                 wmi_reg_write(ar9271->htc_device, reg_ptr + 28, macH);
     471                macl >>= 1;
     472                macl |= (mach & 1) << 31;
     473                mach >>= 1;
     474                mach |= 0x8000;
     475               
     476                wmi_reg_write(ar9271->htc_device, reg_ptr + 24, macl);
     477                wmi_reg_write(ar9271->htc_device, reg_ptr + 28, mach);
    513478               
    514479                /* Setup MIC keys for TKIP. */
    515                 if(key_conf->suite == IEEE80211_SECURITY_SUITE_TKIP) {
     480                if (key_conf->suite == IEEE80211_SECURITY_SUITE_TKIP) {
    516481                        uint32_t mic[5];
    517                         uint8_t *gen_mic =
    518                                 data_start + IEEE80211_TKIP_RX_MIC_OFFSET;
     482                        uint8_t *gen_mic = data_start + IEEE80211_TKIP_RX_MIC_OFFSET;
    519483                        uint8_t *tx_mic;
    520                         if(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP) {
     484                       
     485                        if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)
    521486                                tx_mic = gen_mic;
    522                         } else {
    523                                 tx_mic = data_start +
    524                                         IEEE80211_TKIP_TX_MIC_OFFSET;
    525                         }
    526                        
    527                         mic[0] = uint32_t_le2host(
    528                                 *((uint32_t *) gen_mic));
    529                         mic[1] = uint16_t_le2host(
    530                                 *((uint16_t *) (tx_mic + 2))) & 0xFFFF;
    531                         mic[2] = uint32_t_le2host(
    532                                 *((uint32_t *) (gen_mic + 4)));
    533                         mic[3] = uint16_t_le2host(
    534                                 *((uint16_t *) tx_mic)) & 0xFFFF;
    535                         mic[4] = uint32_t_le2host(
    536                                 *((uint32_t *) (tx_mic + 4)));
    537                        
    538                         wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 0,
    539                                 mic[0]);
    540                         wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 4,
    541                                 mic[1]);
    542                         wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 8,
    543                                 mic[2]);
    544                         wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 12,
    545                                 mic[3]);
    546                         wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 16,
    547                                 mic[4]);
    548                         wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 20,
    549                                 AR9271_KEY_TABLE_TYPE_CLR);
     487                        else
     488                                tx_mic = data_start + IEEE80211_TKIP_TX_MIC_OFFSET;
     489                       
     490                        mic[0] = uint32_t_le2host(*((uint32_t *) gen_mic));
     491                        mic[1] = uint16_t_le2host(*((uint16_t *) (tx_mic + 2))) & 0xFFFF;
     492                        mic[2] = uint32_t_le2host(*((uint32_t *) (gen_mic + 4)));
     493                        mic[3] = uint16_t_le2host(*((uint16_t *) tx_mic)) & 0xFFFF;
     494                        mic[4] = uint32_t_le2host(*((uint32_t *) (tx_mic + 4)));
     495                       
     496                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 0, mic[0]);
     497                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 4, mic[1]);
     498                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 8, mic[2]);
     499                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 12, mic[3]);
     500                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 16, mic[4]);
     501                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 20,
     502                            AR9271_KEY_TABLE_TYPE_CLR);
    550503                       
    551504                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 24, 0);
     
    553506                }
    554507               
    555                 if(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)
     508                if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)
    556509                        ieee80211_setup_key_confirm(ieee80211_dev, true);
    557510        } else {
     
    564517
    565518static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
    566         void *buffer, size_t buffer_size)
     519    void *buffer, size_t buffer_size)
    567520{
    568521        assert(ieee80211_dev);
    569522       
    570         size_t complete_size, offset;
     523        size_t complete_size;
     524        size_t offset;
    571525        void *complete_buffer;
    572526        int endpoint;
     
    575529       
    576530        uint16_t frame_ctrl = *((uint16_t *) buffer);
    577         if(ieee80211_is_data_frame(frame_ctrl)) {
     531        if (ieee80211_is_data_frame(frame_ctrl)) {
    578532                offset = sizeof(htc_tx_data_header_t) +
    579                         sizeof(htc_frame_header_t);
     533                    sizeof(htc_frame_header_t);
    580534                complete_size = buffer_size + offset;
    581535                complete_buffer = malloc(complete_size);
    582536                memset(complete_buffer, 0, complete_size);
    583537               
    584                 /* 
     538                /*
    585539                 * Because we handle just station mode yet, node ID and VIF ID
    586540                 * are fixed.
    587541                 */
    588542                htc_tx_data_header_t *data_header =
    589                         (htc_tx_data_header_t *)
    590                         (complete_buffer + sizeof(htc_frame_header_t));
     543                    (htc_tx_data_header_t *)
     544                    (complete_buffer + sizeof(htc_frame_header_t));
    591545                data_header->data_type = HTC_DATA_NORMAL;
    592546                data_header->node_idx = 1;
     
    594548                data_header->cookie = 0;
    595549               
    596                 if(ieee80211_query_using_key(ieee80211_dev)) {
     550                if (ieee80211_query_using_key(ieee80211_dev)) {
    597551                        data_header->keyix = AR9271_STA_KEY_INDEX;
    598                         int sec_suite =
    599                                 ieee80211_get_pairwise_security(ieee80211_dev);
    600                         switch(sec_suite) {
    601                                 case IEEE80211_SECURITY_SUITE_WEP40:
    602                                 case IEEE80211_SECURITY_SUITE_WEP104:
    603                                         data_header->key_type =
    604                                                 AR9271_KEY_TYPE_WEP;
    605                                         break;
    606                                 case IEEE80211_SECURITY_SUITE_TKIP:
    607                                         data_header->key_type =
    608                                                 AR9271_KEY_TYPE_TKIP;
    609                                         break;
    610                                 case IEEE80211_SECURITY_SUITE_CCMP:
    611                                         data_header->key_type =
    612                                                 AR9271_KEY_TYPE_AES;
    613                                         break;
     552                       
     553                        int sec_suite =
     554                            ieee80211_get_pairwise_security(ieee80211_dev);
     555                       
     556                        switch (sec_suite) {
     557                        case IEEE80211_SECURITY_SUITE_WEP40:
     558                        case IEEE80211_SECURITY_SUITE_WEP104:
     559                                data_header->key_type = AR9271_KEY_TYPE_WEP;
     560                                break;
     561                        case IEEE80211_SECURITY_SUITE_TKIP:
     562                                data_header->key_type = AR9271_KEY_TYPE_TKIP;
     563                                break;
     564                        case IEEE80211_SECURITY_SUITE_CCMP:
     565                                data_header->key_type = AR9271_KEY_TYPE_AES;
     566                                break;
    614567                        }
    615568                } else {
     
    621574        } else {
    622575                offset = sizeof(htc_tx_management_header_t) +
    623                         sizeof(htc_frame_header_t);
     576                    sizeof(htc_frame_header_t);
    624577                complete_size = buffer_size + offset;
    625578                complete_buffer = malloc(complete_size);
    626579                memset(complete_buffer, 0, complete_size);
    627580               
    628                 /* 
     581                /*
    629582                 * Because we handle just station mode yet, node ID and VIF ID
    630583                 * are fixed.
    631584                 */
    632585                htc_tx_management_header_t *mgmt_header =
    633                         (htc_tx_management_header_t *)
    634                         (complete_buffer + sizeof(htc_frame_header_t));
     586                    (htc_tx_management_header_t *)
     587                    (complete_buffer + sizeof(htc_frame_header_t));
    635588                mgmt_header->node_idx = 0;
    636589                mgmt_header->vif_idx = 0;
     
    645598       
    646599        htc_send_data_message(ar9271->htc_device, complete_buffer,
    647                 complete_size, endpoint);
     600            complete_size, endpoint);
    648601       
    649602        free(complete_buffer);
     
    661614       
    662615        int rc = hw_reset(ar9271);
    663         if(rc != EOK) {
     616        if (rc != EOK) {
    664617                usb_log_error("Failed to do HW reset.\n");
    665618                return rc;
     
    667620       
    668621        uint16_t htc_mode = host2uint16_t_be(1);
    669         wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 
    670                 (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
     622        wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
     623            (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
    671624        wmi_send_command(ar9271->htc_device, WMI_ATH_INIT, NULL, 0, NULL);
    672625        wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL);
     
    674627       
    675628        rc = hw_rx_init(ar9271);
    676         if(rc != EOK) {
     629        if (rc != EOK) {
    677630                usb_log_error("Failed to initialize RX.\n");
    678631                return rc;
     
    681634        /* Send capability message to target. */
    682635        htc_cap_msg_t cap_msg;
    683         cap_msg.ampdu_limit = host2uint32_t_be(0xFFFF);
    684         cap_msg.ampdu_subframes = 0xFF;
     636        cap_msg.ampdu_limit = host2uint32_t_be(0xffff);
     637        cap_msg.ampdu_subframes = 0xff;
    685638        cap_msg.enable_coex = 0;
    686639        cap_msg.tx_chainmask = 0x1;
    687640       
    688641        wmi_send_command(ar9271->htc_device, WMI_TARGET_IC_UPDATE,
    689                 (uint8_t *) &cap_msg, sizeof(cap_msg), NULL);
     642            (uint8_t *) &cap_msg, sizeof(cap_msg), NULL);
    690643       
    691644        rc = htc_init_new_vif(ar9271->htc_device);
    692         if(rc != EOK) {
     645        if (rc != EOK) {
    693646                usb_log_error("Failed to initialize new VIF.\n");
    694647                return rc;
     
    697650        /* Add data polling fibril. */
    698651        fid_t fibril = fibril_create(ar9271_data_polling, ar9271);
    699         if (fibril == 0) {
     652        if (fibril == 0)
    700653                return ENOMEM;
    701         }
     654       
    702655        fibril_add_ready(fibril);
    703656       
     
    725678       
    726679        int rc = ath_usb_init(ar9271->ath_device, usb_device);
    727         if(rc != EOK) {
     680        if (rc != EOK) {
    728681                free(ar9271->ath_device);
    729682                usb_log_error("Failed to initialize ath device.\n");
     
    741694       
    742695        rc = ieee80211_device_init(ar9271->ieee80211_dev, ar9271->ddf_dev);
    743         if(rc != EOK) {
     696        if (rc != EOK) {
    744697                free(ar9271->ieee80211_dev);
    745698                free(ar9271->ath_device);
    746699                usb_log_error("Failed to initialize IEEE80211 device structure."
    747                         "\n");
     700                    "\n");
    748701                return rc;
    749702        }
    750703       
    751704        ieee80211_set_specific(ar9271->ieee80211_dev, ar9271);
    752                
     705       
    753706        /* HTC device structure initialization. */
    754707        ar9271->htc_device = calloc(1, sizeof(htc_device_t));
    755         if(!ar9271->htc_device) {
     708        if (!ar9271->htc_device) {
    756709                free(ar9271->ieee80211_dev);
    757710                free(ar9271->ath_device);
     
    761714        }
    762715       
    763         rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev, 
    764                 ar9271->htc_device);
    765         if(rc != EOK) {
     716        rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev,
     717            ar9271->htc_device);
     718        if (rc != EOK) {
    766719                free(ar9271->htc_device);
    767720                free(ar9271->ieee80211_dev);
     
    774727}
    775728
    776 /**
    777  * Upload firmware to WiFi device.
    778  *
     729/** Upload firmware to WiFi device.
     730 *
    779731 * @param ar9271 AR9271 device structure
    780  * 
     732 *
    781733 * @return EOK if succeed, negative error code otherwise
     734 *
    782735 */
    783736static int ar9271_upload_fw(ar9271_t *ar9271)
    784737{
    785         int rc;
    786        
    787738        usb_device_t *usb_device = ar9271->usb_device;
    788        
    789         /* TODO: Set by maximum packet size in pipe. */
     739       
     740        /* TODO: Set by maximum packet size in pipe. */
    790741        static const size_t MAX_TRANSFER_SIZE = 512;
    791742       
     
    802753       
    803754        void *fw_data = malloc(file_size);
    804         if(fw_data == NULL) {
     755        if (fw_data == NULL) {
    805756                fclose(fw_file);
    806757                usb_log_error("Failed allocating memory for firmware.\n");
    807758                return ENOMEM;
    808759        }
    809 
     760       
    810761        fread(fw_data, file_size, 1, fw_file);
    811762        fclose(fw_file);
     
    816767        uint8_t *current_data = fw_data;
    817768        uint8_t *buffer = malloc(MAX_TRANSFER_SIZE);
    818         while(remain_size > 0) {
     769       
     770        while (remain_size > 0) {
    819771                size_t chunk_size = min(remain_size, MAX_TRANSFER_SIZE);
    820772                memcpy(buffer, current_data, chunk_size);
    821                 rc = usb_control_request_set(&usb_device->ctrl_pipe,
     773                int rc = usb_control_request_set(&usb_device->ctrl_pipe,
    822774                    USB_REQUEST_TYPE_VENDOR,
    823775                    USB_REQUEST_RECIPIENT_DEVICE,
     
    825777                    uint16_host2usb(current_addr >> 8),
    826778                    0, buffer, chunk_size);
    827                 if(rc != EOK) {
     779                if (rc != EOK) {
    828780                        free(fw_data);
    829781                        free(buffer);
     
    841793        free(buffer);
    842794       
    843         /* Send command that firmware is successfully uploaded.
    844          * This should initiate creating confirmation message in
    845          * device side buffer which we will check in htc_check_ready function.
    846          */
    847         rc = usb_control_request_set(&usb_device->ctrl_pipe,
     795        /*
     796         * Send command that firmware is successfully uploaded.
     797         * This should initiate creating confirmation message in
     798         * device side buffer which we will check in htc_check_ready function.
     799        */
     800        int rc = usb_control_request_set(&usb_device->ctrl_pipe,
    848801            USB_REQUEST_TYPE_VENDOR,
    849802            USB_REQUEST_RECIPIENT_DEVICE,
     
    852805            0, NULL, 0);
    853806       
    854         if(rc != EOK) {
     807        if (rc != EOK) {
    855808                usb_log_error("IO error when sending fw upload confirmation "
    856                         "message.\n");
     809                    "message.\n");
    857810                return rc;
    858811        }
     
    867820
    868821/** Create driver data structure.
    869  * 
     822 *
    870823 *  @param dev The device structure
    871  * 
     824 *
    872825 *  @return Intialized device data structure or NULL if error occured
    873826 */
     
    883836        const char *err_msg = NULL;
    884837        int rc = usb_device_init(usb_device, dev, endpoints, &err_msg);
    885         if(rc != EOK) {
     838        if (rc != EOK) {
    886839                free(usb_device);
    887840                usb_log_error("Failed to create USB device: %s, "
     
    902855       
    903856        rc = ar9271_init(ar9271, usb_device);
    904         if(rc != EOK) {
     857        if (rc != EOK) {
    905858                free(ar9271);
    906859                free(usb_device);
    907                 usb_log_error("Failed to initialize AR9271 structure: %d\n", 
    908                         rc);
     860                usb_log_error("Failed to initialize AR9271 structure: %d\n",
     861                    rc);
    909862                return NULL;
    910863        }
     
    948901        /* Initialize AR9271 HTC services. */
    949902        int rc = htc_init(ar9271->htc_device);
    950         if(rc != EOK) {
     903        if (rc != EOK) {
    951904                ar9271_delete_dev_data(ar9271);
    952905                usb_log_error("HTC initialization failed.\n");
     
    956909        /* Initialize AR9271 HW. */
    957910        rc = hw_init(ar9271);
    958         if(rc != EOK) {
     911        if (rc != EOK) {
    959912                ar9271_delete_dev_data(ar9271);
    960913                usb_log_error("HW initialization failed.\n");
     
    964917        /* Initialize AR9271 IEEE 802.11 framework. */
    965918        rc = ieee80211_init(ar9271->ieee80211_dev, &ar9271_ieee80211_ops,
    966                 &ar9271_ieee80211_iface, &ar9271_ieee80211_nic_iface,
    967                 &ar9271_ieee80211_dev_ops);
    968         if(rc != EOK) {
     919            &ar9271_ieee80211_iface, &ar9271_ieee80211_nic_iface,
     920            &ar9271_ieee80211_dev_ops);
     921        if (rc != EOK) {
    969922                ar9271_delete_dev_data(ar9271);
    970923                usb_log_error("Failed to initialize IEEE80211 framework.\n");
     
    973926       
    974927        nic_set_filtering_change_handlers(nic_get_from_ddf_dev(dev),
    975                 ar9271_on_unicast_mode_change, ar9271_on_multicast_mode_change,
    976                 ar9271_on_broadcast_mode_change, NULL, NULL);
     928            ar9271_on_unicast_mode_change, ar9271_on_multicast_mode_change,
     929            ar9271_on_broadcast_mode_change, NULL, NULL);
    977930       
    978931        usb_log_info("HelenOS AR9271 added device.\n");
     
    989942       
    990943        usb_log_info("HelenOS AR9271 driver started.\n");
    991 
     944       
    992945        return ddf_driver_main(&ar9271_driver);
    993946}
Note: See TracChangeset for help on using the changeset viewer.