]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Remove references to time_t/time()/random()
authorPer Ekman <pek@kth.se>
Mon, 11 Apr 2011 15:33:48 +0000 (18:33 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 11 Apr 2011 15:33:48 +0000 (18:33 +0300)
Replace direct calls in AP mode code with os_*() wrappers.

src/ap/accounting.c
src/ap/ap_list.c
src/ap/ap_list.h
src/ap/ieee802_11.c
src/ap/ieee802_11_auth.c

index e48503e59588ae61e2b36250f205831b55710dc7..dbfb058af02fa8fbd9129e15ae2b3d2117394607 100644 (file)
@@ -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)
@@ -289,8 +290,9 @@ static void accounting_sta_report(struct hostapd_data *hapd,
                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 +347,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 +478,12 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
  */
 int accounting_init(struct hostapd_data *hapd)
 {
+       struct os_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);
+       os_get_time(&now);
+       hapd->acct_session_id_hi = now.sec;
 
        if (radius_client_register(hapd->radius, RADIUS_ACCT,
                                   accounting_receive, hapd))
index 5297dbf3bf5f363ee431d95539a9f907e460a6c8..9b9fc9ebf3c3d9a2cd7daa8464835cff5325d404 100644 (file)
@@ -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;
 
@@ -340,12 +342,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);
index f49f58b54e43556c2855e5e3c9c80ca4a5620ef6..6df8981c58d2aa62373bf5f61db1570ef6f0de80 100644 (file)
@@ -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 */
index c08cfe78460a2a2e4a63843079e2bb4c8df1ee5b..ffc38ae9a3803cd0ceefa13ebc92662c8e455e87 100644 (file)
@@ -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);
index de66e0dbdb7b9408202e86a13cc58ed1aa655451..b933263b0714509e0e2a85ab881b6f987cb91e12 100644 (file)
@@ -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,8 @@ 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 +368,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);
 }