Ignore:
Timestamp:
2015-04-23T23:40:14Z (10 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/lib/ieee80211/src/ieee80211_iface_impl.c

    r09044cb r8a64320e  
    2727 */
    2828
     29/** @addtogroup libieee80211
     30 * @{
     31 */
     32
     33/** @file ieee80211_iface_impl.c
     34 *
     35 * IEEE 802.11 default interface functions implementation.
     36 */
     37
    2938#include <str.h>
    3039#include <errno.h>
    31 
    3240#include <ieee80211_private.h>
    3341#include <ieee80211_iface_impl.h>
    3442
    35 /** @addtogroup libieee80211
    36  * @{
    37  */
    38 
    39 /** @file ieee80211_iface_impl.c
    40  *
    41  * IEEE 802.11 default interface functions implementation.
    42  */
    43 
    44 /**
    45  * Implementation of fetching scan results.
    46  *
    47  * @param fun Device function.
     43/** Implementation of fetching scan results.
     44 *
     45 * @param fun     Device function.
    4846 * @param results Structure where should be stored scan results.
    49  *
    50  * @return EOK if everything went OK, EREFUSED when device is not ready yet.
    51  */
    52 int ieee80211_get_scan_results_impl(ddf_fun_t *fun,
    53         ieee80211_scan_results_t *results, bool now)
     47 *
     48 * @return EOK if everything went OK,
     49 *         EREFUSED when device is not ready yet.
     50 *
     51 */
     52int ieee80211_get_scan_results_impl(ddf_fun_t *fun,
     53    ieee80211_scan_results_t *results, bool now)
    5454{
    5555        nic_t *nic_data = nic_get_from_ddf_fun(fun);
    5656        ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data);
    5757       
    58         if(!ieee80211_is_ready(ieee80211_dev))
     58        if (!ieee80211_is_ready(ieee80211_dev))
    5959                return EREFUSED;
    6060       
    61         if(now) {
     61        if (now)
    6262                ieee80211_dev->ops->scan(ieee80211_dev);
    63         }
    6463       
    6564        fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex);
    66         if(results) {
     65       
     66        if (results) {
    6767                ieee80211_scan_result_list_t *result_list =
    68                         &ieee80211_dev->ap_list;
    69                
    70                 int i = 0;
     68                    &ieee80211_dev->ap_list;
     69               
     70                unsigned int i = 0;
    7171                ieee80211_scan_result_list_foreach(*result_list, result) {
    72                         memcpy(&results->results[i], 
    73                                 &result->scan_result,
    74                                 sizeof(ieee80211_scan_result_t));
     72                        memcpy(&results->results[i],
     73                            &result->scan_result,
     74                            sizeof(ieee80211_scan_result_t));
    7575                        i++;
    7676                }
     
    7878                results->length = i;
    7979        }
     80       
    8081        fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex);
    8182       
     
    8889}
    8990
    90 /**
    91  * Working procedure of connect function.
    92  *
     91/** Working procedure of connect function.
     92 *
    9393 * @param ieee80211_dev Pointer to IEEE 802.11 device.
    94  * @param auth_data Selected AP data we want to connect to.
    95  *
    96  * @return EOK if everything OK, ETIMEOUT when timeout during authenticating.
     94 * @param auth_data     Selected AP data we want to connect to.
     95 *
     96 * @return EOK if everything OK,
     97 *         ETIMEOUT when timeout during authenticating.
     98 *
    9799 */
    98100static int ieee80211_connect_proc(ieee80211_dev_t *ieee80211_dev,
    99         ieee80211_scan_result_link_t *auth_data, char *password)
     101    ieee80211_scan_result_link_t *auth_data, char *password)
    100102{
    101103        ieee80211_dev->bssid_info.res_link = auth_data;
    102104       
    103105        /* Set channel. */
    104         int rc = ieee80211_dev->ops->set_freq(ieee80211_dev, 
    105                 ieee80211_channel_to_freq(auth_data->scan_result.channel));
    106         if(rc != EOK)
     106        int rc = ieee80211_dev->ops->set_freq(ieee80211_dev,
     107            ieee80211_channel_to_freq(auth_data->scan_result.channel));
     108        if (rc != EOK)
    107109                return rc;
    108110       
    109111        /* Try to authenticate. */
    110112        ieee80211_authenticate(ieee80211_dev);
     113       
    111114        fibril_mutex_lock(&ieee80211_dev->gen_mutex);
    112115        rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond,
    113                         &ieee80211_dev->gen_mutex,
    114                         AUTH_TIMEOUT);
     116            &ieee80211_dev->gen_mutex, AUTH_TIMEOUT);
    115117        fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
    116         if(rc != EOK)
     118       
     119        if (rc != EOK)
    117120                return rc;
    118         if(ieee80211_get_auth_phase(ieee80211_dev) !=
    119                 IEEE80211_AUTH_AUTHENTICATED) {
    120                 ieee80211_set_auth_phase(ieee80211_dev,
    121                         IEEE80211_AUTH_DISCONNECTED);
     121       
     122        if (ieee80211_get_auth_phase(ieee80211_dev) !=
     123            IEEE80211_AUTH_AUTHENTICATED) {
     124                ieee80211_set_auth_phase(ieee80211_dev,
     125                    IEEE80211_AUTH_DISCONNECTED);
    122126                return EINVAL;
    123127        }
     
    125129        /* Try to associate. */
    126130        ieee80211_associate(ieee80211_dev, password);
     131       
    127132        fibril_mutex_lock(&ieee80211_dev->gen_mutex);
    128133        rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond,
    129                         &ieee80211_dev->gen_mutex,
    130                         AUTH_TIMEOUT);
     134            &ieee80211_dev->gen_mutex, AUTH_TIMEOUT);
    131135        fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
    132         if(rc != EOK)
     136       
     137        if (rc != EOK)
    133138                return rc;
    134         if(ieee80211_get_auth_phase(ieee80211_dev) !=
    135                 IEEE80211_AUTH_ASSOCIATED) {
    136                 ieee80211_set_auth_phase(ieee80211_dev,
    137                         IEEE80211_AUTH_DISCONNECTED);
     139       
     140        if (ieee80211_get_auth_phase(ieee80211_dev) !=
     141            IEEE80211_AUTH_ASSOCIATED) {
     142                ieee80211_set_auth_phase(ieee80211_dev,
     143                    IEEE80211_AUTH_DISCONNECTED);
    138144                return EINVAL;
    139145        }
    140146       
    141147        /* On open network, we are finished. */
    142         if(auth_data->scan_result.security.type != IEEE80211_SECURITY_OPEN) {
     148        if (auth_data->scan_result.security.type !=
     149            IEEE80211_SECURITY_OPEN) {
    143150                /* Otherwise wait for 4-way handshake to complete. */
     151               
    144152                fibril_mutex_lock(&ieee80211_dev->gen_mutex);
    145153                rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond,
    146                                 &ieee80211_dev->gen_mutex,
    147                                 HANDSHAKE_TIMEOUT);
     154                    &ieee80211_dev->gen_mutex, HANDSHAKE_TIMEOUT);
    148155                fibril_mutex_unlock(&ieee80211_dev->gen_mutex);
    149                 if(rc != EOK) {
     156               
     157                if (rc != EOK) {
    150158                        ieee80211_deauthenticate(ieee80211_dev);
    151159                        return rc;
     
    158166}
    159167
    160 /**
    161  * Implementation of connecting to specified SSID.
    162  *
    163  * @param fun Device function.
     168/** Implementation of connecting to specified SSID.
     169 *
     170 * @param fun        Device function.
    164171 * @param ssid_start SSID prefix of access point we want to connect to.
    165  *
    166  * @return EOK if everything OK, ETIMEOUT when timeout during authenticating,
    167  * EINVAL when SSID not in scan results list, EPERM when incorrect password
    168  * passed, EREFUSED when device is not ready yet.
     172 *
     173 * @return EOK if everything OK,
     174 *         ETIMEOUT when timeout during authenticating,
     175 *         EINVAL when SSID not in scan results list,
     176 *         EPERM when incorrect password passed,
     177 *         EREFUSED when device is not ready yet.
     178 *
    169179 */
    170180int ieee80211_connect_impl(ddf_fun_t *fun, char *ssid_start, char *password)
     
    173183        assert(password);
    174184       
    175         int rc;
    176        
    177185        nic_t *nic_data = nic_get_from_ddf_fun(fun);
    178186        ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data);
    179187       
    180         if(!ieee80211_is_ready(ieee80211_dev))
     188        if (!ieee80211_is_ready(ieee80211_dev))
    181189                return EREFUSED;
    182190       
    183         if(ieee80211_is_connected(ieee80211_dev)) {
    184                 rc = ieee80211_dev->iface->disconnect(fun);
    185                 if(rc != EOK)
     191        if (ieee80211_is_connected(ieee80211_dev)) {
     192                int rc = ieee80211_dev->iface->disconnect(fun);
     193                if (rc != EOK)
    186194                        return rc;
    187195        }
     
    189197        ieee80211_set_connect_request(ieee80211_dev);
    190198       
    191         rc = ENOENT;
     199        int rc = ENOENT;
    192200        fibril_mutex_lock(&ieee80211_dev->scan_mutex);
    193201       
    194202        ieee80211_dev->pending_conn_req = false;
    195 
     203       
    196204        ieee80211_scan_result_list_foreach(ieee80211_dev->ap_list, result) {
    197                 if(!str_lcmp(ssid_start,
    198                         result->scan_result.ssid,
    199                         str_size(ssid_start))) {
     205                if (!str_lcmp(ssid_start, result->scan_result.ssid,
     206                    str_size(ssid_start))) {
    200207                        rc = ieee80211_connect_proc(ieee80211_dev, result,
    201                                 password);
     208                            password);
    202209                        break;
    203210                }
     
    209216}
    210217
    211 /**
    212  * Implementation of disconnecting device from network.
    213  *
     218/** Implementation of disconnecting device from network.
     219 *
    214220 * @param fun Device function.
    215  *
    216  * @return EOK if everything OK, EREFUSED if device is not ready yet.
     221 *
     222 * @return EOK if everything OK,
     223 *         EREFUSED if device is not ready yet.
     224 *
    217225 */
    218226int ieee80211_disconnect_impl(ddf_fun_t *fun)
     
    221229        ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data);
    222230       
    223         if(!ieee80211_is_ready(ieee80211_dev))
     231        if (!ieee80211_is_ready(ieee80211_dev))
    224232                return EREFUSED;
    225233       
    226         if(!ieee80211_is_connected(ieee80211_dev)) {
     234        if (!ieee80211_is_connected(ieee80211_dev))
    227235                return EOK;
    228         } else {
    229                 fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex);
    230                 int rc = ieee80211_deauthenticate(ieee80211_dev);
    231                 fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex);
    232                 return rc;
    233         }
     236       
     237        fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex);
     238        int rc = ieee80211_deauthenticate(ieee80211_dev);
     239        fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex);
     240       
     241        return rc;
    234242}
    235243
Note: See TracChangeset for help on using the changeset viewer.