summaryrefslogtreecommitdiff
path: root/network/wlan/WDI/COMMON/P2P_Build.c
blob: 8b3a901a45ee6021710d48174b9bf219adb5f7bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "Mp_Precomp.h"

#if WPP_SOFTWARE_TRACE
#include "P2P_Build.tmh"
#endif

#include "P2P_Internal.h"

#define P2P_BUILD_P2P_IE_HDR_LEN 		(1 + 1 + 4)
#define P2P_BUILD_MAX_ATTR_LEN_PER_IE 	(240)

#if (P2P_SUPPORT == 1)

//-----------------------------------------------------------------------------
// Local
//-----------------------------------------------------------------------------
static
VOID
p2p_write_IeLength(
	IN  FRAME_BUF				*pBuf,
	IN  pu1Byte					pLen
	)
{
	WriteEF1Byte(pLen, (u1Byte)((FrameBuf_Tail(pBuf) - 1) - pLen));
	return;
}

static
VOID
p2p_build_AttrIe(
	IN  FRAME_BUF				*pBuf,
	IN  const FRAME_BUF			*pAttr
	)
{
	const u1Byte				*pos = FrameBuf_Head(pAttr);
	const u1Byte				*end = pos + FrameBuf_Length(pAttr);

	while(pos < end)
	{
		u2Byte 					fragLen = (u2Byte)(end - pos);
		pu1Byte		pLen = NULL;

		if(P2P_BUILD_MAX_ATTR_LEN_PER_IE < fragLen)
			fragLen = P2P_BUILD_MAX_ATTR_LEN_PER_IE;

		if(NULL == (pLen = p2p_add_IEHdr(pBuf))) break;
	
		FrameBuf_Add_Data(pBuf, pos, fragLen);
	
		p2p_write_IeLength(pBuf, pLen);
	}

	return;
}

//-----------------------------------------------------------------------------
// Exported
//-----------------------------------------------------------------------------

u1Byte *
p2p_add_IEHdr(
	IN  FRAME_BUF				*pBuf
	)
{
	u1Byte						*pLen = NULL;
	
	FrameBuf_Add_u1(pBuf, (u1Byte)EID_Vendor);

	pLen = FrameBuf_Add(pBuf, 1);
		
	FrameBuf_Add_be_u4(pBuf, P2P_IE_VENDOR_TYPE);

	return pLen;
}

VOID
p2p_update_IeHdrLen(
	IN  FRAME_BUF				*pBuf,
	IN  u1Byte					*pLen
	)
{
	FRAME_BUF					attrBuf;
	FRAME_BUF					*pDupAttrBuf = NULL;
	u2Byte						attrLen = (u2Byte)(FrameBuf_Tail(pBuf) - 1 - pLen);

	if(attrLen <= P2P_BUILD_MAX_ATTR_LEN_PER_IE)
	{
		p2p_write_IeLength(pBuf, pLen);
	return;
	}
		else
	{
		FrameBuf_Init(attrLen, attrLen, pLen + 1, &attrBuf);

		pDupAttrBuf = FrameBuf_Clone(&attrBuf);

		if(!pDupAttrBuf) return;

		FrameBuf_Minus(pBuf, P2P_BUILD_P2P_IE_HDR_LEN);

		p2p_build_AttrIe(pBuf, pDupAttrBuf);

		FrameBuf_Free(pDupAttrBuf);
	}
	
	return;
}

VOID



p2p_add_ActionFrameMacHdr(
	IN  FRAME_BUF				*pBuf,
	IN  const u1Byte			*dest,
	IN  const u1Byte			*src,
	IN  const u1Byte			*bssid
	)
{
	pu1Byte						buf = NULL;
	
	if(NULL == (buf = FrameBuf_Add(pBuf, 24))) return;
	
	SET_80211_HDR_FRAME_CONTROL(buf, 0);
	SET_80211_HDR_TYPE_AND_SUBTYPE(buf, Type_Action);
	SET_80211_HDR_DURATION(buf, 0);
	SET_80211_HDR_ADDRESS1(buf, dest);
	SET_80211_HDR_ADDRESS2(buf, src);
	SET_80211_HDR_ADDRESS3(buf, bssid);
	SET_80211_HDR_FRAGMENT_SEQUENCE(buf, 0);

	return;
}

VOID
p2p_add_MgntFrameMacHdr(
	IN  FRAME_BUF				*pBuf,
	IN  TYPE_SUBTYPE			typeSubtype,
	IN  const u1Byte			*dest,
	IN  const u1Byte			*src,
	IN  const u1Byte			*bssid
	)
{
	pu1Byte						buf = NULL;
	
	if(NULL == (buf = FrameBuf_Add(pBuf, 24))) return;
	
	SET_80211_HDR_FRAME_CONTROL(buf, 0);
	SET_80211_HDR_TYPE_AND_SUBTYPE(buf, typeSubtype);
	SET_80211_HDR_DURATION(buf, 0);
	
	SET_80211_HDR_FRAGMENT_SEQUENCE(buf, 0);
	SET_80211_HDR_ADDRESS1(buf, dest);
	SET_80211_HDR_ADDRESS2(buf, src);
	SET_80211_HDR_ADDRESS3(buf, bssid);
	SET_80211_HDR_FRAGMENT_SEQUENCE(buf, 0);

	return;
}

VOID
p2p_add_PublicActionHdr(
	IN  FRAME_BUF				*pBuf,
	IN  u1Byte					actionCode,
	IN  u1Byte					dialogToken
	)
{
	FrameBuf_Add_u1(pBuf, WLAN_ACTION_PUBLIC);
	FrameBuf_Add_u1(pBuf, actionCode);
	FrameBuf_Add_u1(pBuf, dialogToken);

	return;
}

#endif