📄 dot11smeibsslib.c
字号:
/***************************************************************************** dot11SmeIbssStateTaskFree - De-initialize the IBSS state task** This routine frees all objects associated with the state task.** RETURNS: OK or ERROR** ERRNO: N/A*/LOCAL STATUS dot11SmeIbssStateTaskFree ( DOT11_FW * pDot11 /* Ptr to DOT11 framework root obj */ ) { STATUS status = OK; DOT11_IBSS_OBJ * pIbss; DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssStateTaskFree: Freeing.\n", 0,0,0,0,0,0)); pIbss = &pDot11->sme->type.ibss; /* Try to shutdown the task gracefully. If it doesn't shutdown within the specified time, then shut it down forcefully */ if (dot11SmeIbssLinkEventNotify(pDot11, DOT11_IBSS_EV_SHUTDOWN) == OK) { /* Wait for the task to delete itself */ taskDelay(DOT11_IBSS_TASK_DELETE_TIMEOUT); } if (taskIdVerify(pIbss->stateTid) != ERROR) { if (taskDelete(pIbss->stateTid) == ERROR) { DOT11_LOG(DOT11_DEBUG_ERROR, DOT11_AREA_SME, ("dot11SmeIbssStateTaskFree: Error deleting task %08x.\n" ,pIbss->stateTid,0,0,0,0,0)); /* Don't exit - continue freeing what resources we can */ status = ERROR; } } if (msgQDelete(pIbss->stateMsgQ) != OK) { DOT11_LOG(DOT11_DEBUG_ERROR, DOT11_AREA_SME, ("dot11SmeIbssStateTaskFree: Error deleting task %08x.\n" ,pIbss->stateTid,0,0,0,0,0)); status = ERROR; } pIbss->stateTid = -1; pIbss->stateMsgQ = NULL; return status; }/***************************************************************************** dot11SmeIbssStateTask - The task loop for the IBSS state task** This routine adjusts the state of the state machine depending on events* received on its event queue. The possible events are:* DOT11_IBSS_EV_RESET* DOT11_IBSS_EV_JOIN_REQ,* DOT11_IBSS_EV_CREATE_IBSS,* DOT11_IBSS_EV_JOIN_IBSS* DOT11_IBSS_EV_SHUTDOWN** These events will drive the station through the following states:** DOT11_IBSS_STATE_NOIBSS, * DOT11_IBSS_STATE_SEARCHING, * DOT11_IBSS_STATE_CONNECTED ** RETURNS: OK or ERROR** ERRNO: N/A*/LOCAL void dot11SmeIbssStateTask ( DOT11_FW * pDot11 /* Ptr to DOT11 framework root obj */ ) { DOT11_IBSS_EV event; DOT11_IBSS_OBJ * pIbss; pIbss = &pDot11->sme->type.ibss; FOREVER { event = -1; /* Pend on the message queue until we get a link event message */ if (msgQReceive(pIbss->stateMsgQ, (char *)&event, sizeof(DOT11_IBSS_EV), WAIT_FOREVER) == ERROR) { DOT11_LOG(DOT11_DEBUG_FATAL, DOT11_AREA_SME, ("dot11SmeIbssStateTask: Err in msgQ, errno = 0x%08x\n", errno,0,0,0,0,0)); break; } DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssStateTask: Got event %d\n", event,0,0,0,0,0)); if (event == DOT11_IBSS_EV_SHUTDOWN) { /* Exit the task cleanly by breaking the FOREVER loop */ break; } switch(event) { case DOT11_IBSS_EV_RESET: DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssStateTask: RESET\n", 0,0,0,0,0,0)); dot11SmeIbssResetProcess(pDot11); break; case DOT11_IBSS_EV_JOIN_REQ: DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssStateTask: JOIN_REQ\n", 0,0,0,0,0,0)); dot11SmeIbssJoinReqProcess(pDot11); break; case DOT11_IBSS_EV_CREATE_IBSS: DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssStateTask: CREATE_IBSS\n", 0,0,0,0,0,0)); dot11SmeIbssCreateIbssProcess(pDot11); break; case DOT11_IBSS_EV_JOIN_IBSS: DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssStateTask: JOIN_IBSS\n", 0,0,0,0,0,0)); dot11SmeIbssJoinIbssProcess(pDot11); break; case DOT11_IBSS_EV_SYNC_IBSS: DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssStateTask: SYNC_IBSS\n", 0,0,0,0,0,0)); dot11SmeIbssSyncIbssProcess(pDot11); break; default: DOT11_LOG(DOT11_DEBUG_ERROR, DOT11_AREA_SME, ("dot11SmeIbssStateTask: Unknown event %d\n", event,0,0,0,0,0)); break; } if (pIbss->state == DOT11_IBSS_STATE_CONNECTED) { DOT11_DEFAULT_BSS->linkStatus = DOT11_LINK_UP; } else { DOT11_DEFAULT_BSS->linkStatus = DOT11_LINK_DOWN; } } DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssStateTask: Exiting\n",0,0,0,0,0,0)); return; }/***************************************************************************** dot11SmeIbssLinkEventNotify - Passes events to the state task** This routine, which can be called from any context, passes the event* to the state task message queue for processing.** RETURNS: OK or ERROR** ERRNO: N/A*/LOCAL STATUS dot11SmeIbssLinkEventNotify ( DOT11_FW * pDot11, /* Ptr to DOT11 framework root obj */ int event /* Event to pass to state task */ ) { DOT11_IBSS_OBJ * pIbss; pIbss = &pDot11->sme->type.ibss; if (msgQSend(pIbss->stateMsgQ, (char *)&event, sizeof(int), NO_WAIT, MSG_PRI_NORMAL) != OK) { DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssLinkEventNotify: Err sending to msgQ, " "errno = 0x%08x\n", errno,0,0,0,0,0)); return ERROR; } return OK; }/***************************************************************************** dot11SmeIbssResetProcess - Handles a RESET event** This event is generated when there is an error in the state machine and* init cannot proceed with normal operation. The state machine is reset and * placed in the NOIBSS state as a result.** RETURNS: OK or ERROR** ERRNO: N/A*/LOCAL STATUS dot11SmeIbssResetProcess ( DOT11_FW * pDot11 /* Ptr to DOT11 framework root obj */ ) { DOT11_IBSS_OBJ * pIbss; pIbss = &pDot11->sme->type.ibss; DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssResetProcess: Started\n", 0,0,0,0,0,0)); /* If we are generating beacons, stop it */ if (pIbss->beaconing) { dot11SmeIbssBeaconStop(pDot11); bzero((char *)DOT11_DEFAULT_BSS->bssid, DOT11_ADDR_LEN); } taskLock(); pIbss->state = DOT11_IBSS_STATE_NOIBSS; taskUnlock(); return OK; }/***************************************************************************** dot11SmeIbssJoinReq - Handles a JOIN_REQ event** This routine executes a join request by performing the following steps:* 1. Flush the KSL to erase old entries* 2. Perform a passive and/or active scan on the current channel* 3. See if there are any KSL entries that match the current SSID* a. If so, grab the bssid (assuming there is only one) and issue* a IBSS_JOIN event.* b. If not, issue IBSS_CREATE, which will make a new bssid** Note that the ANY ssid is supported for an IBSS, but it disables the * creation of an IBSS - only an existing IBSS can be joined.** RETURNS: OK or ERROR** ERRNO: N/A*/LOCAL STATUS dot11SmeIbssJoinReqProcess ( DOT11_FW * pDot11 /* Ptr to DOT11 framework root obj */ ) { DOT11_IBSS_OBJ * pIbss; /* Ptr to IBSS data */ DOT11_KSL_ENTRY * pKsl; /* Ptr to matching KSL entry */ DOT11_IE_SSID ssid; /* IE for probe req */ pIbss = &pDot11->sme->type.ibss; DOT11_LOG(DOT11_DEBUG_INFO, DOT11_AREA_SME, ("dot11SmeIbssJoinReqProcess: Started\n", 0,0,0,0,0,0)); /* The ANY ssid is valid for an IBSS join req (but only if there is an IBSS), but not the NULL ssid */ if (pDot11->desiredSsid == NULL) { DOT11_LOG(DOT11_DEBUG_ERROR, DOT11_AREA_SME, ("dot11SmeIbssJoinReqProcess: NULL SSID not supported\n", 0,0,0,0,0,0)); dot11SmeIbssLinkEventNotify(pDot11, DOT11_IBSS_EV_RESET); return OK; } taskLock(); pIbss->state = DOT11_IBSS_STATE_SEARCHING; taskUnlock(); /* Flush the KSL to erase any stale entries. */ pDot11->sme->ksl.flush(pDot11); /* Since we're searching, set the sync flag to FALSE, so that we store the timestamp of any beacons we encounter */ /* Perform an active scan if desired */ if (pDot11->sme->activeScan) { ssid.elementId = DOT11_ELEMID_SSID; ssid.length = strlen(pDot11->desiredSsid); /* We deliberately don't account for the NULL-terminator, since the 802.11 SSID IE is not null-terminated */ strncpy(ssid.ssid, pDot11->desiredSsid, DOT11_SSID_LEN); pDot11->sme->probeReqSend(pDot11, &ssid, &pDot11->sme->suppRates, DOT11_DEFAULT_BSS); } /* The wait time is the maximum of the passive and active scan times, assuming (it seems safe) that the passive delay is always more than the active delay.*/ if (pDot11->sme->activeScan) { taskDelay(DOT11_SCAN_ACTIVE_DWELL_TIME); } if (pDot11->sme->passiveScan) { taskDelay(max(0, DOT11_SCAN_PASSIVE_DWELL_TIME - ((int)pDot11->sme->activeScan * DOT11_SCAN_ACTIVE_DWELL_TIME))); } /* Get the lock on the KSL */ if (pDot11->sme->ksl.lock(pDot11) != OK) { DOT11_LOG(DOT11_DEBUG_ERROR, DOT11_AREA_SME, ("dot11SmeIbssJoinReqProcess: Cannot get KSL lock\n", 0,0,0,0,0,0)); dot11SmeIbssLinkEventNotify(pDot11, DOT11_IBSS_EV_RESET); return ERROR; } /* See if a suitable BSS was found. */ if((pKsl = pDot11->sme->ksl.ssidLookup(pDot11, pDot11->desiredSsid, DOT11_MODE_IBSS)) != NULL) { /* Since we're joining an existing BSS, coipy the BSSID over */ bcopy((char *)pKsl->type.ibss.bssid, (char *)DOT11_DEFAULT_BSS->bssid, DOT11_ADDR_LEN); /* Set the KSL pointer for the current BSS to point to the station we got above. The station is not the IBSS, but it should have all of the parameters of the station. */ pDot11->sme->type.ibss.pKslIbss = pKsl; /* Notify the state machine to join an existing IBSS, particularily that referenced in pKslIbss above */ dot11SmeIbssLinkEventNotify(pDot11, DOT11_IBSS_EV_JOIN_IBSS); } else /* No matching entry found */ { if (dot11SmeIbssBssidCreate(pDot11, DOT11_DEFAULT_BSS->bssid) != OK) { pDot11->sme->type.ibss.pKslIbss = NULL; pDot11->sme->ksl.unlock(pDot11); dot11SmeIbssLinkEventNotify(pDot11, DOT11_IBSS_EV_RESET); return ERROR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -