int wsc_event_notify(char * pDataSend) { static int initialized=0; static int event_sock=0; struct sockaddr_in to; struct sockaddr_in from; char tmpBuffer[WSC_EVENT_RX_BUF_SIZE]; int recvBytes; if(initialized==0){ event_sock = udp_open(); initialized ++; } memset(&to,0,sizeof(to)); to.sin_addr.s_addr = inet_addr(WSC_EVENT_ADDR); to.sin_family = AF_INET; to.sin_port = htons(WSC_EVENT_PORT); if (udp_write(event_sock, pDataSend, strlen(pDataSend), &to) < strlen(pDataSend)) { wpa_printf(MSG_ERROR, "Hostapd: Sending WSC event to " "upper Layer failed"); return 1; } recvBytes = udp_read_timed(event_sock, (char *) tmpBuffer, WSC_EVENT_RX_BUF_SIZE, &from, 15); if (recvBytes == -1) { wpa_printf(MSG_INFO, "EAP-WSC: Event messageACK timeout failure\n"); return 1; } if(strncmp(tmpBuffer,WSC_EVENT_ACK_STRING, strlen(WSC_EVENT_ACK_STRING))!=0) { wpa_printf(MSG_INFO, "EAP-WSC: wrong WSC_EVENT ACK message \n"); return 1; } return 0; }
static u8 * eap_wsc_com_buildReq(struct eap_sm *sm, struct eap_wsc_data *data, int id, size_t *reqDataLen) { u8 *req = NULL; int recvBytes; struct sockaddr_in from; struct sockaddr_in to; WSC_NOTIFY_DATA notifyData; WSC_NOTIFY_DATA * recvNotify; notifyData.type = WSC_NOTIFY_TYPE_BUILDREQ; notifyData.u.bldReq.id = id; notifyData.u.bldReq.state = data->state; notifyData.length = 0; to.sin_addr.s_addr = inet_addr(WSC_EAP_UDP_ADDR); to.sin_family = AF_INET; to.sin_port = htons(WSC_EAP_UDP_PORT); memcpy(notifyData.sta_mac_addr, sm->sta->addr, ETH_ALEN); if (udp_write(data->udpFdEap, (char *) ¬ifyData, sizeof(WSC_NOTIFY_DATA), &to) < sizeof(WSC_NOTIFY_DATA)) { wpa_printf(MSG_INFO, "EAP-WSC: Sending Eap message to " "upper Layer failed\n"); data->state = FAILURE; return NULL; } recvBytes = udp_read_timed(data->udpFdEap, (char *) data->recvBuf, WSC_RECVBUF_SIZE, &from, 15); /* Jerry timeout value */ if (recvBytes == -1) { wpa_printf(MSG_INFO, "EAP-WSC: req Reading EAP message " "from upper layer failed\n"); data->state = FAILURE; return NULL; } recvNotify = (WSC_NOTIFY_DATA *) data->recvBuf; if ( (recvNotify->type != WSC_NOTIFY_TYPE_BUILDREQ_RESULT) || (recvNotify->length == 0) || (recvNotify->u.bldReqResult.result != WSC_NOTIFY_RESULT_SUCCESS) ) { wpa_printf(MSG_INFO, "EAP-WSC: Build Request failed " "soemwhere\n"); data->state = FAILURE; return NULL; } req = (u8 *) malloc(recvNotify->length); if ( ! req) { wpa_printf(MSG_INFO, "EAP-WSC: Memory allocation " "for the request failed\n"); data->state = FAILURE; return NULL; } memcpy(req, recvNotify + 1, recvNotify->length); *reqDataLen = recvNotify->length; data->state = CONTINUE; sm->eapol_cb->set_eap_respTimeout(sm->eapol_ctx,15); return req; }
static int eap_wsc_com_process(struct eap_sm *sm, struct eap_wsc_data *data, u8 * respData, unsigned int respDataLen) { int recvBytes; struct sockaddr_in from; struct sockaddr_in to; u8 * sendBuf; u32 sendBufLen; WSC_NOTIFY_DATA notifyData; WSC_NOTIFY_DATA * recvNotify; notifyData.type = WSC_NOTIFY_TYPE_PROCESS_RESP; notifyData.length = respDataLen; notifyData.u.process.state = data->state; memcpy(notifyData.sta_mac_addr, sm->sta->addr, ETH_ALEN); sendBuf = (u8 *) malloc(sizeof(WSC_NOTIFY_DATA) + respDataLen); if ( ! sendBuf) { wpa_printf(MSG_INFO, "EAP-WSC: Memory allocation " "for the sendBuf failed\n"); data->state = FAILURE; return -1; } memcpy(sendBuf, ¬ifyData, sizeof(WSC_NOTIFY_DATA)); memcpy(sendBuf + sizeof(WSC_NOTIFY_DATA), respData, respDataLen); sendBufLen = sizeof(WSC_NOTIFY_DATA) + respDataLen; to.sin_addr.s_addr = inet_addr(WSC_EAP_UDP_ADDR); to.sin_family = AF_INET; to.sin_port = htons(WSC_EAP_UDP_PORT); if (udp_write(data->udpFdEap, (char *) sendBuf, sendBufLen, &to) < sendBufLen) { wpa_printf(MSG_INFO, "EAP-WSC: com Sending Eap message to " "upper Layer failed\n"); data->state = FAILURE; free(sendBuf); return -1; } free(sendBuf); recvBytes = udp_read_timed(data->udpFdEap, (char *) data->recvBuf, WSC_RECVBUF_SIZE, &from, 15); /* Jerry timeout value change*/ if (recvBytes == -1) { wpa_printf(MSG_INFO, "EAP-WSC: com Reading EAP message " "from upper layer failed\n"); data->state = FAILURE; return -1; } recvNotify = (WSC_NOTIFY_DATA *) data->recvBuf; /* printf("type = %d, length = %d, result = %d\n", recvNotify->type, recvNotify->length, recvNotify->u.processResult.result);*/ if ( (recvNotify->type != WSC_NOTIFY_TYPE_PROCESS_RESULT) || (recvNotify->u.processResult.result != WSC_NOTIFY_RESULT_SUCCESS) ) { wpa_printf(MSG_DEBUG, "EAP-WSC: Process Message failed " "somewhere\n"); data->state = FAILURE; return -1; } data->state = CONTINUE; return 0; }
static u8 * eap_wps_process(struct eap_sm *sm, void *priv, struct eap_method_ret *ret, const u8 *reqData, size_t reqDataLen, size_t *respDataLen) { struct eap_wps_data *data = priv; struct eap_hdr *req; int recvBytes; u8 * resp; u8 * sendBuf; u32 sendBufLen; struct sockaddr_in from; struct sockaddr_in to; WPS_NOTIFY_DATA notifyData; WPS_NOTIFY_DATA * recvNotify; wpa_printf(MSG_DEBUG,"@#*@#*@#*EAP-WPS: Entered eap_wps_process *#@*#@*#@"); req = (struct eap_hdr *) reqData; wpa_printf(MSG_DEBUG, "EAP-WPS : Received packet(len=%lu) ", (unsigned long) reqDataLen); if(ntohs(req->length) != reqDataLen) { wpa_printf(MSG_INFO, "EAP-WPS: Pkt length in pkt(%d) differs from" " supplied (%d)\n", ntohs(req->length), reqDataLen); ret->ignore = TRUE; return NULL; } notifyData.type = WPS_NOTIFY_TYPE_PROCESS_REQ; notifyData.length = reqDataLen; notifyData.u.process.state = data->state; sendBuf = (u8 *) os_malloc(sizeof(WPS_NOTIFY_DATA) + reqDataLen); if ( ! sendBuf) { wpa_printf(MSG_INFO, "EAP-WPS: Memory allocation " "for the sendBuf failed\n"); ret->ignore = TRUE; return NULL; } os_memcpy(sendBuf, ¬ifyData, sizeof(WPS_NOTIFY_DATA)); os_memcpy(sendBuf + sizeof(WPS_NOTIFY_DATA), reqData, reqDataLen); sendBufLen = sizeof(WPS_NOTIFY_DATA) + reqDataLen; to.sin_addr.s_addr = inet_addr(WPS_EAP_UDP_ADDR); to.sin_family = AF_INET; to.sin_port = host_to_be16(WPS_EAP_UDP_PORT); if (udp_write(data->udpFdEap, (char *) sendBuf, sendBufLen, &to) < sendBufLen) { wpa_printf(MSG_INFO, "EAP-WPS: Sending Eap message to " "upper Layer failed\n"); ret->ignore = TRUE; os_free(sendBuf); return NULL; } os_free(sendBuf); recvBytes = udp_read_timed(data->udpFdEap, (char *) data->recvBuf, WPS_RECVBUF_SIZE, &from, 5); if (recvBytes == -1) { wpa_printf(MSG_INFO, "EAP-WPS: Reading EAP message " "from upper layer failed\n"); ret->ignore = TRUE; return NULL; } recvNotify = (WPS_NOTIFY_DATA *) data->recvBuf; if ( (recvNotify->type != WPS_NOTIFY_TYPE_PROCESS_RESULT) || // (recvNotify->length == 0) || (recvNotify->u.processResult.result != WPS_NOTIFY_RESULT_SUCCESS) ) { wpa_printf(MSG_INFO, "EAP-WPS: Process Message failed " "somewhere\n"); ret->ignore = TRUE; return NULL; } resp = (u8 *) os_malloc(recvNotify->length); if ( ! resp) { wpa_printf(MSG_INFO, "EAP-WPS: Memory allocation " "for the resp failed\n"); ret->ignore = TRUE; return NULL; } os_memcpy(resp, recvNotify + 1, recvNotify->length); *respDataLen = recvNotify->length; ret->ignore = FALSE; ret->decision = DECISION_COND_SUCC; ret->allowNotifications = FALSE; /*check if we're done*/ if (recvNotify->u.processResult.done) { ret->methodState = METHOD_DONE; } else { wpa_printf(MSG_INFO, "Always setting it to METHOD_CONT\n"); ret->methodState = METHOD_CONT; } return resp; }