summaryrefslogtreecommitdiff
path: root/net-wireless/hostapd/files/cui-20120717.patch
blob: e6e5e8dc761b0204ccc900d985c618fc6258395e (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
diff -urN hostapd-1.0.orig//src/ap/accounting.c hostapd-1.0/src/ap/accounting.c
--- hostapd-1.0.orig//src/ap/accounting.c	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/ap/accounting.c	2012-07-17 18:40:21.000000000 +0800
@@ -25,6 +25,7 @@
 #include "sta_info.h"
 #include "ap_drv_ops.h"
 #include "accounting.h"
+/*#include "eapol_auth/eapol_auth_sm_i.h"*/
 
 
 /* Default interval in seconds for polling TX/RX octets from the driver if
@@ -44,7 +45,10 @@
 	char buf[128];
 	u8 *val;
 	size_t len;
+	u8 *cui; /*Define CUI Attribute*/
+	size_t cui_len; /*Define CUI Attribute length*/
 	int i;
+	struct eapol_state_machine *sm = sta->eapol_sm; 
 
 	msg = radius_msg_new(RADIUS_CODE_ACCOUNTING_REQUEST,
 			     radius_client_get_id(hapd->radius));
@@ -83,7 +87,9 @@
 
 	if (sta) {
 		val = ieee802_1x_get_identity(sta->eapol_sm, &len);
+		printf("GOT ID\n");
 		if (!val) {
+			
 			os_snprintf(buf, sizeof(buf), RADIUS_ADDR_FORMAT,
 				    MAC2STR(sta->addr));
 			val = (u8 *) buf;
@@ -95,6 +101,30 @@
 			printf("Could not add User-Name\n");
 			goto fail;
 		}
+
+		
+		/*Check if the CUI attribute is set, if so returns the TRUE or FALSE accordingly**************/
+		if (getSetCui(sta->eapol_sm)){
+		cui=get_CUI (sta->eapol_sm, &cui_len);
+		printf("GOT CUI\n");
+
+		if (!cui) {
+					
+					os_snprintf(buf, sizeof(buf), RADIUS_ADDR_FORMAT,
+						    MAC2STR(sta->addr));
+					cui = (u8 *) buf;
+					cui_len = os_strlen(buf);
+				}
+		if (!radius_msg_add_attr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY, cui,
+				cui_len)) { /*Add CUI attribute to the Accounting Request Message*/
+					printf("Could not add CUI\n");
+					goto fail;
+				}
+		/********************/
+		}
+		/*else { */
+		/*	printf ("PROBLEM IN IF\n");*/
+		/*}*/
 	}
 
 	if (hapd->conf->own_ip_addr.af == AF_INET &&
diff -urN hostapd-1.0.orig//src/ap/accounting.h hostapd-1.0/src/ap/accounting.h
--- hostapd-1.0.orig//src/ap/accounting.h	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/ap/accounting.h	2012-07-17 18:40:21.000000000 +0800
@@ -22,6 +22,7 @@
 {
 }
 
+
 static inline void accounting_sta_stop(struct hostapd_data *hapd,
 				       struct sta_info *sta)
 {
diff -urN hostapd-1.0.orig//src/ap/ieee802_1x.c hostapd-1.0/src/ap/ieee802_1x.c
--- hostapd-1.0.orig//src/ap/ieee802_1x.c	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/ap/ieee802_1x.c	2012-07-17 18:40:21.000000000 +0800
@@ -966,6 +966,7 @@
 			 * re-authentication without having to wait for the
 			 * Supplicant to send EAPOL-Start.
 			 */
+			printf("REAUTHENTICATION-EAPOL");
 			sta->eapol_sm->reAuthenticate = TRUE;
 		}
 		eapol_auth_step(sta->eapol_sm);
@@ -1205,6 +1206,68 @@
 	sm->identity_len = len;
 }
 
