[PATCH] Remove references to time_t/time()/random()

Per Ekman pek
Mon Apr 11 01:33:12 PDT 2011


Presumably these should go through the OS interface instead.

---
 src/ap/accounting.c      |   12 ++++++++----
 src/ap/ap_list.c         |   11 ++++++-----
 src/ap/ap_list.h         |    2 +-
 src/ap/ieee802_11.c      |    8 ++++----
 src/ap/ieee802_11_auth.c |   22 +++++++++++-----------
 5 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/src/ap/accounting.c b/src/ap/accounting.c
index e48503e..825ff80 100644
--- a/src/ap/accounting.c
+++ b/src/ap/accounting.c
@@ -276,6 +276,7 @@ static void accounting_sta_report(struct hostapd_data *hapd,
 	struct radius_msg *msg;
 	int cause = sta->acct_terminate_cause;
 	struct hostap_sta_driver_data data;
+        struct os_time now;
 	u32 gigawords;
 
 	if (!hapd->conf->radius->acct_server)
@@ -288,9 +289,9 @@ static void accounting_sta_report(struct hostapd_data *hapd,
 		printf("Could not create RADIUS Accounting message\n");
 		return;
 	}
-
+        os_get_time(&now);
 	if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_SESSION_TIME,
-				       time(NULL) - sta->acct_session_start)) {
+				       now.sec - sta->acct_session_start)) {
 		printf("Could not add Acct-Session-Time\n");
 		goto fail;
 	}
@@ -345,7 +346,7 @@ static void accounting_sta_report(struct hostapd_data *hapd,
 	}
 
 	if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_EVENT_TIMESTAMP,
-				       time(NULL))) {
+				       now.sec)) {
 		printf("Could not add Event-Timestamp\n");
 		goto fail;
 	}
