- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# /space/home/slher/rel/Beken/v6_4_5/macsw/ip/lmac/src/scan/scan_task.c

Go to the documentation of this file.

    00001
    00020 /*
    00021  * INCLUDE FILES
    00022  ****************************************************************************************
    00023  */
    00024 #include "co_endian.h"
    00025
    00026
    00027 #include "scan.h"
    00028 #include "scan_task.h"
    00029 #include "phy.h"
    00030 #include "mm.h"
    00031
    00032
    00033 #include "dbg.h"
    00034
    00035
    00036
    00037 #if NX_HW_SCAN
    00038 /*
    00039  * MESSAGE HANDLERS
    00040  ****************************************************************************************
    00041  */
    00055 static int
    00056 scan_start_req_handler(ke_msg_id_t const msgid,
    00057                        struct scan_start_req const *param,
    00058                        ke_task_id_t const dest_id,
    00059                        ke_task_id_t const src_id)
    00060 {
    00061     int msg_status = KE_MSG_CONSUMED;
    00062
    00063     // Allocate the response message
    00064     struct scan_start_cfm *msg = KE_MSG_ALLOC(SCAN_START_CFM, src_id, dest_id,
    00065                                               scan_start_cfm);
    00066
    00067     // Check the current state of the scanning procedure
    00068     if (ke_state_get(TASK_SCAN) == SCAN_IDLE)
    00069     {
    00070         // Sanity check - at least one channel should be requested
    00071         ASSERT_ERR(param->chan_cnt > 0);
    00072
    00073         // No scan ongoing, we will proceed to the request
    00074         msg->status = CO_OK;
    00075
    00076         // Initialize the scan parameters
    00077         scan_env.chan_idx = 0;
    00078         scan_env.req_id = src_id;
    00079         scan_env.param = param;
    00080
    00081         // Prepare the IE buffer of the Probe Request
    00082         scan_ie_download(param);
    00083
    00084         // Message will be freed at the end of the scanning procedure
    00085         msg_status = KE_MSG_NO_FREE;
    00086     }
    00087     else
    00088     {
    00089         // We are currently in a scan process, so reject the current request
    00090         msg->status = CO_BUSY;
    00091     }
    00092
    00093     // Send the response
    00094     ke_msg_send(msg);
    00095
    00096     //  Return the message status.
    00097     return (msg_status);
    00098 }
    00099
    00113 static int
    00114 scan_cancel_req_handler(ke_msg_id_t const msgid,
    00115                         void const *param,
    00116                         ke_task_id_t const dest_id,
    00117                         ke_task_id_t const src_id)
    00118 {
    00119     ke_state_t scan_state = ke_state_get(TASK_SCAN);
    00120
    00121     // Check if a scan process is in progress
    00122     if (scan_state != SCAN_IDLE)
    00123     {
    00124         scan_env.abort = true;
    00125     }
    00126     else
    00127     {
    00128         // Directly send the confirmation with an error status
    00129         scan_send_cancel_cfm(CO_FAIL, src_id);
    00130     }
    00131
    00132     //  Return the message status.
    00133     return (KE_MSG_CONSUMED);
    00134 }
    00135
    00149 static int
    00150 mm_scan_channel_start_ind_handler(ke_msg_id_t const msgid,
    00151                                   void const *param,
    00152                                   ke_task_id_t const dest_id,
    00153                                   ke_task_id_t const src_id)
    00154 {
    00155     struct mac_chan_def const *chan = &scan_env.param->chan[scan_env.chan_idx];
    00156
    00157     // Sanity check
    00158     ASSERT_ERR(ke_state_get(TASK_SCAN) == SCAN_WAIT_CHANNEL);
    00159
    00160     // Configure the RX filter to receive beacons and probe responses
    00161     mm_rx_filter_lmac_enable_set(NXMAC_ACCEPT_ALL_BEACON_BIT | NXMAC_ACCEPT_PROBE_RESP_BIT);
    00162
    00163     // Prepare and transmit the Probe Request(s) unless passive scan is requested
    00164     if (! (chan->flags & CHAN_NO_IR))
    00165         scan_probe_req_tx();
    00166
    00167     // Change the state of the task
    00168     ke_state_set(TASK_SCAN, SCAN_WAIT_BEACON_PROBE_RSP);
    00169
    00170     //  Return the KE_MSG_CONSUMED status.
    00171     return (KE_MSG_CONSUMED);
    00172 }
    00173
    00190 static int
    00191 mm_scan_channel_end_ind_handler(ke_msg_id_t const msgid,
    00192                                 void const *param,
    00193                                 ke_task_id_t const dest_id,
    00194                                 ke_task_id_t const src_id)
    00195 {
    00196     // Sanity check
    00197     ASSERT_ERR(ke_state_get(TASK_SCAN) == SCAN_WAIT_BEACON_PROBE_RSP);
    00198
    00199     // Configure the RX filter to disable beacons and probe responses reception
    00200     mm_rx_filter_lmac_enable_clear(NXMAC_ACCEPT_ALL_BEACON_BIT | NXMAC_ACCEPT_PROBE_RESP_BIT);
    00201
    00202     // Increase the channel index
    00203     scan_env.chan_idx++;
    00204
    00205     // Check if we still have channels to scan, or if abort has been requested
    00206     if ((scan_env.chan_idx < scan_env.param->chan_cnt) && !scan_env.abort)
    00207     {
    00208         // Send the new set channel request
    00209         scan_set_channel_request();
    00210     }
    00211     else
    00212     {
    00213         // Free the scan parameter buffer
    00214         ke_msg_free(ke_param2msg(scan_env.param));
    00215
    00216         if (scan_env.abort)
    00217         {
    00218             // Send the scan end indication to the host
    00219             scan_send_cancel_cfm(CO_OK, scan_env.req_id);
    00220
    00221             scan_env.abort = false;
    00222         }
    00223         else
    00224         {
    00225             // Send the scan end indication to the host
    00226             ke_msg_send_basic(SCAN_DONE_IND, scan_env.req_id, TASK_SCAN);
    00227         }
    00228
    00229         // Put back the state machine to IDLE
    00230         ke_state_set(TASK_SCAN, SCAN_IDLE);
    00231     }
    00232
    00233     //  Return the KE_MSG_CONSUMED status.
    00234     return (KE_MSG_CONSUMED);
    00235 }
    00236
    00237
    00238 /*
    00239  * TASK DESCRIPTOR DEFINITIONS
    00240  ****************************************************************************************
    00241  */
    00243 const struct ke_msg_handler scan_default_state[] =
    00244 {
    00245     // From UMAC
    00246     {SCAN_START_REQ,            (ke_msg_func_t)scan_start_req_handler},
    00247     // From MM
    00248     {MM_SCAN_CHANNEL_START_IND, (ke_msg_func_t)mm_scan_channel_start_ind_handler},
    00249     // From MM
    00250     {MM_SCAN_CHANNEL_END_IND,   (ke_msg_func_t)mm_scan_channel_end_ind_handler},
    00251     // From UMAC
    00252     {SCAN_CANCEL_REQ,           (ke_msg_func_t)scan_cancel_req_handler},
    00253 };
    00254
    00256 const struct ke_state_handler scan_default_handler =
    00257     KE_STATE_HANDLER(scan_default_state);
    00258
    00260 ke_state_t scan_state[SCAN_IDX_MAX];
    00261 #endif
    00262