+/* This method is used to   Set the CUI attribute Value**************************************/
+static void set_cui(struct hostapd_data *hapd,
+					   struct sta_info *sta,
+					   struct radius_msg *msg)
+
+{
+	u8 *buf,*cui_identity;
+	size_t len;
+	struct eapol_state_machine *sm = sta->eapol_sm;
+
+	if (sm == NULL)
+			return;
+
+	if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY, &buf, &len,
+					    NULL) < 0)
+			return;
+	cui_identity = os_malloc(len + 1);
+		if (cui_identity == NULL)
+			return;
+	os_memcpy(cui_identity, buf, len);
+	cui_identity[len] = '\0';
+
+	sm->cui = cui_identity;
+	sm->cui_len = len;
+	printf(" SET CUI %s",(char *) cui_identity);
+
+
+}
+
+
+/*  **************************************/
+
+/*check CUI attribute is available in Access Accept */
+static void check_cuiAttr (struct radius_msg *msg,struct sta_info *sta, struct hostapd_data *hapd)
+{
+	
+	struct eapol_state_machine *sm = sta->eapol_sm; /*Define a pointer to eapol_state_machine*/
+	
+
+	size_t i;
+
+	for (i = 0;i<msg->attr_used;i++)
+	{	struct radius_attr_hdr *attr = radius_get_attr_hdr(msg, i);
+		if (attr->type == RADIUS_ATTR_CHARGEABLE_USER_IDENTITY) /*check CUI attribute is availabe in Access-Accept packet*/
+		{
+			printf("CUI Attribute is Available");
+			sm->cuiAvailable = TRUE;
+			set_cui(hapd, sta, msg);
+			break;
+
+		}
+		else {
+			sm->cuiAvailable = FALSE;
+			printf ("CUI is not available in this packet");
+
+		}
+
+
+	}
+
+}
+
 
 struct sta_id_search {
 	u8 identifier;
@@ -1365,6 +1428,8 @@
 				    shared_secret_len);
 		ieee802_1x_store_radius_class(hapd, sta, msg);
 		ieee802_1x_update_sta_identity(hapd, sta, msg);
+		/*set_cui(hapd, sta, msg);*/
+		check_cuiAttr (msg,sta,hapd);
 		if (sm->eap_if->eapKeyAvailable &&
 		    wpa_auth_pmksa_add(sta->wpa_sm, sm->eapol_key_crypt,
 				       session_timeout_set ?
@@ -1859,6 +1924,27 @@
 }
 
 
+
+u8 * get_CUI(struct eapol_state_machine *sm, size_t *len) /* return CUI Attribute Value  ******************************/
+{
+	if (sm == NULL || sm->identity == NULL)
+		return NULL;
+
+	*len = sm->cui_len;
+	return sm->cui;
+}
+
+Boolean getSetCui (struct eapol_state_machine *sm) /*Check if the CUI value is set or not, and returns TRUE or FALSE accordingly*/
+
+{ if (sm->cuiAvailable)
+	return TRUE;
+else
+	return FALSE;
+	}
+
+/*****************************/
+
+
 u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
 				 int idx)
 {
diff -urN hostapd-1.0.orig//src/ap/ieee802_1x.h hostapd-1.0/src/ap/ieee802_1x.h
--- hostapd-1.0.orig//src/ap/ieee802_1x.h	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/ap/ieee802_1x.h	2012-07-17 18:40:21.000000000 +0800
@@ -69,6 +69,13 @@
 int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
 			 const u8 *buf, size_t len, int ack);
 u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len);
+
+/** definig CUI get function */
+u8 * get_CUI(struct eapol_state_machine *sm, size_t *len);
+Boolean getSetCui (struct eapol_state_machine *sm);
+
+/*********************/
+
 u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
 				 int idx);
 const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len);
diff -urN hostapd-1.0.orig//src/ap/pmksa_cache_auth.c hostapd-1.0/src/ap/pmksa_cache_auth.c
--- hostapd-1.0.orig//src/ap/pmksa_cache_auth.c	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/ap/pmksa_cache_auth.c	2012-07-17 18:40:21.000000000 +0800
@@ -142,6 +142,20 @@
 		}
 	}
 
+/*set to cui in to cache*/
+
+	if (eapol ->cui) {
+		
+		entry ->cui = os_malloc(eapol->cui_len); /*Allocate memory for CUI attribute*/
+		if (entry->cui) {
+			entry->cui_len = eapol->cui_len;
+			os_memcpy(entry->cui, eapol->cui,
+				  eapol->cui_len);
+		}
+	}
+
+/*set to cui in to cache*/
+
 #ifndef CONFIG_NO_RADIUS
 	radius_copy_class(&entry->radius_class, &eapol->radius_class);
 #endif /* CONFIG_NO_RADIUS */
