CWBool CW80211AssembleIEMaxIdlePeriod(char * frame, int * offset, short int value) {
	
	char val=IE_TYPE_BSS_MAX_IDLE_PERIOD;	
	CW_COPY_MEMORY(frame, &(val), IE_TYPE_LEN);
	(*offset) += IE_TYPE_LEN;
	
	val=300;
	CW_COPY_MEMORY((frame+IE_TYPE_LEN), &(val), IE_SIZE_LEN);
	(*offset) += IE_SIZE_LEN;
	
/*
		unsigned int val;
		*pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD;
		*pos++ = 3;
		val = hapd->conf->ap_max_inactivity;
		if (val > 68000)
			val = 68000;
		val *= 1000;
		val /= 1024;
		if (val == 0)
			val = 1;
		if (val > 65535)
			val = 65535;
		WPA_PUT_LE16(pos, val);
		pos += 2;
		*pos++ = 0x00; // TODO: Protected Keep-Alive Required
 */
	CW_COPY_MEMORY((frame+IE_TYPE_LEN+IE_SIZE_LEN), &(value), 1);
	(*offset) += 1;

	return CW_TRUE;
}
CWBool CW80211AssembleIEDSSS(char * frame, int * offset, char value) {
	
	char val=IE_TYPE_DSSS;	
	CW_COPY_MEMORY(frame, &(val), IE_TYPE_LEN);
	(*offset) += IE_TYPE_LEN;
	
	val=1;
	CW_COPY_MEMORY((frame+IE_TYPE_LEN), &(val), IE_SIZE_LEN);
	(*offset) += IE_SIZE_LEN;
	
	CW_COPY_MEMORY((frame+IE_TYPE_LEN+IE_SIZE_LEN), &(value), 1);
	(*offset) += 1;

	return CW_TRUE;
}
CWBool CW80211ParseFrameIEAddr(char * frameReceived, int * offsetFrameReceived, unsigned char * addr) {
	
	CW_COPY_MEMORY(addr, frameReceived, ETH_ALEN);
	(*offsetFrameReceived) += ETH_ALEN;
	
	return CW_TRUE;
}
CWBool CW80211AssembleIEAuthTransNum(char * frame, int * offset, short int value) {

	CW_COPY_MEMORY(frame, &(value), LEN_IE_AUTH_TRANS);
	(*offset) += LEN_IE_AUTH_TRANS;
	
	return CW_TRUE;
}
/* ------------------ PARSE ---------------------- */
CWBool CW80211ParseFrameIEControl(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_FRAME_CONTROL);
	(*offsetFrameReceived) += LEN_IE_FRAME_CONTROL;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIECapability(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_CAPABILITY);
	(*offsetFrameReceived) += LEN_IE_CAPABILITY;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIEStatusCode(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_STATUS_CODE);
	(*offsetFrameReceived) += LEN_IE_STATUS_CODE;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIEAuthAlgo(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_AUTH_ALG);
	(*offsetFrameReceived) += LEN_IE_AUTH_ALG;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIEAuthTransaction(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_AUTH_TRANS);
	(*offsetFrameReceived) += LEN_IE_AUTH_TRANS;
	
	return CW_TRUE;
}
CWBool CW80211AssembleIEStatusCode(char * frame, int * offset, short int value) {

	CW_COPY_MEMORY(frame, &(value), LEN_IE_STATUS_CODE);
	(*offset) += LEN_IE_STATUS_CODE;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIEReasonCode(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_REASON_CODE);
	(*offsetFrameReceived) += LEN_IE_REASON_CODE;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIEAssID(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_ASSOCIATION_ID);
	(*offsetFrameReceived) += LEN_IE_ASSOCIATION_ID;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIESeqCtrl(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_SEQ_CTRL);
	(*offsetFrameReceived) += LEN_IE_SEQ_CTRL;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIEDuration(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_DURATION);
	(*offsetFrameReceived) += LEN_IE_DURATION;
	
	return CW_TRUE;
}
CWBool CW80211ParseFrameIEListenInterval(char * frameReceived, int * offsetFrameReceived, short int * value) {
	
	CW_COPY_MEMORY(value,frameReceived, LEN_IE_LISTEN_INTERVAL);
	(*offsetFrameReceived) += LEN_IE_LISTEN_INTERVAL;
	
	return CW_TRUE;
}
//802.3
CWBool CW8023AssembleHdrLength(char * frame, int * offset, short int value) {

	CW_COPY_MEMORY(frame, &(value), 2);
	(*offset) += 2;
	
	return CW_TRUE;
}
CWBool CW80211AssembleIECapability(char * frame, int * offset, short int value) {

	CW_COPY_MEMORY(frame, &(value), LEN_IE_CAPABILITY);
	(*offset) += LEN_IE_CAPABILITY;
	
	return CW_TRUE;
}
Example #18
0
// retrieves 8 bits from the message, increments the current offset in bytes.
unsigned char CWProtocolRetrieve8(CWProtocolMessage *msgPtr) {
	unsigned char val;
	
	CW_COPY_MEMORY(&val, &((msgPtr->msg)[(msgPtr->offset)]), 1);
	(msgPtr->offset) += 1;
	
	return val;
}
Example #19
0
// retrieves 16 bits from the message, increments the current offset in bytes.
unsigned short CWProtocolRetrieve16(CWProtocolMessage *msgPtr) {
	unsigned short val;
	
	CW_COPY_MEMORY(&val, &((msgPtr->msg)[(msgPtr->offset)]), 2);
	(msgPtr->offset) += 2;
	
	return ntohs(val);
}
CWBool CW80211AssembleIESupportedRates(char * frame, int * offset, char * value, int numRates) {
	
	char val=IE_TYPE_SUPP_RATES;	
	CW_COPY_MEMORY(frame, &(val), IE_TYPE_LEN);
	(*offset) += IE_TYPE_LEN;
	
	if(numRates <= 0)
		return CW_FALSE;
		
	CW_COPY_MEMORY((frame+IE_TYPE_LEN), &(numRates), IE_SIZE_LEN);
	(*offset) += IE_SIZE_LEN;
	
	CW_COPY_MEMORY((frame+IE_TYPE_LEN+IE_SIZE_LEN), value, numRates);
	(*offset) += numRates;
	
	return CW_TRUE;
}
CWBool CW80211AssembleIESSID(char * frame, int * offset, char * value) {
	//Type
	unsigned char val=IE_TYPE_SSID;	
	CW_COPY_MEMORY(frame, &(val), IE_TYPE_LEN);
	(*offset) += IE_TYPE_LEN;
	
	//len
	val=strlen(value);
	CW_COPY_MEMORY((frame+IE_TYPE_LEN), &(val), IE_SIZE_LEN);
	(*offset) += IE_SIZE_LEN;
	
	//value
	CW_COPY_MEMORY((frame+IE_TYPE_LEN+IE_SIZE_LEN), value, strlen(value));
	(*offset) += strlen(value);

	return CW_TRUE;
}
CWBool CW80211AssembleIEAssID(char * frame, int * offset, short int value) {
	value |= BIT(14);
	value |= BIT(15);
	CW_COPY_MEMORY(frame, &(value), LEN_IE_ASSOCIATION_ID);
	(*offset) += LEN_IE_ASSOCIATION_ID;
	
	return CW_TRUE;
}
Example #23
0
// retrieves 32 bits from the message, increments the current offset in bytes.
unsigned int CWProtocolRetrieve32(CWProtocolMessage *msgPtr) {
	unsigned int val;
	
	CW_COPY_MEMORY(&val, &((msgPtr->msg)[(msgPtr->offset)]), 4);
	(msgPtr->offset) += 4;
	
	return ntohl(val);
}
CWBool CW80211AssembleIEBeaconInterval(char * frame, int * offset, short int value) {
	
	short int val = htons(host_to_le16(value));
	
	CW_COPY_MEMORY(frame, &(val), LEN_IE_BEACON_INT);
	(*offset) += LEN_IE_BEACON_INT;
	
	return CW_TRUE;
}
/* FIXED LEN IE */
CWBool CW80211AssembleIEFrameControl(char * frame, int * offset, int frameType, int frameSubtype) {
	
	short int val = IEEE80211_FC(frameType, frameSubtype);
	
	CW_COPY_MEMORY(frame, &(val), LEN_IE_FRAME_CONTROL);
	(*offset) += LEN_IE_FRAME_CONTROL;
	
	return CW_TRUE;
}
CWBool CW80211AssembleIESequenceNumber(char * frame, int * offset, int value) {
	
	short int val = htons(host_to_le16(value));
	
	CW_COPY_MEMORY(frame, &(val), LEN_IE_SEQ_CTRL);
	(*offset) += LEN_IE_SEQ_CTRL;
	
	return CW_TRUE;
}
CWBool CW80211AssembleIEDuration(char * frame, int * offset, int value) {
	
	short int val = htons(host_to_le16(value));
	
	CW_COPY_MEMORY(frame, &(val), LEN_IE_DURATION);
	(*offset) += LEN_IE_DURATION;
	
	return CW_TRUE;
}
Example #28
0
/* 
 * Receive a message, that can be fragmented. This is useful not only for the Join State
 */
