Esempio n. 1
0
uint32
reg_proto_check_nonce(IN uint8 *nonce, IN BufferObj *msg, IN int nonceType)
{
	uint16 type;

	if ((nonceType != WPS_ID_REGISTRAR_NONCE) &&
		(nonceType !=  WPS_ID_ENROLLEE_NONCE)) {
		TUTRACE((TUTRACE_ERR, "RPROTO: Invalid attribute ID passed to"
			" CheckNonce\n"));
		return WPS_ERR_INVALID_PARAMETERS;
	}

	while (1) {
		type = buffobj_NextType(msg);
		if (!type)
			break;
		if (nonceType == type) {
			if (!(memcmp(nonce, msg->pCurrent+sizeof(WpsTlvHdr),
				SIZE_128_BITS))) {
				buffobj_Rewind(msg);
				return WPS_SUCCESS;
			}
			else {
				TUTRACE((TUTRACE_ERR, "RPROTO: Nonce mismatch\n"));
				buffobj_Rewind(msg);
				return RPROT_ERR_NONCE_MISMATCH;
			}
		}

		/*
		 * advance past the TLV - the total number of bytes to advance is
		 * the size of the TLV header + the length indicated in the header
		 */
		if (!(buffobj_Advance(msg, sizeof(WpsTlvHdr) +
			WpsNtohs((msg->pCurrent+sizeof(uint16)))))) {
			TUTRACE((TUTRACE_ERR, "RPROTO: Didn't find nonce\n"));
			break;
		 }
	}

	buffobj_Rewind(msg);
	return RPROT_ERR_REQD_TLV_MISSING;
}
Esempio n. 2
0
uint32
reg_proto_get_msg_type(uint32 *msgType, BufferObj *msg)
{
	CTlvVersion version;
	CTlvMsgType bufMsgType;
	int err = 0;

	err |= tlv_dserialize(&version, WPS_ID_VERSION, msg, 0, 0);
	memset(&bufMsgType, 0, sizeof(CTlvMsgType));
	err |= tlv_dserialize(&bufMsgType, WPS_ID_MSG_TYPE, msg, 0, 0);
	*msgType = bufMsgType.m_data;
	buffobj_Rewind(msg);

	if (err)
		return WPS_ERR_INVALID_PARAMETERS;
	else
		return WPS_SUCCESS;
}
Esempio n. 3
0
/*
* NOTE: The caller MUST call tlv_delete(ssrmsg->authorizedMacs, 1) to free memory which
* allocated in this fcuntion.
*/
int
wps_get_upnpDevSSR(WPSAPI_T *g_mc, void *p_cbData, uint32 length, CTlvSsrIE *ssrmsg)
{
	int ret = WPS_CONT;
	uint8 data8;
	DevInfo *info = g_mc->dev_info;

	TUTRACE((TUTRACE_INFO, "wps_get_upnpDevSSR\n"));

	if (info->sc_mode == SCMODE_AP_REGISTRAR) {
		BufferObj *vendorExt_bufObj = NULL;
		BufferObj *wlidcardMac_bufObj = NULL;

		/* De-serialize the data to get the TLVs */
		BufferObj *bufObj = buffobj_new();
		if (!bufObj)
			return WPS_ERR_SYSTEM;

		buffobj_dserial(bufObj, (uint8 *)p_cbData, length);

		memset(ssrmsg, 0, sizeof(CTlvSsrIE));

		/* Version */
		tlv_dserialize(&ssrmsg->version, WPS_ID_VERSION, bufObj, 0, 0);
		/* Selected Registrar */
		tlv_dserialize(&ssrmsg->selReg, WPS_ID_SEL_REGISTRAR, bufObj, 0, 0);
		/* Device Password ID */
		tlv_dserialize(&ssrmsg->devPwdId, WPS_ID_DEVICE_PWD_ID, bufObj, 0, 0);
		/* Selected Registrar Config Methods */
		tlv_dserialize(&ssrmsg->selRegCfgMethods, WPS_ID_SEL_REG_CFG_METHODS,
			bufObj, 0, 0);

		/* WSC 2.0 */
		data8 = info->version2;
		if (data8 >= WPS_VERSION2) {
			/* Check subelement in WFA Vendor Extension */
			if (tlv_find_vendorExtParse(&ssrmsg->vendorExt, bufObj,
				(uint8 *)WFA_VENDOR_EXT_ID) != 0)
				goto add_wildcard_mac;

			/* Deserialize subelement */
			vendorExt_bufObj = buffobj_new();
			if (!vendorExt_bufObj) {
				buffobj_del(bufObj);
				return -1;
			}

			buffobj_dserial(vendorExt_bufObj, ssrmsg->vendorExt.vendorData,
				ssrmsg->vendorExt.dataLength);

			/* Get Version2 and AuthorizedMACs subelement */
			if (subtlv_dserialize(&ssrmsg->version2, WPS_WFA_SUBID_VERSION2,
				vendorExt_bufObj, 0, 0) == 0) {
				/* AuthorizedMACs, <= 30B */
				subtlv_dserialize(&ssrmsg->authorizedMacs,
					WPS_WFA_SUBID_AUTHORIZED_MACS,
					vendorExt_bufObj, 0, 0);
			}

			/* Add wildcard MAC when authorized mac not specified */
			if (ssrmsg->authorizedMacs.subtlvbase.m_len == 0) {
add_wildcard_mac:
				/*
				 * If the External Registrar is WSC version 1.0 it
				 * will not have included an AuthorizedMACs subelement.
				 * In this case the AP shall add the wildcard MAC Address
				 * (FF:FF:FF:FF:FF:FF) in an AuthorizedMACs subelement in
				 * Beacon and Probe Response frames
				 */
				wlidcardMac_bufObj = buffobj_new();
				if (!wlidcardMac_bufObj) {
					buffobj_del(vendorExt_bufObj);
					buffobj_del(bufObj);
					return -1;
				}

				/* Serialize the wildcard_authorizedMacs to wlidcardMac_Obj */
				subtlv_serialize(WPS_WFA_SUBID_AUTHORIZED_MACS, wlidcardMac_bufObj,
					(char *)wildcard_authorizedMacs, SIZE_MAC_ADDR);
				buffobj_Rewind(wlidcardMac_bufObj);
				/*
				 * De-serialize the wlidcardMac_Obj data to get the TLVs
				 * Do allocation, because wlidcardMac_bufObj will be freed here but
				 * ssrmsg->authorizedMacs return and used by caller.
				 */
				subtlv_dserialize(&ssrmsg->authorizedMacs,
					WPS_WFA_SUBID_AUTHORIZED_MACS,
					wlidcardMac_bufObj, 0, 1); /* Need to free it */
			}

			/* Get UUID-R after WFA-Vendor Extension (wpa_supplicant use this way) */
			tlv_find_dserialize(&ssrmsg->uuid_R, WPS_ID_UUID_R, bufObj, 0, 0);
		}

		/* Other... */

		if (bufObj)
			buffobj_del(bufObj);

		if (wlidcardMac_bufObj)
			buffobj_del(wlidcardMac_bufObj);

		if (vendorExt_bufObj)
			buffobj_del(vendorExt_bufObj);

		ret = WPS_SUCCESS;
	}

	return ret;
}