@@ -169,6 +183,25 @@
 				  eapol->identity, eapol->identity_len);
 	}
 
+/*Added to get CUI from the cache*/
+
+
+	if (entry->cui) {
+			os_free(eapol->cui);
+			
+			eapol->cui = os_malloc(entry->cui_len);
+			eapol->cuiAvailable=TRUE;
+			if (eapol->cui) {
+				eapol->cui_len = entry->cui_len;
+				os_memcpy(eapol->cui, entry->cui, 
+					  entry->cui_len); /*copy the CUI attribute value to EAPOL data structure*/
+			}
+			wpa_hexdump_ascii(MSG_DEBUG, "CUIfrom PMKSA",
+					  eapol->cui, eapol->cui_len);
+		}
+
+	/*Added to get CUI from the cache*/
+
 #ifndef CONFIG_NO_RADIUS
 	radius_free_class(&eapol->radius_class);
 	radius_copy_class(&eapol->radius_class, &entry->radius_class);
@@ -180,6 +213,7 @@
 
 	eapol->eap_type_authsrv = entry->eap_type_authsrv;
 	((struct sta_info *) eapol->sta)->vlan_id = entry->vlan_id;
+	printf ("GETTING CACHE ENTRY\n");
 }
 
 
diff -urN hostapd-1.0.orig//src/ap/pmksa_cache_auth.h hostapd-1.0/src/ap/pmksa_cache_auth.h
--- hostapd-1.0.orig//src/ap/pmksa_cache_auth.h	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/ap/pmksa_cache_auth.h	2012-07-17 18:40:21.000000000 +0800
@@ -31,6 +31,8 @@
 
 	u8 *identity;
 	size_t identity_len;
+	u8 *cui; /* cui by me*/
+	size_t cui_len; /*Size of the cached cui by me*/
 	struct radius_class_data radius_class;
 	u8 eap_type_authsrv;
 	int vlan_id;
diff -urN hostapd-1.0.orig//src/common/ieee802_11_common.c hostapd-1.0/src/common/ieee802_11_common.c
--- hostapd-1.0.orig//src/common/ieee802_11_common.c	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/common/ieee802_11_common.c	2012-07-17 18:40:21.000000000 +0800
@@ -31,8 +31,8 @@
 	if (elen < 4) {
 		if (show_errors) {
 			wpa_printf(MSG_MSGDUMP, "short vendor specific "
-				   "information element ignored (len=%lu)",
-				   (unsigned long) elen);
+				  "information element ignored (len=%lu)",
+				  (unsigned long) elen);
 		}
 		return -1;
 	}
diff -urN hostapd-1.0.orig//src/eapol_auth/eapol_auth_sm_i.h hostapd-1.0/src/eapol_auth/eapol_auth_sm_i.h
--- hostapd-1.0.orig//src/eapol_auth/eapol_auth_sm_i.h	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/eapol_auth/eapol_auth_sm_i.h	2012-07-17 18:40:21.000000000 +0800
@@ -75,6 +75,7 @@
 	/* variables */
 	Boolean eapolLogoff;
 	Boolean eapolStart;
+	Boolean cuiAvailable; /*to check CUI is available in AcessAccept*/
 	PortTypes portMode;
 	unsigned int reAuthCount;
 	/* constants */
@@ -159,6 +160,8 @@
 	u8 last_eap_id; /* last used EAP Identifier */
 	u8 *identity;
 	size_t identity_len;
+	u8 *cui; /*Define CUI Attribute*/
+	size_t cui_len; /*Define CUI attribute length*/
 	u8 eap_type_authsrv; /* EAP type of the last EAP packet from
 			      * Authentication server */
 	u8 eap_type_supp; /* EAP type of the last EAP packet from Supplicant */