CWBool CWReceiveMessage(CWProtocolMessage *msgPtr) {
	CWList fragments = NULL;
	int readBytes;
	char buf[CW_BUFFER_SIZE];
	CWBool dataFlag = CW_FALSE;
	
	CW_REPEAT_FOREVER {
		CW_ZERO_MEMORY(buf, CW_BUFFER_SIZE);
#ifdef CW_NO_DTLS
		char *pkt_buffer = NULL;

		CWLockSafeList(gPacketReceiveList);

		while (CWGetCountElementFromSafeList(gPacketReceiveList) == 0)
			CWWaitElementFromSafeList(gPacketReceiveList);

		pkt_buffer = (char*)CWRemoveHeadElementFromSafeListwithDataFlag(gPacketReceiveList, &readBytes,&dataFlag);

		CWUnlockSafeList(gPacketReceiveList);

		CW_COPY_MEMORY(buf, pkt_buffer, readBytes);
		CW_FREE_OBJECT(pkt_buffer);
#else
		if(!CWSecurityReceive(gWTPSession, buf, CW_BUFFER_SIZE, &readBytes)) {return CW_FALSE;}
#endif

		if(!CWProtocolParseFragment(buf, readBytes, &fragments, msgPtr, &dataFlag, NULL)) {
			if(CWErrorGetLastErrorCode() == CW_ERROR_NEED_RESOURCE) { // we need at least one more fragment
				continue;
			} else { // error
				CWErrorCode error;
				error=CWErrorGetLastErrorCode();
				switch(error)
				{
					case CW_ERROR_SUCCESS: {CWDebugLog("ERROR: Success"); break;}
					case CW_ERROR_OUT_OF_MEMORY: {CWDebugLog("ERROR: Out of Memory"); break;}
					case CW_ERROR_WRONG_ARG: {CWDebugLog("ERROR: Wrong Argument"); break;}
					case CW_ERROR_INTERRUPTED: {CWDebugLog("ERROR: Interrupted"); break;}
					case CW_ERROR_NEED_RESOURCE: {CWDebugLog("ERROR: Need Resource"); break;}
					case CW_ERROR_COMUNICATING: {CWDebugLog("ERROR: Comunicating"); break;}
					case CW_ERROR_CREATING: {CWDebugLog("ERROR: Creating"); break;}
					case CW_ERROR_GENERAL: {CWDebugLog("ERROR: General"); break;}
					case CW_ERROR_OPERATION_ABORTED: {CWDebugLog("ERROR: Operation Aborted"); break;}
					case CW_ERROR_SENDING: {CWDebugLog("ERROR: Sending"); break;}
					case CW_ERROR_RECEIVING: {CWDebugLog("ERROR: Receiving"); break;}
					case CW_ERROR_INVALID_FORMAT: {CWDebugLog("ERROR: Invalid Format"); break;}
					case CW_ERROR_TIME_EXPIRED: {CWDebugLog("ERROR: Time Expired"); break;}
					case CW_ERROR_NONE: {CWDebugLog("ERROR: None"); break;}
				}
				CWDebugLog("~~~~~~");
				return CW_FALSE;
			}
		} else break; // the message is fully reassembled
	}
	
	return CW_TRUE;
}
CWBool CW80211AssembleIEAddr(char * frame, int * offset, char * value) {
	//Broadcast
	if(value == NULL)
		memset(frame, 0xff, ETH_ALEN);
	else
		CW_COPY_MEMORY(frame, value, ETH_ALEN);
		
	(*offset) += ETH_ALEN;
	
	return CW_TRUE;
}
CWBool CW80211AssembleIEFrameControlData(char * frame, int * offset, int frameType, int frameSubtype, int toDS, int fromDS) {
		
	short int val = IEEE80211_FC(frameType, frameSubtype);
	if(toDS == 1)
		SETBIT(val,8);
	else
		CLEARBIT(val,8);
		
	if(fromDS == 1)
		SETBIT(val,9);
	else
		CLEARBIT(val,9);

	CW_COPY_MEMORY(frame, &(val), LEN_IE_FRAME_CONTROL);
	(*offset) += LEN_IE_FRAME_CONTROL;
	
	return CW_TRUE;
}