int wtpinfo_lwreadelem_wtp_descriptor(struct wtpinfo * wtpinfo, int type, uint8_t *msgelem, int len)
{
	if (type != LW_ELEM_WTP_DESCRIPTOR)
		return 0;

/*	if (len!=16)
		return -1;
*/

	char  str[64];	
	uint32_t hwversion=ntohl(*((uint32_t*)(msgelem)));
	sprintf(str,"%08X",hwversion);
	cw_setstr(&wtpinfo->hardware_version,(uint8_t*)str,strlen(str));

	uint32_t swversion=ntohl(*((uint32_t*)(msgelem+4)));
	sprintf(str,"%08X",swversion);
	cw_setstr(&wtpinfo->software_version,(uint8_t*)str,strlen(str));

	uint32_t btversion=ntohl(*((uint32_t*)(msgelem+8)));
	sprintf(str,"%08X",btversion);
	cw_setstr(&wtpinfo->bootloader_version,(uint8_t*)str,strlen(str));

	uint32_t l=ntohl(*((uint32_t*)(msgelem+12)));
	
	wtpinfo->max_radios = l >> 24;
	wtpinfo->radios_in_use = (l>>16) & 0xff;


	return 1;
}
Exemple #2
0
int cw_readelem_ac_name(uint8_t **dst, int type,uint8_t *msgelem, int len)
{
	if (type != CWMSGELEM_AC_NAME)
		return 0;
	cw_setstr(dst,msgelem,len);
	return 1;
}
/**
 * Reads the LWAPP message element WTP Name
 * @param dts where to store the WTP name
 * @param type msg element type, must be #LWMSGELEM_WTP_NAME
 * @param msgelem the msg element
 * @param len length of msg element
 * return 0 No WTP name msg elem\n 1=Success 
 */
int lw_readelem_wtp_name(uint8_t ** dst, int type, uint8_t * msgelem, int len)
{
	if (type != LW_ELEM_WTP_NAME)
		return 0;

	
	if (len>254){
		cw_dbg(DBG_MSG_ERR,"Truncating WTP_NAME msgelem to 254, wrong size, type=%d,len=%d",type,len);
		len=254;
	}

	cw_setstr(dst,msgelem,len);
	return 1;
}
Exemple #4
0
int wtpconf_name()
{
	if (conf_wtpname)
		return 1;
	
	char name[64];
	sprintf(name,"WTP%s",sock_hwaddr2idstr(conf_macaddress,conf_macaddress_len));

	conf_wtpname = (char*)cw_setstr((uint8_t**)&conf_wtpname,(uint8_t*)name,strlen(name)); 
	if (!conf_wtpname)
		return 0;

	cw_dbg(DBG_INFO,"Using self assigned wtp name: %s",conf_wtpname);

	return 1;
}
static int wtpinfo_readelem_wtp_descriptor_(struct wtpinfo * wtpinfo, int type, uint8_t *msgelem, int len, int cq)
{
	if (type != CWMSGELEM_WTP_DESCRIPTOR)
		return 0;

	if (len<6)
		return -1;

	wtpinfo->max_radios=*msgelem;
	wtpinfo->radios_in_use=*(msgelem+1);

	int ncrypt = *(msgelem+2);
	int i;
	if (ncrypt == 0 ){
		/* non-conform */
		cw_log_debug1("Non-standard-conform WTP descriptor detected (See RFC 5415)");
		if (!cq) 
			i=3;
		else
			i=4;
	}
	else{
		i=ncrypt*3+3;
	}

	do {
		if (i+8>len)
		{
			cw_log_debug1("WTP descriptor subelement to long, length=%d>%d",i+8,len);
			return -1;
		}

		uint32_t vendor_id=ntohl(*((uint32_t*)(msgelem+i)));

		uint32_t val = ntohl(*((uint32_t*)(msgelem+i+4)));
		int subtype= (val>>16)&0xffff;
		int sublen = val&0xffff;
		i+=8;

		if (sublen+i>len){
			cw_log_debug1("WTP descriptor subelement too long, length = %d",sublen);
			return -1;
		}

		cw_log_debug2("Reading WTP descriptor subelement, type=%d,len=%d",subtype,sublen);
	
		switch(subtype){
			case CWMSGSUBELEM_WTP_DESCRIPTOR_HARDWARE_VERSION:
				wtpinfo->hardware_vendor_id=vendor_id;
				cw_setstr(&wtpinfo->hardware_version,msgelem+i,sublen);
				wtpinfo->hardware_version_len=sublen;
				break;
			case CWMSGSUBELEM_WTP_DESCRIPTOR_SOFTWARE_VERSION:
				wtpinfo->software_vendor_id=vendor_id;
				cw_setstr(&wtpinfo->software_version,msgelem+i,sublen);
				wtpinfo->software_version_len=sublen;
				break;
			case CWMSGSUBELEM_WTP_DESCRIPTOR_BOOTLOADER_VERSION:
				wtpinfo->bootloader_vendor_id=vendor_id;
				cw_setstr(&wtpinfo->bootloader_version,msgelem+i,sublen);
				wtpinfo->bootloader_version_len=sublen;
				break;
			default:
				cw_log_debug1("Unknown WTP descriptor subelement, type = %d",subtype);
				break;
		}
		i+=sublen;

	}while(i<len);

	return 1;
}