diff -urN hostapd-1.0.orig//src/radius/radius.c hostapd-1.0/src/radius/radius.c
--- hostapd-1.0.orig//src/radius/radius.c	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/radius/radius.c	2012-07-17 18:40:21.000000000 +0800
@@ -24,16 +24,16 @@
 /**
  * struct radius_msg - RADIUS message structure for new and parsed messages
  */
-struct radius_msg {
+//struct radius_msg {
 	/**
 	 * buf - Allocated buffer for RADIUS message
 	 */
-	struct wpabuf *buf;
+	//struct wpabuf *buf;
 
 	/**
 	 * hdr - Pointer to the RADIUS header in buf
 	 */
-	struct radius_hdr *hdr;
+	//struct radius_hdr *hdr;
 
 	/**
 	 * attr_pos - Array of indexes to attributes
@@ -41,18 +41,18 @@
 	 * The values are number of bytes from buf to the beginning of
 	 * struct radius_attr_hdr.
 	 */
-	size_t *attr_pos;
+	//size_t *attr_pos;
 
 	/**
 	 * attr_size - Total size of the attribute pointer array
 	 */
-	size_t attr_size;
+	//size_t attr_size;
 
 	/**
 	 * attr_used - Total number of attributes in the array
 	 */
-	size_t attr_used;
-};
+	//size_t attr_used;
+//};
 
 
 struct radius_hdr * radius_msg_get_hdr(struct radius_msg *msg)
@@ -66,7 +66,7 @@
 	return msg->buf;
 }
 
-
+/*
 static struct radius_attr_hdr *
 radius_get_attr_hdr(struct radius_msg *msg, int idx)
 {
@@ -74,7 +74,7 @@
 		(wpabuf_mhead_u8(msg->buf) + msg->attr_pos[idx]);
 }
 
-
+*/
 static void radius_msg_set_hdr(struct radius_msg *msg, u8 code, u8 identifier)
 {
 	msg->hdr->code = code;
diff -urN hostapd-1.0.orig//src/radius/radius.h hostapd-1.0/src/radius/radius.h
--- hostapd-1.0.orig//src/radius/radius.h	2012-05-10 05:56:09.000000000 +0800
+++ hostapd-1.0/src/radius/radius.h	2012-07-17 18:40:21.000000000 +0800
@@ -21,6 +21,45 @@
 #pragma pack(push, 1)
 #endif /* _MSC_VER */
 
+/************************/
+struct radius_msg {
+	/**
+	 * buf - Allocated buffer for RADIUS message
+	 */
+	struct wpabuf *buf;
+
+	/**
+	 * hdr - Pointer to the RADIUS header in buf
+	 */
+	struct radius_hdr *hdr;
+
+	/**
+	 * attr_pos - Array of indexes to attributes
+	 *
+	 * The values are number of bytes from buf to the beginning of
+	 * struct radius_attr_hdr.
+	 */
+	size_t *attr_pos;
+
+	/**
+	 * attr_size - Total size of the attribute pointer array
+	 */
+	size_t attr_size;
+
+	/**
+	 * attr_used - Total number of attributes in the array
+	 */
+	size_t attr_used;
+};
+
+
+
+
+/***********************/
+
+
+
+
 struct radius_hdr {
 	u8 code;
 	u8 identifier;
@@ -201,6 +240,10 @@
 			    size_t secret_len);
 struct radius_attr_hdr * radius_msg_add_attr(struct radius_msg *msg, u8 type,
 					     const u8 *data, size_t data_len);
+
+/****************************/
+
+/*****************************/
 struct radius_msg * radius_msg_parse(const u8 *data, size_t len);
 int radius_msg_add_eap(struct radius_msg *msg, const u8 *data,
 		       size_t data_len);
@@ -238,7 +281,13 @@
 	u32 val = htonl(value);
 	return radius_msg_add_attr(msg, type, (u8 *) &val, 4) != NULL;
 }
-
+/**********************/
+static struct radius_attr_hdr * radius_get_attr_hdr(struct radius_msg *msg, int idx)
+{
+	return (struct radius_attr_hdr *)
+		(wpabuf_mhead_u8(msg->buf) + msg->attr_pos[idx]);
+}
+/**************************/
 static inline int radius_msg_get_attr_int32(struct radius_msg *msg, u8 type,
 					    u32 *value)
 {