@@ -476,9 +477,12 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
  */
 int accounting_init(struct hostapd_data *hapd)
 {
+        struct os_time now;
+
+        os_get_time(&now);
 	/* Acct-Session-Id should be unique over reboots. If reliable clock is
 	 * not available, this could be replaced with reboot counter, etc. */
-	hapd->acct_session_id_hi = time(NULL);
+	hapd->acct_session_id_hi = now.sec;
 
 	if (radius_client_register(hapd->radius, RADIUS_ACCT,
 				   accounting_receive, hapd))
diff --git a/src/ap/ap_list.c b/src/ap/ap_list.c
index 5297dbf..6896d5b 100644
--- a/src/ap/ap_list.c
+++ b/src/ap/ap_list.c
@@ -227,6 +227,7 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
 			    struct hostapd_frame_info *fi)
 {
 	struct ap_info *ap;
+        struct os_time now;
 	int new_ap = 0;
 	size_t len;
 	int set_beacon = 0;
@@ -292,7 +293,8 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
 		ap->ht_support = 0;
 
 	ap->num_beacons++;
-	time(&ap->last_beacon);
+        os_get_time(&now);
+        ap->last_beacon = now.sec;
 	if (fi) {
 		ap->ssi_signal = fi->ssi_signal;
 		ap->datarate = fi->datarate;
@@ -331,7 +333,7 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
 static void ap_list_timer(void *eloop_ctx, void *timeout_ctx)
 {
 	struct hostapd_iface *iface = eloop_ctx;
-	time_t now;
+	struct os_time now;
 	struct ap_info *ap;
 	int set_beacon = 0;
 
@@ -339,13 +341,12 @@ static void ap_list_timer(void *eloop_ctx, void *timeout_ctx)
 
 	if (!iface->ap_list)
 		return;
-
-	time(&now);
+        os_get_time(&now);
 
 	while (iface->ap_list) {
 		ap = iface->ap_list->prev;
 		if (ap->last_beacon + iface->conf->ap_table_expiration_time >=
-		    now)
+		    now.sec)
 			break;
 
 		ap_free_ap(iface, ap);
diff --git a/src/ap/ap_list.h b/src/ap/ap_list.h
index f49f58b..6df8981 100644
--- a/src/ap/ap_list.h
+++ b/src/ap/ap_list.h
@@ -45,7 +45,7 @@ struct ap_info {
 	int ht_support;
 
 	unsigned int num_beacons; /* number of beacon frames received */
-	time_t last_beacon;
+	os_time_t last_beacon;
 
 	int already_seen; /* whether API call AP-NEW has already fetched
 			   * information about this AP */
diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index c08cfe7..ffc38ae 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -244,15 +244,15 @@ static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
 		if (!sta->challenge) {
 			/* Generate a pseudo-random challenge */
 			u8 key[8];
-			time_t now;
+			struct os_time now;
 			int r;
 			sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
 			if (sta->challenge == NULL)
 				return WLAN_STATUS_UNSPECIFIED_FAILURE;
 
-			now = time(NULL);
-			r = random();
-			os_memcpy(key, &now, 4);
+			os_get_time(&now);
+			r = os_random();
+			os_memcpy(key, &now.sec, 4);
 			os_memcpy(key + 4, &r, 4);
 			rc4_skip(key, sizeof(key), 0,
 				 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
diff --git a/src/ap/ieee802_11_auth.c b/src/ap/ieee802_11_auth.c
index de66e0d..b863b60 100644
--- a/src/ap/ieee802_11_auth.c
+++ b/src/ap/ieee802_11_auth.c
@@ -33,7 +33,7 @@
 
 
 struct hostapd_cached_radius_acl {
-	time_t timestamp;
+	os_time_t timestamp;
 	macaddr addr;
 	int accepted; /* HOSTAPD_ACL_* */
 	struct hostapd_cached_radius_acl *next;
@@ -44,7 +44,7 @@ struct hostapd_cached_radius_acl {
 
 
 struct hostapd_acl_query_data {
-	time_t timestamp;
+	os_time_t timestamp;
 	u8 radius_id;
 	macaddr addr;
 	u8 *auth_msg; /* IEEE 802.11 authentication frame from station */
@@ -71,14 +71,14 @@ static int hostapd_acl_cache_get(struct hostapd_data *hapd, const u8 *addr,
 				 u32 *acct_interim_interval, int *vlan_id)
 {
 	struct hostapd_cached_radius_acl *entry;
-	time_t now;
+	struct os_time now;
 
-	time(&now);
+	os_get_time(&now);
 	entry = hapd->acl_cache;
 
 	while (entry) {
 		if (os_memcmp(entry->addr, addr, ETH_ALEN) == 0) {
-			if (now - entry->timestamp > RADIUS_ACL_TIMEOUT)
+			if (now.sec - entry->timestamp > RADIUS_ACL_TIMEOUT)
 				return -1; /* entry has expired */
 			if (entry->accepted == HOSTAPD_ACL_ACCEPT_TIMEOUT)
 				if (session_timeout)
@@ -303,7 +303,7 @@ int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr,
 
 
 #ifndef CONFIG_NO_RADIUS
-static void hostapd_acl_expire_cache(struct hostapd_data *hapd, time_t now)
+static void hostapd_acl_expire_cache(struct hostapd_data *hapd, os_time_t now)
 {
 	struct hostapd_cached_radius_acl *prev, *entry, *tmp;
 
@@ -331,7 +331,7 @@ static void hostapd_acl_expire_cache(struct hostapd_data *hapd, time_t now)
 }
 
 
-static void hostapd_acl_expire_queries(struct hostapd_data *hapd, time_t now)
+static void hostapd_acl_expire_queries(struct hostapd_data *hapd, os_time_t now)
 {
 	struct hostapd_acl_query_data *prev, *entry, *tmp;
 
@@ -367,11 +367,11 @@ static void hostapd_acl_expire_queries(struct hostapd_data *hapd, time_t now)
 static void hostapd_acl_expire(void *eloop_ctx, void *timeout_ctx)
 {
 	struct hostapd_data *hapd = eloop_ctx;
-	time_t now;
+	struct os_time now;
 
-	time(&now);
-	hostapd_acl_expire_cache(hapd, now);
-	hostapd_acl_expire_queries(hapd, now);
+	os_get_time(&now);
+	hostapd_acl_expire_cache(hapd, now.sec);
+	hostapd_acl_expire_queries(hapd, now.sec);
 
 	eloop_register_timeout(10, 0, hostapd_acl_expire, hapd, NULL);
 }
-- 
1.7.0.4




More information about the Hostap mailing list