/* * Manage Join State. */ CWStateTransition CWWTPEnterJoin() { CWTimerID waitJoinTimer; int seqNum; CWProtocolJoinResponseValues values; CWLog("\n"); CWLog("######### Join State #########"); /* reset Join state */ CWNetworkCloseSocket(gWTPSocket); CWSecurityDestroySession(gWTPSession); CWSecurityDestroyContext(gWTPSecurityContext); gWTPSecurityContext = NULL; gWTPSession = NULL; /* Initialize gACInfoPtr */ gACInfoPtr->ACIPv4ListInfo.ACIPv4ListCount=0; gACInfoPtr->ACIPv4ListInfo.ACIPv4List=NULL; gACInfoPtr->ACIPv6ListInfo.ACIPv6ListCount=0; gACInfoPtr->ACIPv6ListInfo.ACIPv6List=NULL; if ((waitJoinTimer = timer_add(gCWWaitJoin, 0, CWWTPWaitJoinExpired, NULL)) == -1) { return CW_ENTER_DISCOVERY; } if(gWTPForceACAddress != NULL) { CW_CREATE_OBJECT_ERR(gACInfoPtr, CWACInfoValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
// Manage Join State CWStateTransition CWWTPEnterJoin() { CWTimerID waitJoinTimer; int seqNum; CWProtocolJoinResponseValues values; CWWTPDebugLog("######### Join State #########"); // reset Join state CWNetworkCloseSocket(gWTPSocket); #ifndef CW_NO_DTLS//csc if(gDtlsSecurity == 1) { CWSecurityDestroySession(gWTPSession); CWSecurityDestroyContext(gWTPSecurityContext); gWTPSecurityContext = NULL; gWTPSession = NULL; } #endif //Initialize gACInfoPtr gACInfoPtr->ACIPv4ListInfo.ACIPv4ListCount=0; gACInfoPtr->ACIPv4ListInfo.ACIPv4List=NULL; gACInfoPtr->ACIPv6ListInfo.ACIPv6ListCount=0; gACInfoPtr->ACIPv6ListInfo.ACIPv6List=NULL; /* * MAURO: allo scadere del waitJoinTimer viene invocata, in modo * asincrono, CWWTPWaitJoinExpired(0) */ if ((waitJoinTimer = timer_add(gCWWaitJoin, 0, CWWTPWaitJoinExpired, NULL)) == -1) { return CW_ENTER_DISCOVERY; } /* * MAURO: gWTPForceACAddress contine l'"indirizzo" dell'AC con cui fare * il JOIN nel caso che sia specificato nel file di configuarazione. * Se questa var globale e' settata da WTP.c viene invocata direttamente * CWWTPEnterJoin per saltare il DISCOVERY. */ if(gWTPForceACAddress != NULL) { CW_CREATE_OBJECT_ERR(gACInfoPtr, CWACInfoValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
/* * Manage Join State. */ CWStateTransition CWWTPEnterJoin() { CWTimerID waitJoinTimer; int seqNum; CWProtocolJoinResponseValues values; CWStateTransition state = CW_ENTER_DISCOVERY; CWDebugLog("Checking if hostapd is connected..."); if (gRADIO_MAC[0] == 0xAA){ CWDebugLog("Waiting for hostapd to connect..."); while(gRADIO_MAC[0] == 0xAA) sleep(1); } else { CWDebugLog("Hostapd is connected..."); } CWDebugLog("\n"); CWDebugLog("######### Join State #########"); /* reset Join state */ CWNetworkCloseSocket(gWTPSocket); #ifndef CW_NO_DTLS CWSecurityDestroySession(gWTPSession); CWSecurityDestroyContext(gWTPSecurityContext); #endif gWTPSecurityContext = NULL; gWTPSession = NULL; /* Initialize gACInfoPtr */ gACInfoPtr = malloc(sizeof(CWACInfoValues)); gACInfoPtr->ACIPv4ListInfo.ACIPv4ListCount = 0; gACInfoPtr->ACIPv4ListInfo.ACIPv4List = NULL; gACInfoPtr->ACIPv6ListInfo.ACIPv6ListCount = 0; gACInfoPtr->ACIPv6ListInfo.ACIPv6List = NULL; CWDebugLog("State is %d", state); if (gWTPForceACAddress != NULL) { CW_CREATE_OBJECT_ERR(gACInfoPtr, CWACInfoValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); );
/* * Manage Discovery State */ CWStateTransition CWWTPEnterDiscovery() { int i; CWBool j; CWLog("\n"); CWLog("######### Discovery State #########"); /* reset Discovery state */ gCWDiscoveryCount = 0; CWNetworkCloseSocket(gWTPSocket); if (!CWErr(CWNetworkInitSocketClient(&gWTPSocket, NULL))) { return CW_QUIT; } /* * note: gCWACList can be freed and reallocated (reading from config file) * at each transition to the discovery state to save memory space */ for (i = 0; i < gCWACCount; i++) gCWACList[i].received = CW_FALSE; /* wait a random time */ sleep(CWRandomIntInRange(gCWDiscoveryInterval, gCWMaxDiscoveryInterval)); CW_REPEAT_FOREVER { CWBool sentSomething = CW_FALSE; /* we get no responses for a very long time */ if (gCWDiscoveryCount == gCWMaxDiscoveries) return CW_ENTER_SULKING; /* send Requests to one or more ACs */ for (i = 0; i < gCWACCount; i++) { /* if this AC hasn't responded to us... */ if (!(gCWACList[i].received)) { /* ...send a Discovery Request */ CWProtocolMessage *msgPtr = NULL; /* get sequence number (and increase it) */ gCWACList[i].seqNum = CWGetSeqNum(); if (!CWErr(CWAssembleDiscoveryRequest(&msgPtr, gCWACList[i].seqNum))) { exit(1); } CW_CREATE_OBJECT_ERR(gACInfoPtr, CWACInfoValues, return CW_QUIT; ); CWNetworkGetAddressForHost(gCWACList[i].address, &(gACInfoPtr->preferredAddress)); CWUseSockNtop(&(gACInfoPtr->preferredAddress), CWDebugLog(str); ); j = CWErr(CWNetworkSendUnsafeUnconnected(gWTPSocket, &(gACInfoPtr->preferredAddress), (*msgPtr).msg, (*msgPtr).offset)); /* * log eventual error and continue * CWUseSockNtop(&(gACInfoPtr->preferredAddress), * CWLog("WTP sends Discovery Request to: %s", str);); */ CW_FREE_PROTOCOL_MESSAGE(*msgPtr); CW_FREE_OBJECT(msgPtr); CW_FREE_OBJECT(gACInfoPtr); /* * we sent at least one Request in this loop * (even if we got an error sending it) */ sentSomething = CW_TRUE; }