commit da0dd02489d20e33bf7e8520795923c934477440 Author: Johannes Berg Date: Wed Nov 13 17:43:08 2013 +0100 use monotonic clock for relative time where available Relative time shouldn't be calculated based on gettimeofday because that clock can jump (e.g. when the time is adjusted by the system administrator.) On systems where that is available, use CLOCK_BOOTTIME (on fairly recent Linux systems, this clock takes into account the time spend suspended) or CLOCK_MONOTONIC (on Linux and some POSIX systems, this clock is just freely running with no adjustments.) Unfortunately this patch is invasive since a lot of places need to be adjusted to use os_get_reltime() rather than os_get_time() that is used now. However, not all instances should use the other clock, e.g. absolute time needed in any certificate checking and similar needs to be wall time. TODO: carefully check all replacements to see if any should actually be using os_get_time() instead! Reported-by: Holger Schurig Signed-hostap: Johannes Berg diff --git a/src/ap/accounting.c b/src/ap/accounting.c index a1f67f0..d7587d2 100644 --- a/src/ap/accounting.c +++ b/src/ap/accounting.c @@ -202,7 +202,7 @@ static void accounting_interim_update(void *eloop_ctx, void *timeout_ctx) void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta) { struct radius_msg *msg; - struct os_time t; + struct os_reltime t; int interval; if (sta->acct_session_started) @@ -213,7 +213,7 @@ void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta) "starting accounting session %08X-%08X", sta->acct_session_id_hi, sta->acct_session_id_lo); - os_get_time(&t); + os_get_reltime(&t); sta->acct_session_start = t.sec; sta->last_rx_bytes = sta->last_tx_bytes = 0; sta->acct_input_gigawords = sta->acct_output_gigawords = 0; @@ -244,7 +244,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; + struct os_reltime now; u32 gigawords; if (!hapd->conf->radius->acct_server) @@ -258,7 +258,7 @@ static void accounting_sta_report(struct hostapd_data *hapd, return; } - os_get_time(&now); + os_get_reltime(&now); if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_SESSION_TIME, now.sec - sta->acct_session_start)) { wpa_printf(MSG_INFO, "Could not add Acct-Session-Time"); diff --git a/src/ap/ap_list.c b/src/ap/ap_list.c index 9f02151..008ea89 100644 --- a/src/ap/ap_list.c +++ b/src/ap/ap_list.c @@ -172,7 +172,7 @@ void ap_list_process_beacon(struct hostapd_iface *iface, struct hostapd_frame_info *fi) { struct ap_info *ap; - struct os_time now; + struct os_reltime now; int new_ap = 0; int set_beacon = 0; @@ -210,7 +210,7 @@ void ap_list_process_beacon(struct hostapd_iface *iface, else ap->ht_support = 0; - os_get_time(&now); + os_get_reltime(&now); ap->last_beacon = now.sec; if (!new_ap && ap != iface->ap_list) { @@ -252,7 +252,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; - struct os_time now; + struct os_reltime now; struct ap_info *ap; int set_beacon = 0; @@ -261,7 +261,7 @@ static void ap_list_timer(void *eloop_ctx, void *timeout_ctx) if (!iface->ap_list) return; - os_get_time(&now); + os_get_reltime(&now); while (iface->ap_list) { ap = iface->ap_list->prev; diff --git a/src/ap/ctrl_iface_ap.c b/src/ap/ctrl_iface_ap.c index 5d99566..a3a8284 100644 --- a/src/ap/ctrl_iface_ap.c +++ b/src/ap/ctrl_iface_ap.c @@ -24,14 +24,14 @@ static int hostapd_get_sta_conn_time(struct sta_info *sta, char *buf, size_t buflen) { - struct os_time now, age; + struct os_reltime now, age; int len = 0, ret; if (!sta->connected_time.sec) return 0; - os_get_time(&now); - os_time_sub(&now, &sta->connected_time, &age); + os_get_reltime(&now); + os_reltime_sub(&now, &sta->connected_time, &age); ret = os_snprintf(buf + len, buflen - len, "connected_time=%u\n", (unsigned int) age.sec); diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 60224cc..9aa7b45 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -1961,7 +1961,7 @@ void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, * IEEE 802.1X/WPA code will start accounting after the station has * been authorized. */ if (!hapd->conf->ieee802_1x && !hapd->conf->wpa) { - os_get_time(&sta->connected_time); + os_get_reltime(&sta->connected_time); accounting_sta_start(hapd, sta); } diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c index d553caa..baf34a0 100644 --- a/src/ap/ieee802_11.c +++ b/src/ap/ieee802_11.c @@ -411,9 +411,9 @@ static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd, { struct wpabuf *buf; u8 *token; - struct os_time t; + struct os_reltime t; - os_get_time(&t); + os_get_reltime(&t); if (hapd->last_sae_token_key_update == 0 || t.sec > hapd->last_sae_token_key_update + 60) { if (random_get_bytes(hapd->sae_token_key, diff --git a/src/ap/ieee802_11_auth.c b/src/ap/ieee802_11_auth.c index c311e55..9ef34eb 100644 --- a/src/ap/ieee802_11_auth.c +++ b/src/ap/ieee802_11_auth.c @@ -104,9 +104,9 @@ static int hostapd_acl_cache_get(struct hostapd_data *hapd, const u8 *addr, char **identity, char **radius_cui) { struct hostapd_cached_radius_acl *entry; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); for (entry = hapd->acl_cache; entry; entry = entry->next) { if (os_memcmp(entry->addr, addr, ETH_ALEN) != 0) @@ -265,7 +265,7 @@ int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr, return HOSTAPD_ACL_REJECT; #else /* CONFIG_NO_RADIUS */ struct hostapd_acl_query_data *query; - struct os_time t; + struct os_reltime t; /* Check whether ACL cache has an entry for this station */ int res = hostapd_acl_cache_get(hapd, addr, session_timeout, @@ -305,7 +305,7 @@ int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr, wpa_printf(MSG_ERROR, "malloc for query data failed"); return HOSTAPD_ACL_REJECT; } - os_get_time(&t); + os_get_reltime(&t); query->timestamp = t.sec; os_memcpy(query->addr, addr, ETH_ALEN); if (hostapd_radius_acl_query(hapd, addr, query)) { @@ -403,9 +403,9 @@ static void hostapd_acl_expire_queries(struct hostapd_data *hapd, static void hostapd_acl_expire(void *eloop_ctx, void *timeout_ctx) { struct hostapd_data *hapd = eloop_ctx; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); hostapd_acl_expire_cache(hapd, now.sec); hostapd_acl_expire_queries(hapd, now.sec); @@ -480,7 +480,7 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req, struct hostapd_acl_query_data *query, *prev; struct hostapd_cached_radius_acl *cache; struct radius_hdr *hdr = radius_msg_get_hdr(msg); - struct os_time t; + struct os_reltime t; query = hapd->acl_queries; prev = NULL; @@ -515,7 +515,7 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req, wpa_printf(MSG_DEBUG, "Failed to add ACL cache entry"); goto done; } - os_get_time(&t); + os_get_reltime(&t); cache->timestamp = t.sec; os_memcpy(cache->addr, query->addr, sizeof(cache->addr)); if (hdr->code == RADIUS_CODE_ACCESS_ACCEPT) { diff --git a/src/ap/ieee802_11_shared.c b/src/ap/ieee802_11_shared.c index 76688b5..eadaa4d 100644 --- a/src/ap/ieee802_11_shared.c +++ b/src/ap/ieee802_11_shared.c @@ -24,13 +24,13 @@ u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd, { u8 *pos = eid; u32 timeout, tu; - struct os_time now, passed; + struct os_reltime now, passed; *pos++ = WLAN_EID_TIMEOUT_INTERVAL; *pos++ = 5; *pos++ = WLAN_TIMEOUT_ASSOC_COMEBACK; - os_get_time(&now); - os_time_sub(&now, &sta->sa_query_start, &passed); + os_get_reltime(&now); + os_reltime_sub(&now, &sta->sa_query_start, &passed); tu = (passed.sec * 1000000 + passed.usec) / 1024; if (hapd->conf->assoc_sa_query_max_timeout > tu) timeout = hapd->conf->assoc_sa_query_max_timeout - tu; diff --git a/src/ap/ieee802_1x.c b/src/ap/ieee802_1x.c index 7874332..8aca423 100644 --- a/src/ap/ieee802_1x.c +++ b/src/ap/ieee802_1x.c @@ -102,7 +102,7 @@ void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd, } if (authorized) { - os_get_time(&sta->connected_time); + os_get_reltime(&sta->connected_time); accounting_sta_start(hapd, sta); } } @@ -1951,7 +1951,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta, { int len = 0, ret; struct eapol_state_machine *sm = sta->eapol_sm; - struct os_time t; + struct os_reltime t; if (sm == NULL) return 0; @@ -2066,7 +2066,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta, len += ret; /* dot1xAuthSessionStatsTable */ - os_get_time(&t); + os_get_reltime(&t); ret = os_snprintf(buf + len, buflen - len, /* TODO: dot1xAuthSessionOctetsRx */ /* TODO: dot1xAuthSessionOctetsTx */ diff --git a/src/ap/pmksa_cache_auth.c b/src/ap/pmksa_cache_auth.c index 40972e9..4720b59 100644 --- a/src/ap/pmksa_cache_auth.c +++ b/src/ap/pmksa_cache_auth.c @@ -91,9 +91,9 @@ void pmksa_cache_free_entry(struct rsn_pmksa_cache *pmksa, static void pmksa_cache_expire(void *eloop_ctx, void *timeout_ctx) { struct rsn_pmksa_cache *pmksa = eloop_ctx; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); while (pmksa->pmksa && pmksa->pmksa->expiration <= now.sec) { wpa_printf(MSG_DEBUG, "RSN: expired PMKSA cache entry for " MACSTR, MAC2STR(pmksa->pmksa->spa)); @@ -107,12 +107,12 @@ static void pmksa_cache_expire(void *eloop_ctx, void *timeout_ctx) static void pmksa_cache_set_expiration(struct rsn_pmksa_cache *pmksa) { int sec; - struct os_time now; + struct os_reltime now; eloop_cancel_timeout(pmksa_cache_expire, pmksa, NULL); if (pmksa->pmksa == NULL) return; - os_get_time(&now); + os_get_reltime(&now); sec = pmksa->pmksa->expiration - now.sec; if (sec < 0) sec = 0; @@ -241,7 +241,7 @@ pmksa_cache_auth_add(struct rsn_pmksa_cache *pmksa, struct eapol_state_machine *eapol, int akmp) { struct rsn_pmksa_cache_entry *entry, *pos; - struct os_time now; + struct os_reltime now; if (pmk_len > PMK_LEN) return NULL; @@ -253,7 +253,7 @@ pmksa_cache_auth_add(struct rsn_pmksa_cache *pmksa, entry->pmk_len = pmk_len; rsn_pmkid(pmk, pmk_len, aa, spa, entry->pmkid, wpa_key_mgmt_sha256(akmp)); - os_get_time(&now); + os_get_reltime(&now); entry->expiration = now.sec; if (session_timeout > 0) entry->expiration += session_timeout; diff --git a/src/ap/sta_info.c b/src/ap/sta_info.c index a6775f3..132d1aa 100644 --- a/src/ap/sta_info.c +++ b/src/ap/sta_info.c @@ -821,9 +821,9 @@ int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta, int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta) { u32 tu; - struct os_time now, passed; - os_get_time(&now); - os_time_sub(&now, &sta->sa_query_start, &passed); + struct os_reltime now, passed; + os_get_reltime(&now); + os_reltime_sub(&now, &sta->sa_query_start, &passed); tu = (passed.sec * 1000000 + passed.usec) / 1024; if (hapd->conf->assoc_sa_query_max_timeout < tu) { hostapd_logger(hapd, sta->addr, @@ -860,7 +860,7 @@ static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx) return; if (sta->sa_query_count == 0) { /* Starting a new SA Query procedure */ - os_get_time(&sta->sa_query_start); + os_get_reltime(&sta->sa_query_start); } trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; sta->sa_query_trans_id = nbuf; diff --git a/src/ap/sta_info.h b/src/ap/sta_info.h index dc74219..ea3fe40 100644 --- a/src/ap/sta_info.h +++ b/src/ap/sta_info.h @@ -113,7 +113,7 @@ struct sta_info { u8 *sa_query_trans_id; /* buffer of WLAN_SA_QUERY_TR_ID_LEN * * sa_query_count octets of pending SA Query * transaction identifiers */ - struct os_time sa_query_start; + struct os_reltime sa_query_start; #endif /* CONFIG_IEEE80211W */ #ifdef CONFIG_INTERWORKING @@ -126,7 +126,7 @@ struct sta_info { struct wpabuf *p2p_ie; /* P2P IE from (Re)Association Request */ struct wpabuf *hs20_ie; /* HS 2.0 IE from (Re)Association Request */ - struct os_time connected_time; + struct os_reltime connected_time; #ifdef CONFIG_SAE struct sae_data *sae; diff --git a/src/ap/tkip_countermeasures.c b/src/ap/tkip_countermeasures.c index 4a2ea06..6474164 100644 --- a/src/ap/tkip_countermeasures.c +++ b/src/ap/tkip_countermeasures.c @@ -68,7 +68,7 @@ void ieee80211_tkip_countermeasures_deinit(struct hostapd_data *hapd) int michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local) { - struct os_time now; + struct os_reltime now; int ret = 0; if (addr && local) { @@ -89,7 +89,7 @@ int michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local) } } - os_get_time(&now); + os_get_reltime(&now); if (now.sec > hapd->michael_mic_failure + 60) { hapd->michael_mic_failures = 1; } else { diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c index d9a7509..80cccae 100644 --- a/src/common/wpa_ctrl.c +++ b/src/common/wpa_ctrl.c @@ -395,7 +395,7 @@ int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, void (*msg_cb)(char *msg, size_t len)) { struct timeval tv; - struct os_time started_at; + struct os_reltime started_at; int res; fd_set rfds; const char *_cmd; @@ -434,10 +434,10 @@ retry_send: * longer before giving up. */ if (started_at.sec == 0) - os_get_time(&started_at); + os_get_reltime(&started_at); else { - struct os_time n; - os_get_time(&n); + struct os_reltime n; + os_get_reltime(&n); /* Try for a few seconds. */ if (n.sec > started_at.sec + 5) goto send_err; diff --git a/src/drivers/driver.h b/src/drivers/driver.h index f233032..d2e9d8a 100644 --- a/src/drivers/driver.h +++ b/src/drivers/driver.h @@ -226,7 +226,7 @@ struct wpa_scan_res { struct wpa_scan_results { struct wpa_scan_res **res; size_t num; - struct os_time fetch_time; + struct os_reltime fetch_time; }; /** diff --git a/src/drivers/driver_test.c b/src/drivers/driver_test.c index 5742b98..9c16ca9 100644 --- a/src/drivers/driver_test.c +++ b/src/drivers/driver_test.c @@ -1318,8 +1318,8 @@ static void wpa_driver_test_scan_timeout(void *eloop_ctx, void *timeout_ctx) if (drv->pending_p2p_scan && drv->p2p) { #ifdef CONFIG_P2P size_t i; - struct os_time now; - os_get_time(&now); + struct os_reltime now; + os_get_reltime(&now); for (i = 0; i < drv->num_scanres; i++) { struct wpa_scan_res *bss = drv->scanres[i]; if (p2p_scan_res_handler(drv->p2p, bss->bssid, diff --git a/src/eap_server/eap_sim_db.c b/src/eap_server/eap_sim_db.c index 345c788..02d1a6b 100644 --- a/src/eap_server/eap_sim_db.c +++ b/src/eap_server/eap_sim_db.c @@ -38,7 +38,7 @@ struct eap_sim_db_pending { char imsi[20]; enum { PENDING, SUCCESS, FAILURE } state; void *cb_session_ctx; - struct os_time timestamp; + struct os_reltime timestamp; int aka; union { struct { @@ -935,7 +935,7 @@ int eap_sim_db_get_gsm_triplets(struct eap_sim_db_data *data, if (entry == NULL) return EAP_SIM_DB_FAILURE; - os_get_time(&entry->timestamp); + os_get_reltime(&entry->timestamp); os_strlcpy(entry->imsi, imsi, sizeof(entry->imsi)); entry->cb_session_ctx = cb_session_ctx; entry->state = PENDING; @@ -1395,7 +1395,7 @@ int eap_sim_db_get_aka_auth(struct eap_sim_db_data *data, const char *username, if (entry == NULL) return EAP_SIM_DB_FAILURE; - os_get_time(&entry->timestamp); + os_get_reltime(&entry->timestamp); entry->aka = 1; os_strlcpy(entry->imsi, imsi, sizeof(entry->imsi)); entry->cb_session_ctx = cb_session_ctx; diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index b263609..b6ccf23 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -48,10 +48,10 @@ static void p2p_scan_timeout(void *eloop_ctx, void *timeout_ctx); static void p2p_expire_peers(struct p2p_data *p2p) { struct p2p_device *dev, *n; - struct os_time now; + struct os_reltime now; size_t i; - os_get_time(&now); + os_get_reltime(&now); dl_list_for_each_safe(dev, n, &p2p->devices, struct p2p_device, list) { if (dev->last_seen.sec + P2P_PEER_EXPIRATION_AGE >= now.sec) continue; @@ -63,7 +63,7 @@ static void p2p_expire_peers(struct p2p_data *p2p) * We are connected as a client to a group in which the * peer is the GO, so do not expire the peer entry. */ - os_get_time(&dev->last_seen); + os_get_reltime(&dev->last_seen); continue; } @@ -77,7 +77,7 @@ static void p2p_expire_peers(struct p2p_data *p2p) * The peer is connected as a client in a group where * we are the GO, so do not expire the peer entry. */ - os_get_time(&dev->last_seen); + os_get_reltime(&dev->last_seen); continue; } @@ -377,7 +377,7 @@ static struct p2p_device * p2p_create_device(struct p2p_data *p2p, dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { count++; if (oldest == NULL || - os_time_before(&dev->last_seen, &oldest->last_seen)) + os_reltime_before(&dev->last_seen, &oldest->last_seen)) oldest = dev; } if (count + 1 > p2p->cfg->max_peers && oldest) { @@ -480,7 +480,7 @@ static int p2p_add_group_clients(struct p2p_data *p2p, const u8 *go_dev_addr, os_memcpy(dev->interface_addr, cli->p2p_interface_addr, ETH_ALEN); - os_get_time(&dev->last_seen); + os_get_reltime(&dev->last_seen); os_memcpy(dev->member_in_go_dev, go_dev_addr, ETH_ALEN); os_memcpy(dev->member_in_go_iface, go_interface_addr, ETH_ALEN); @@ -596,14 +596,14 @@ static void p2p_copy_wps_info(struct p2p_data *p2p, struct p2p_device *dev, * Info attributes. */ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, - struct os_time *rx_time, int level, const u8 *ies, + struct os_reltime *rx_time, int level, const u8 *ies, size_t ies_len, int scan_res) { struct p2p_device *dev; struct p2p_message msg; const u8 *p2p_dev_addr; int i; - struct os_time time_now; + struct os_reltime time_now; os_memset(&msg, 0, sizeof(msg)); if (p2p_parse_ies(ies, ies_len, &msg)) { @@ -637,7 +637,7 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, } if (rx_time == NULL) { - os_get_time(&time_now); + os_get_reltime(&time_now); rx_time = &time_now; } @@ -646,7 +646,7 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, * entry is newer than the one previously stored. */ if (dev->last_seen.sec > 0 && - os_time_before(rx_time, &dev->last_seen)) { + os_reltime_before(rx_time, &dev->last_seen)) { p2p_dbg(p2p, "Do not update peer entry based on old frame (rx_time=%u.%06u last_seen=%u.%06u)", (unsigned int) rx_time->sec, (unsigned int) rx_time->usec, @@ -656,7 +656,7 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, return -1; } - os_memcpy(&dev->last_seen, rx_time, sizeof(struct os_time)); + os_memcpy(&dev->last_seen, rx_time, sizeof(struct os_reltime)); dev->flags &= ~(P2P_DEV_PROBE_REQ_ONLY | P2P_DEV_GROUP_CLIENT_ONLY); @@ -982,7 +982,7 @@ int p2p_find(struct p2p_data *p2p, unsigned int timeout, int res; p2p_dbg(p2p, "Starting find (type=%d)", type); - os_get_time(&p2p->find_start); + os_get_reltime(&p2p->find_start); if (p2p->p2p_scan_running) { p2p_dbg(p2p, "p2p_scan is already running"); } @@ -1453,7 +1453,7 @@ int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr, void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr, struct p2p_device *dev, struct p2p_message *msg) { - os_get_time(&dev->last_seen); + os_get_reltime(&dev->last_seen); p2p_copy_wps_info(p2p, dev, 0, msg); @@ -1792,7 +1792,7 @@ static void p2p_add_dev_from_probe_req(struct p2p_data *p2p, const u8 *addr, if (dev) { if (dev->country[0] == 0 && msg.listen_channel) os_memcpy(dev->country, msg.listen_channel, 3); - os_get_time(&dev->last_seen); + os_get_reltime(&dev->last_seen); p2p_parse_free(&msg); return; /* already known */ } @@ -1803,7 +1803,7 @@ static void p2p_add_dev_from_probe_req(struct p2p_data *p2p, const u8 *addr, return; } - os_get_time(&dev->last_seen); + os_get_reltime(&dev->last_seen); dev->flags |= P2P_DEV_PROBE_REQ_ONLY; if (msg.listen_channel) { @@ -1837,7 +1837,7 @@ struct p2p_device * p2p_add_dev_from_go_neg_req(struct p2p_data *p2p, dev = p2p_get_device(p2p, addr); if (dev) { - os_get_time(&dev->last_seen); + os_get_reltime(&dev->last_seen); return dev; /* already known */ } @@ -2752,10 +2752,10 @@ static void p2p_prov_disc_cb(struct p2p_data *p2p, int success) int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, - struct os_time *rx_time, int level, const u8 *ies, + struct os_reltime *rx_time, int level, const u8 *ies, size_t ies_len) { - if (os_time_before(rx_time, &p2p->find_start)) { + if (os_reltime_before(rx_time, &p2p->find_start)) { /* * The driver may have cached (e.g., in cfg80211 BSS table) the * scan results for relatively long time. To avoid reporting @@ -3436,7 +3436,7 @@ int p2p_get_peer_info_txt(const struct p2p_peer_info *info, struct p2p_device *dev; int res; char *pos, *end; - struct os_time now; + struct os_reltime now; if (info == NULL) return -1; @@ -3447,7 +3447,7 @@ int p2p_get_peer_info_txt(const struct p2p_peer_info *info, pos = buf; end = buf + buflen; - os_get_time(&now); + os_get_reltime(&now); res = os_snprintf(pos, end - pos, "age=%d\n" "listen_freq=%d\n" diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 6e4a850..89fb004 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1244,7 +1244,7 @@ void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa, * start of a pending operation, e.g., to start a pending GO negotiation. */ int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, - struct os_time *rx_time, int level, const u8 *ies, + struct os_reltime *rx_time, int level, const u8 *ies, size_t ies_len); /** diff --git a/src/p2p/p2p_i.h b/src/p2p/p2p_i.h index 6b7f6bd..8bb703b 100644 --- a/src/p2p/p2p_i.h +++ b/src/p2p/p2p_i.h @@ -23,7 +23,7 @@ enum p2p_go_state { */ struct p2p_device { struct dl_list list; - struct os_time last_seen; + struct os_reltime last_seen; int listen_freq; enum p2p_wps_method wps_method; @@ -395,7 +395,7 @@ struct p2p_data { u8 *find_dev_id; u8 find_dev_id_buf[ETH_ALEN]; - struct os_time find_start; /* time of last p2p_find start */ + struct os_reltime find_start; /* time of last p2p_find start */ struct p2p_group **groups; size_t num_groups; @@ -716,7 +716,7 @@ struct p2p_device * p2p_add_dev_from_go_neg_req(struct p2p_data *p2p, void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr, struct p2p_device *dev, struct p2p_message *msg); int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, - struct os_time *rx_time, int level, const u8 *ies, + struct os_reltime *rx_time, int level, const u8 *ies, size_t ies_len, int scan_res); struct p2p_device * p2p_get_device(struct p2p_data *p2p, const u8 *addr); struct p2p_device * p2p_get_device_interface(struct p2p_data *p2p, diff --git a/src/radius/radius_client.c b/src/radius/radius_client.c index 290c7c8..7625996 100644 --- a/src/radius/radius_client.c +++ b/src/radius/radius_client.c @@ -122,7 +122,7 @@ struct radius_msg_list { /** * last_attempt - Time of the last transmission attempt */ - struct os_time last_attempt; + struct os_reltime last_attempt; /** * shared_secret - Shared secret with the target RADIUS server @@ -351,7 +351,7 @@ static int radius_client_retransmit(struct radius_client_data *radius, HOSTAPD_LEVEL_DEBUG, "Resending RADIUS message (id=%d)", radius_msg_get_hdr(entry->msg)->identifier); - os_get_time(&entry->last_attempt); + os_get_reltime(&entry->last_attempt); buf = radius_msg_get_buf(entry->msg); if (send(s, wpabuf_head(buf), wpabuf_len(buf), 0) < 0) radius_client_handle_send_error(radius, s, entry->msg_type); @@ -373,7 +373,7 @@ static void radius_client_timer(void *eloop_ctx, void *timeout_ctx) { struct radius_client_data *radius = eloop_ctx; struct hostapd_radius_servers *conf = radius->conf; - struct os_time now; + struct os_reltime now; os_time_t first; struct radius_msg_list *entry, *prev, *tmp; int auth_failover = 0, acct_failover = 0; @@ -383,7 +383,7 @@ static void radius_client_timer(void *eloop_ctx, void *timeout_ctx) if (!entry) return; - os_get_time(&now); + os_get_reltime(&now); first = 0; prev = NULL; @@ -481,7 +481,7 @@ static void radius_client_timer(void *eloop_ctx, void *timeout_ctx) static void radius_client_update_timeout(struct radius_client_data *radius) { - struct os_time now; + struct os_reltime now; os_time_t first; struct radius_msg_list *entry; @@ -497,7 +497,7 @@ static void radius_client_update_timeout(struct radius_client_data *radius) first = entry->next_try; } - os_get_time(&now); + os_get_reltime(&now); if (first < now.sec) first = now.sec; eloop_register_timeout(first - now.sec, 0, radius_client_timer, radius, @@ -536,7 +536,7 @@ static void radius_client_list_add(struct radius_client_data *radius, entry->msg_type = msg_type; entry->shared_secret = shared_secret; entry->shared_secret_len = shared_secret_len; - os_get_time(&entry->last_attempt); + os_get_reltime(&entry->last_attempt); entry->first_try = entry->last_attempt.sec; entry->next_try = entry->first_try + RADIUS_CLIENT_FIRST_WAIT; entry->attempts = 1; @@ -692,7 +692,7 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx) struct radius_rx_handler *handlers; size_t num_handlers, i; struct radius_msg_list *req, *prev_req; - struct os_time now; + struct os_reltime now; struct hostapd_radius_server *rconf; int invalid_authenticator = 0; @@ -772,7 +772,7 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx) goto fail; } - os_get_time(&now); + os_get_reltime(&now); roundtrip = (now.sec - req->last_attempt.sec) * 100 + (now.usec - req->last_attempt.usec) / 10000; hostapd_logger(radius->ctx, req->addr, HOSTAPD_MODULE_RADIUS, diff --git a/src/radius/radius_server.c b/src/radius/radius_server.c index fe19770..48b3c70 100644 --- a/src/radius/radius_server.c +++ b/src/radius/radius_server.c @@ -244,7 +244,7 @@ struct radius_server_data { /** * start_time - Timestamp of server start */ - struct os_time start_time; + struct os_reltime start_time; /** * counters - Statistics counters for server operations @@ -1261,7 +1261,7 @@ radius_server_init(struct radius_server_conf *conf) if (data == NULL) return NULL; - os_get_time(&data->start_time); + os_get_reltime(&data->start_time); data->conf_ctx = conf->conf_ctx; data->eap_sim_db_priv = conf->eap_sim_db_priv; data->ssl_ctx = conf->ssl_ctx; @@ -1375,7 +1375,7 @@ int radius_server_get_mib(struct radius_server_data *data, char *buf, int ret, uptime; unsigned int idx; char *end, *pos; - struct os_time now; + struct os_reltime now; struct radius_client *cli; /* RFC 2619 - RADIUS Authentication Server MIB */ @@ -1386,7 +1386,7 @@ int radius_server_get_mib(struct radius_server_data *data, char *buf, pos = buf; end = buf + buflen; - os_get_time(&now); + os_get_reltime(&now); uptime = (now.sec - data->start_time.sec) * 100 + ((now.usec - data->start_time.usec) / 10000) % 100; ret = os_snprintf(pos, end - pos, diff --git a/src/rsn_supp/peerkey.c b/src/rsn_supp/peerkey.c index 789ac25..f57050d 100644 --- a/src/rsn_supp/peerkey.c +++ b/src/rsn_supp/peerkey.c @@ -516,7 +516,7 @@ static int wpa_supplicant_process_smk_m45( struct wpa_peerkey *peerkey; struct wpa_eapol_ie_parse kde; u32 lifetime; - struct os_time now; + struct os_reltime now; if (!sm->peerkey_enabled || sm->proto != WPA_PROTO_RSN) { wpa_printf(MSG_DEBUG, "RSN: SMK handshake not allowed for " @@ -570,7 +570,7 @@ static int wpa_supplicant_process_smk_m45( if (lifetime > 1000000000) lifetime = 1000000000; /* avoid overflowing expiration time */ peerkey->lifetime = lifetime; - os_get_time(&now); + os_get_reltime(&now); peerkey->expiration = now.sec + lifetime; eloop_register_timeout(lifetime, 0, wpa_supplicant_smk_timeout, sm, peerkey); @@ -736,7 +736,7 @@ static void wpa_supplicant_update_smk_lifetime(struct wpa_sm *sm, struct wpa_eapol_ie_parse *kde) { u32 lifetime; - struct os_time now; + struct os_reltime now; if (kde->lifetime == NULL || kde->lifetime_len < sizeof(lifetime)) return; @@ -755,7 +755,7 @@ static void wpa_supplicant_update_smk_lifetime(struct wpa_sm *sm, lifetime, peerkey->lifetime); peerkey->lifetime = lifetime; - os_get_time(&now); + os_get_reltime(&now); peerkey->expiration = now.sec + lifetime; eloop_cancel_timeout(wpa_supplicant_smk_timeout, sm, peerkey); eloop_register_timeout(lifetime, 0, wpa_supplicant_smk_timeout, diff --git a/src/rsn_supp/pmksa_cache.c b/src/rsn_supp/pmksa_cache.c index 33fa1a2..0960815 100644 --- a/src/rsn_supp/pmksa_cache.c +++ b/src/rsn_supp/pmksa_cache.c @@ -53,9 +53,9 @@ static void pmksa_cache_free_entry(struct rsn_pmksa_cache *pmksa, static void pmksa_cache_expire(void *eloop_ctx, void *timeout_ctx) { struct rsn_pmksa_cache *pmksa = eloop_ctx; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); while (pmksa->pmksa && pmksa->pmksa->expiration <= now.sec) { struct rsn_pmksa_cache_entry *entry = pmksa->pmksa; pmksa->pmksa = entry->next; @@ -80,13 +80,13 @@ static void pmksa_cache_set_expiration(struct rsn_pmksa_cache *pmksa) { int sec; struct rsn_pmksa_cache_entry *entry; - struct os_time now; + struct os_reltime now; eloop_cancel_timeout(pmksa_cache_expire, pmksa, NULL); eloop_cancel_timeout(pmksa_cache_reauth, pmksa, NULL); if (pmksa->pmksa == NULL) return; - os_get_time(&now); + os_get_reltime(&now); sec = pmksa->pmksa->expiration - now.sec; if (sec < 0) sec = 0; @@ -125,7 +125,7 @@ pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa, void *network_ctx, int akmp) { struct rsn_pmksa_cache_entry *entry, *pos, *prev; - struct os_time now; + struct os_reltime now; if (pmk_len > PMK_LEN) return NULL; @@ -137,7 +137,7 @@ pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len, entry->pmk_len = pmk_len; rsn_pmkid(pmk, pmk_len, aa, spa, entry->pmkid, wpa_key_mgmt_sha256(akmp)); - os_get_time(&now); + os_get_reltime(&now); entry->expiration = now.sec + pmksa->sm->dot11RSNAConfigPMKLifetime; entry->reauth_time = now.sec + pmksa->sm->dot11RSNAConfigPMKLifetime * pmksa->sm->dot11RSNAConfigPMKReauthThreshold / 100; @@ -466,9 +466,9 @@ int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len) int i, ret; char *pos = buf; struct rsn_pmksa_cache_entry *entry; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); ret = os_snprintf(pos, buf + len - pos, "Index / AA / PMKID / expiration (in seconds) / " "opportunistic\n"); diff --git a/src/utils/eloop.c b/src/utils/eloop.c index ddddcf1..f8bb0fd 100644 --- a/src/utils/eloop.c +++ b/src/utils/eloop.c @@ -31,7 +31,7 @@ struct eloop_sock { struct eloop_timeout { struct dl_list list; - struct os_time time; + struct os_reltime time; void *eloop_data; void *user_data; eloop_timeout_handler handler; @@ -484,7 +484,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs, timeout = os_zalloc(sizeof(*timeout)); if (timeout == NULL) return -1; - if (os_get_time(&timeout->time) < 0) { + if (os_get_reltime(&timeout->time) < 0) { os_free(timeout); return -1; } @@ -514,7 +514,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs, /* Maintain timeouts in order of increasing time */ dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) { - if (os_time_before(&timeout->time, &tmp->time)) { + if (os_reltime_before(&timeout->time, &tmp->time)) { dl_list_add(tmp->list.prev, &timeout->list); return 0; } @@ -558,13 +558,13 @@ int eloop_cancel_timeout(eloop_timeout_handler handler, int eloop_cancel_timeout_one(eloop_timeout_handler handler, void *eloop_data, void *user_data, - struct os_time *remaining) + struct os_reltime *remaining) { struct eloop_timeout *timeout, *prev; int removed = 0; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); remaining->sec = remaining->usec = 0; dl_list_for_each_safe(timeout, prev, &eloop.timeout, @@ -573,8 +573,8 @@ int eloop_cancel_timeout_one(eloop_timeout_handler handler, (timeout->eloop_data == eloop_data) && (timeout->user_data == user_data)) { removed = 1; - if (os_time_before(&now, &timeout->time)) - os_time_sub(&timeout->time, &now, remaining); + if (os_reltime_before(&now, &timeout->time)) + os_reltime_sub(&timeout->time, &now, remaining); eloop_remove_timeout(timeout); break; } @@ -603,7 +603,7 @@ int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs, eloop_timeout_handler handler, void *eloop_data, void *user_data) { - struct os_time now, requested, remaining; + struct os_reltime now, requested, remaining; struct eloop_timeout *tmp; dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) { @@ -612,9 +612,9 @@ int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs, tmp->user_data == user_data) { requested.sec = req_secs; requested.usec = req_usecs; - os_get_time(&now); - os_time_sub(&tmp->time, &now, &remaining); - if (os_time_before(&remaining, &requested)) { + os_get_reltime(&now); + os_reltime_sub(&tmp->time, &now, &remaining); + if (os_reltime_before(&remaining, &requested)) { eloop_cancel_timeout(handler, eloop_data, user_data); eloop_register_timeout(requested.sec, @@ -745,7 +745,7 @@ void eloop_run(void) struct timeval _tv; #endif /* CONFIG_ELOOP_POLL */ int res; - struct os_time tv, now; + struct os_reltime tv, now; #ifndef CONFIG_ELOOP_POLL rfds = os_malloc(sizeof(*rfds)); @@ -762,9 +762,9 @@ void eloop_run(void) timeout = dl_list_first(&eloop.timeout, struct eloop_timeout, list); if (timeout) { - os_get_time(&now); - if (os_time_before(&now, &timeout->time)) - os_time_sub(&timeout->time, &now, &tv); + os_get_reltime(&now); + if (os_reltime_before(&now, &timeout->time)) + os_reltime_sub(&timeout->time, &now, &tv); else tv.sec = tv.usec = 0; #ifdef CONFIG_ELOOP_POLL @@ -806,8 +806,8 @@ void eloop_run(void) timeout = dl_list_first(&eloop.timeout, struct eloop_timeout, list); if (timeout) { - os_get_time(&now); - if (!os_time_before(&now, &timeout->time)) { + os_get_reltime(&now); + if (!os_reltime_before(&now, &timeout->time)) { void *eloop_data = timeout->eloop_data; void *user_data = timeout->user_data; eloop_timeout_handler handler = @@ -852,9 +852,9 @@ void eloop_terminate(void) void eloop_destroy(void) { struct eloop_timeout *timeout, *prev; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); dl_list_for_each_safe(timeout, prev, &eloop.timeout, struct eloop_timeout, list) { int sec, usec; diff --git a/src/utils/eloop.h b/src/utils/eloop.h index befb070..049f291 100644 --- a/src/utils/eloop.h +++ b/src/utils/eloop.h @@ -207,7 +207,7 @@ int eloop_cancel_timeout(eloop_timeout_handler handler, */ int eloop_cancel_timeout_one(eloop_timeout_handler handler, void *eloop_data, void *user_data, - struct os_time *remaining); + struct os_reltime *remaining); /** * eloop_is_timeout_registered - Check if a timeout is already registered diff --git a/src/utils/eloop_none.c b/src/utils/eloop_none.c index cb5e922..e832501 100644 --- a/src/utils/eloop_none.c +++ b/src/utils/eloop_none.c @@ -22,7 +22,7 @@ struct eloop_sock { struct eloop_timeout { struct dl_list list; - struct os_time time; + struct os_reltime time; void *eloop_data; void *user_data; eloop_timeout_handler handler; @@ -118,7 +118,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs, timeout = os_zalloc(sizeof(*timeout)); if (timeout == NULL) return -1; - if (os_get_time(&timeout->time) < 0) { + if (os_get_reltime(&timeout->time) < 0) { os_free(timeout); return -1; } @@ -145,7 +145,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs, /* Maintain timeouts in order of increasing time */ dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) { - if (os_time_before(&timeout->time, &tmp->time)) { + if (os_reltime_before(&timeout->time, &tmp->time)) { dl_list_add(tmp->list.prev, &timeout->list); return 0; } @@ -187,13 +187,13 @@ int eloop_cancel_timeout(eloop_timeout_handler handler, int eloop_cancel_timeout_one(eloop_timeout_handler handler, void *eloop_data, void *user_data, - struct os_time *remaining) + struct os_reltime *remaining) { struct eloop_timeout *timeout, *prev; int removed = 0; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); remaining->sec = remaining->usec = 0; dl_list_for_each_safe(timeout, prev, &eloop.timeout, @@ -202,8 +202,8 @@ int eloop_cancel_timeout_one(eloop_timeout_handler handler, (timeout->eloop_data == eloop_data) && (timeout->user_data == user_data)) { removed = 1; - if (os_time_before(&now, &timeout->time)) - os_time_sub(&timeout->time, &now, remaining); + if (os_reltime_before(&now, &timeout->time)) + os_reltime_sub(&timeout->time, &now, remaining); eloop_remove_timeout(timeout); break; } @@ -318,7 +318,7 @@ int eloop_register_signal_reconfig(eloop_signal_handler handler, void eloop_run(void) { int i; - struct os_time tv, now; + struct os_reltime tv, now; while (!eloop.terminate && (!dl_list_empty(&eloop.timeout) || eloop.reader_count > 0)) { @@ -326,9 +326,9 @@ void eloop_run(void) timeout = dl_list_first(&eloop.timeout, struct eloop_timeout, list); if (timeout) { - os_get_time(&now); - if (os_time_before(&now, &timeout->time)) - os_time_sub(&timeout->time, &now, &tv); + os_get_reltime(&now); + if (os_reltime_before(&now, &timeout->time)) + os_reltime_sub(&timeout->time, &now, &tv); else tv.sec = tv.usec = 0; } @@ -345,8 +345,8 @@ void eloop_run(void) timeout = dl_list_first(&eloop.timeout, struct eloop_timeout, list); if (timeout) { - os_get_time(&now); - if (!os_time_before(&now, &timeout->time)) { + os_get_reltime(&now); + if (!os_reltime_before(&now, &timeout->time)) { void *eloop_data = timeout->eloop_data; void *user_data = timeout->user_data; eloop_timeout_handler handler = diff --git a/src/utils/eloop_win.c b/src/utils/eloop_win.c index 1f40530..f9b73bd 100644 --- a/src/utils/eloop_win.c +++ b/src/utils/eloop_win.c @@ -31,7 +31,7 @@ struct eloop_event { struct eloop_timeout { struct dl_list list; - struct os_time time; + struct os_reltime time; void *eloop_data; void *user_data; eloop_timeout_handler handler; @@ -244,7 +244,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs, timeout = os_zalloc(sizeof(*timeout)); if (timeout == NULL) return -1; - if (os_get_time(&timeout->time) < 0) { + if (os_get_reltime(&timeout->time) < 0) { os_free(timeout); return -1; } @@ -271,7 +271,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs, /* Maintain timeouts in order of increasing time */ dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) { - if (os_time_before(&timeout->time, &tmp->time)) { + if (os_reltime_before(&timeout->time, &tmp->time)) { dl_list_add(tmp->list.prev, &timeout->list); return 0; } @@ -313,13 +313,13 @@ int eloop_cancel_timeout(eloop_timeout_handler handler, int eloop_cancel_timeout_one(eloop_timeout_handler handler, void *eloop_data, void *user_data, - struct os_time *remaining) + struct os_reltime *remaining) { struct eloop_timeout *timeout, *prev; int removed = 0; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); remaining->sec = remaining->usec = 0; dl_list_for_each_safe(timeout, prev, &eloop.timeout, @@ -328,8 +328,8 @@ int eloop_cancel_timeout_one(eloop_timeout_handler handler, (timeout->eloop_data == eloop_data) && (timeout->user_data == user_data)) { removed = 1; - if (os_time_before(&now, &timeout->time)) - os_time_sub(&timeout->time, &now, remaining); + if (os_reltime_before(&now, &timeout->time)) + os_reltime_sub(&timeout->time, &now, remaining); eloop_remove_timeout(timeout); break; } @@ -358,7 +358,7 @@ int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs, eloop_timeout_handler handler, void *eloop_data, void *user_data) { - struct os_time now, requested, remaining; + struct os_reltime now, requested, remaining; struct eloop_timeout *tmp; dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) { @@ -367,9 +367,9 @@ int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs, tmp->user_data == user_data) { requested.sec = req_secs; requested.usec = req_usecs; - os_get_time(&now); - os_time_sub(&tmp->time, &now, &remaining); - if (os_time_before(&remaining, &requested)) { + os_get_reltime(&now); + os_reltime_sub(&tmp->time, &now, &remaining); + if (os_reltime_before(&remaining, &requested)) { eloop_cancel_timeout(handler, eloop_data, user_data); eloop_register_timeout(requested.sec, @@ -499,7 +499,7 @@ int eloop_register_signal_reconfig(eloop_signal_handler handler, void eloop_run(void) { - struct os_time tv, now; + struct os_reltime tv, now; DWORD count, ret, timeout_val, err; size_t i; @@ -511,9 +511,9 @@ void eloop_run(void) timeout = dl_list_first(&eloop.timeout, struct eloop_timeout, list); if (timeout) { - os_get_time(&now); - if (os_time_before(&now, &timeout->time)) - os_time_sub(&timeout->time, &now, &tv); + os_get_reltime(&now); + if (os_reltime_before(&now, &timeout->time)) + os_reltime_sub(&timeout->time, &now, &tv); } count = 0; @@ -552,8 +552,8 @@ void eloop_run(void) timeout = dl_list_first(&eloop.timeout, struct eloop_timeout, list); if (timeout) { - os_get_time(&now); - if (!os_time_before(&now, &timeout->time)) { + os_get_reltime(&now); + if (!os_reltime_before(&now, &timeout->time)) { void *eloop_data = timeout->eloop_data; void *user_data = timeout->user_data; eloop_timeout_handler handler = diff --git a/src/utils/os.h b/src/utils/os.h index 2aab13a..77dc6e3 100644 --- a/src/utils/os.h +++ b/src/utils/os.h @@ -23,6 +23,11 @@ struct os_time { os_time_t usec; }; +struct os_reltime { + os_time_t sec; + os_time_t usec; +}; + /** * os_get_time - Get current time (sec, usec) * @t: Pointer to buffer for the time @@ -30,21 +35,56 @@ struct os_time { */ int os_get_time(struct os_time *t); +/** + * os_get_reltime - Get relative time (sec, usec) + * @t: Pointer to buffer for the time + * Returns: 0 on success, -1 on failure + */ +int os_get_reltime(struct os_reltime *t); + + +/* Helpers for handling struct os_time */ + +static inline int os_time_before(struct os_time *a, struct os_time *b) +{ + return (a->sec < b->sec) || + (a->sec == b->sec && a->usec < b->usec); +} + + +static inline void os_time_sub(struct os_time *a, struct os_time *b, + struct os_time *res) +{ + res->sec = a->sec - b->sec; + res->usec = a->usec - b->usec; + if (res->usec < 0) { + res->sec--; + res->usec += 1000000; + } +} + -/* Helper macros for handling struct os_time */ +/* Helpers for handling struct os_reltime */ -#define os_time_before(a, b) \ - ((a)->sec < (b)->sec || \ - ((a)->sec == (b)->sec && (a)->usec < (b)->usec)) +static inline int os_reltime_before(struct os_reltime *a, + struct os_reltime *b) +{ + return (a->sec < b->sec) || + (a->sec == b->sec && a->usec < b->usec); +} + + +static inline void os_reltime_sub(struct os_reltime *a, struct os_reltime *b, + struct os_reltime *res) +{ + res->sec = a->sec - b->sec; + res->usec = a->usec - b->usec; + if (res->usec < 0) { + res->sec--; + res->usec += 1000000; + } +} -#define os_time_sub(a, b, res) do { \ - (res)->sec = (a)->sec - (b)->sec; \ - (res)->usec = (a)->usec - (b)->usec; \ - if ((res)->usec < 0) { \ - (res)->sec--; \ - (res)->usec += 1000000; \ - } \ -} while (0) /** * os_mktime - Convert broken-down time into seconds since 1970-01-01 diff --git a/src/utils/os_internal.c b/src/utils/os_internal.c index e4b7fdb..21bd069 100644 --- a/src/utils/os_internal.c +++ b/src/utils/os_internal.c @@ -30,7 +30,7 @@ void os_sleep(os_time_t sec, os_time_t usec) } -int os_get_time(struct os_time *t) +int os_get_reltime(struct os_reltime *t) { int res; struct timeval tv; diff --git a/src/utils/os_none.c b/src/utils/os_none.c index cabf73b..8daf88a 100644 --- a/src/utils/os_none.c +++ b/src/utils/os_none.c @@ -20,6 +20,12 @@ void os_sleep(os_time_t sec, os_time_t usec) } +int os_get_reltime(struct os_reltime *t) +{ + return -1; +} + + int os_get_time(struct os_time *t) { return -1; diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c index 960073a..5265c3c 100644 --- a/src/utils/os_unix.c +++ b/src/utils/os_unix.c @@ -60,6 +60,33 @@ int os_get_time(struct os_time *t) } +int os_get_reltime(struct os_reltime *t) +{ + static clockid_t clock_id = CLOCK_BOOTTIME; + struct timespec ts; + int res; + + while (1) { + res = clock_gettime(clock_id, &ts); + if (res == 0) { + t->sec = ts.tv_sec; + t->usec = ts.tv_nsec / 1000; + return 0; + } + switch (clock_id) { + case CLOCK_BOOTTIME: + clock_id = CLOCK_MONOTONIC; + break; + case CLOCK_MONOTONIC: + clock_id = CLOCK_REALTIME; + break; + case CLOCK_REALTIME: + return -1; + } + } +} + + int os_mktime(int year, int month, int day, int hour, int min, int sec, os_time_t *t) { diff --git a/src/utils/os_win32.c b/src/utils/os_win32.c index 163cebe..0054b3b 100644 --- a/src/utils/os_win32.c +++ b/src/utils/os_win32.c @@ -47,6 +47,16 @@ int os_get_time(struct os_time *t) } +int os_get_reltime(struct os_reltime *t) +{ + struct os_time now; + int res = os_get_time(&now); + t->sec = now.sec; + t->usec = now.usec; + return res; +} + + int os_mktime(int year, int month, int day, int hour, int min, int sec, os_time_t *t) { diff --git a/src/wps/wps_common.c b/src/wps/wps_common.c index 4b431ad..02332b6 100644 --- a/src/wps/wps_common.c +++ b/src/wps/wps_common.c @@ -238,8 +238,8 @@ unsigned int wps_generate_pin(void) /* Generate seven random digits for the PIN */ if (random_get_bytes((unsigned char *) &val, sizeof(val)) < 0) { - struct os_time now; - os_get_time(&now); + struct os_reltime now; + os_get_reltime(&now); val = os_random() ^ now.sec ^ now.usec; } val %= 10000000; diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c index ef17617..4b65eeb 100644 --- a/src/wps/wps_registrar.c +++ b/src/wps/wps_registrar.c @@ -82,7 +82,7 @@ struct wps_uuid_pin { #define PIN_LOCKED BIT(0) #define PIN_EXPIRES BIT(1) int flags; - struct os_time expiration; + struct os_reltime expiration; u8 enrollee_addr[ETH_ALEN]; }; @@ -113,7 +113,7 @@ struct wps_pbc_session { struct wps_pbc_session *next; u8 addr[ETH_ALEN]; u8 uuid_e[WPS_UUID_LEN]; - struct os_time timestamp; + struct os_reltime timestamp; }; @@ -183,7 +183,7 @@ struct wps_registrar { u8 p2p_dev_addr[ETH_ALEN]; u8 pbc_ignore_uuid[WPS_UUID_LEN]; - struct os_time pbc_ignore_start; + struct os_reltime pbc_ignore_start; }; @@ -311,9 +311,9 @@ static void wps_registrar_add_pbc_session(struct wps_registrar *reg, const u8 *addr, const u8 *uuid_e) { struct wps_pbc_session *pbc, *prev = NULL; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); pbc = reg->pbc_sessions; while (pbc) { @@ -395,9 +395,9 @@ int wps_registrar_pbc_overlap(struct wps_registrar *reg, int count = 0; struct wps_pbc_session *pbc; struct wps_pbc_session *first = NULL; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); wpa_printf(MSG_DEBUG, "WPS: Checking active PBC sessions for overlap"); @@ -748,7 +748,7 @@ int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr, if (timeout) { p->flags |= PIN_EXPIRES; - os_get_time(&p->expiration); + os_get_reltime(&p->expiration); p->expiration.sec += timeout; } @@ -797,13 +797,13 @@ static void wps_registrar_remove_pin(struct wps_registrar *reg, static void wps_registrar_expire_pins(struct wps_registrar *reg) { struct wps_uuid_pin *pin, *prev; - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); dl_list_for_each_safe(pin, prev, ®->pins, struct wps_uuid_pin, list) { if ((pin->flags & PIN_EXPIRES) && - os_time_before(&pin->expiration, &now)) { + os_reltime_before(&pin->expiration, &now)) { wpa_hexdump(MSG_DEBUG, "WPS: Expired PIN for UUID", pin->uuid, WPS_UUID_LEN); wps_registrar_remove_pin(reg, pin); @@ -1037,7 +1037,7 @@ void wps_registrar_complete(struct wps_registrar *registrar, const u8 *uuid_e, wps_registrar_remove_pbc_session(registrar, uuid_e, NULL); wps_registrar_pbc_completed(registrar); - os_get_time(®istrar->pbc_ignore_start); + os_get_reltime(®istrar->pbc_ignore_start); os_memcpy(registrar->pbc_ignore_uuid, uuid_e, WPS_UUID_LEN); } else { wps_registrar_pin_completed(registrar); @@ -1140,9 +1140,9 @@ void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr, #ifdef WPS_WORKAROUNDS if (reg->pbc_ignore_start.sec && os_memcmp(attr.uuid_e, reg->pbc_ignore_uuid, WPS_UUID_LEN) == 0) { - struct os_time now, dur; - os_get_time(&now); - os_time_sub(&now, ®->pbc_ignore_start, &dur); + struct os_reltime now, dur; + os_get_reltime(&now); + os_reltime_sub(&now, ®->pbc_ignore_start, &dur); if (dur.sec >= 0 && dur.sec < 5) { wpa_printf(MSG_DEBUG, "WPS: Ignore PBC activation " "based on Probe Request from the Enrollee " @@ -3189,7 +3189,7 @@ static enum wps_process_res wps_process_wsc_done(struct wps_data *wps, wps->uuid_e, wps->p2p_dev_addr); wps_registrar_pbc_completed(wps->wps->registrar); - os_get_time(&wps->wps->registrar->pbc_ignore_start); + os_get_reltime(&wps->wps->registrar->pbc_ignore_start); os_memcpy(wps->wps->registrar->pbc_ignore_uuid, wps->uuid_e, WPS_UUID_LEN); } else { diff --git a/src/wps/wps_upnp.c b/src/wps/wps_upnp.c index bea2b33..29e8320 100644 --- a/src/wps/wps_upnp.c +++ b/src/wps/wps_upnp.c @@ -480,14 +480,14 @@ static void upnp_wps_device_send_event(struct upnp_wps_device_sm *sm) "\n" "\n"; const char *format_tail = "\n"; - struct os_time now; + struct os_reltime now; if (dl_list_empty(&sm->subscriptions)) { /* optimize */ return; } - if (os_get_time(&now) == 0) { + if (os_get_reltime(&now) == 0) { if (now.sec != sm->last_event_sec) { sm->last_event_sec = now.sec; sm->num_events_in_sec = 1; diff --git a/wpa_supplicant/bgscan_learn.c b/wpa_supplicant/bgscan_learn.c index 07d31e4..429e605 100644 --- a/wpa_supplicant/bgscan_learn.c +++ b/wpa_supplicant/bgscan_learn.c @@ -34,7 +34,7 @@ struct bgscan_learn_data { int signal_threshold; int short_interval; /* use if signal < threshold */ int long_interval; /* use if signal > threshold */ - struct os_time last_bgscan; + struct os_reltime last_bgscan; char *fname; struct dl_list bss; int *supp_freqs; @@ -311,7 +311,7 @@ static void bgscan_learn_timeout(void *eloop_ctx, void *timeout_ctx) eloop_register_timeout(data->scan_interval, 0, bgscan_learn_timeout, data, NULL); } else - os_get_time(&data->last_bgscan); + os_get_reltime(&data->last_bgscan); os_free(freqs); } @@ -428,7 +428,7 @@ static void * bgscan_learn_init(struct wpa_supplicant *wpa_s, * us skip an immediate new scan in cases where the current signal * level is below the bgscan threshold. */ - os_get_time(&data->last_bgscan); + os_get_reltime(&data->last_bgscan); return data; } @@ -555,7 +555,7 @@ static void bgscan_learn_notify_signal_change(void *priv, int above, { struct bgscan_learn_data *data = priv; int scan = 0; - struct os_time now; + struct os_reltime now; if (data->short_interval == data->long_interval || data->signal_threshold == 0) @@ -569,7 +569,7 @@ static void bgscan_learn_notify_signal_change(void *priv, int above, wpa_printf(MSG_DEBUG, "bgscan learn: Start using short bgscan " "interval"); data->scan_interval = data->short_interval; - os_get_time(&now); + os_get_reltime(&now); if (now.sec > data->last_bgscan.sec + 1) scan = 1; } else if (data->scan_interval == data->short_interval && above) { @@ -584,7 +584,7 @@ static void bgscan_learn_notify_signal_change(void *priv, int above, * Signal dropped further 4 dB. Request a new scan if we have * not yet scanned in a while. */ - os_get_time(&now); + os_get_reltime(&now); if (now.sec > data->last_bgscan.sec + 10) scan = 1; } diff --git a/wpa_supplicant/bgscan_simple.c b/wpa_supplicant/bgscan_simple.c index 479f703..a467cc5 100644 --- a/wpa_supplicant/bgscan_simple.c +++ b/wpa_supplicant/bgscan_simple.c @@ -26,7 +26,7 @@ struct bgscan_simple_data { int max_short_scans; /* maximum times we short-scan before back-off */ int short_interval; /* use if signal < threshold */ int long_interval; /* use if signal > threshold */ - struct os_time last_bgscan; + struct os_reltime last_bgscan; }; @@ -75,7 +75,7 @@ static void bgscan_simple_timeout(void *eloop_ctx, void *timeout_ctx) */ data->short_scan_count--; } - os_get_time(&data->last_bgscan); + os_get_reltime(&data->last_bgscan); } } @@ -159,7 +159,7 @@ static void * bgscan_simple_init(struct wpa_supplicant *wpa_s, * us skip an immediate new scan in cases where the current signal * level is below the bgscan threshold. */ - os_get_time(&data->last_bgscan); + os_get_reltime(&data->last_bgscan); return data; } @@ -211,7 +211,7 @@ static void bgscan_simple_notify_signal_change(void *priv, int above, { struct bgscan_simple_data *data = priv; int scan = 0; - struct os_time now; + struct os_reltime now; if (data->short_interval == data->long_interval || data->signal_threshold == 0) @@ -225,7 +225,7 @@ static void bgscan_simple_notify_signal_change(void *priv, int above, wpa_printf(MSG_DEBUG, "bgscan simple: Start using short " "bgscan interval"); data->scan_interval = data->short_interval; - os_get_time(&now); + os_get_reltime(&now); if (now.sec > data->last_bgscan.sec + 1 && data->short_scan_count <= data->max_short_scans) /* @@ -259,7 +259,7 @@ static void bgscan_simple_notify_signal_change(void *priv, int above, * Signal dropped further 4 dB. Request a new scan if we have * not yet scanned in a while. */ - os_get_time(&now); + os_get_reltime(&now); if (now.sec > data->last_bgscan.sec + 10) scan = 1; } diff --git a/wpa_supplicant/bss.c b/wpa_supplicant/bss.c index df1a0c8..fbe53df 100644 --- a/wpa_supplicant/bss.c +++ b/wpa_supplicant/bss.c @@ -224,9 +224,9 @@ struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid, } -static void calculate_update_time(const struct os_time *fetch_time, +static void calculate_update_time(const struct os_reltime *fetch_time, unsigned int age_ms, - struct os_time *update_time) + struct os_reltime *update_time) { os_time_t usec; @@ -243,7 +243,7 @@ static void calculate_update_time(const struct os_time *fetch_time, static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src, - struct os_time *fetch_time) + struct os_reltime *fetch_time) { dst->flags = src->flags; os_memcpy(dst->bssid, src->bssid, ETH_ALEN); @@ -326,7 +326,7 @@ static int wpa_bss_remove_oldest(struct wpa_supplicant *wpa_s) static struct wpa_bss * wpa_bss_add(struct wpa_supplicant *wpa_s, const u8 *ssid, size_t ssid_len, struct wpa_scan_res *res, - struct os_time *fetch_time) + struct os_reltime *fetch_time) { struct wpa_bss *bss; @@ -492,7 +492,7 @@ static void notify_bss_changes(struct wpa_supplicant *wpa_s, u32 changes, static struct wpa_bss * wpa_bss_update(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, - struct wpa_scan_res *res, struct os_time *fetch_time) + struct wpa_scan_res *res, struct os_reltime *fetch_time) { u32 changes; @@ -587,17 +587,17 @@ void wpa_bss_update_start(struct wpa_supplicant *wpa_s) */ void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s, struct wpa_scan_res *res, - struct os_time *fetch_time) + struct os_reltime *fetch_time) { const u8 *ssid, *p2p; struct wpa_bss *bss; if (wpa_s->conf->ignore_old_scan_res) { - struct os_time update; + struct os_reltime update; calculate_update_time(fetch_time, res->age, &update); - if (os_time_before(&update, &wpa_s->scan_trigger_time)) { - struct os_time age; - os_time_sub(&wpa_s->scan_trigger_time, &update, &age); + if (os_reltime_before(&update, &wpa_s->scan_trigger_time)) { + struct os_reltime age; + os_reltime_sub(&wpa_s->scan_trigger_time, &update, &age); wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Ignore driver BSS " "table entry that is %u.%06u seconds older " "than our scan trigger", @@ -732,7 +732,7 @@ void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info, struct wpa_bss *bss, *n; wpa_s->last_scan_full = 0; - os_get_time(&wpa_s->last_scan); + os_get_reltime(&wpa_s->last_scan); if (!new_scan) return; /* do not expire entries without new scan */ @@ -781,19 +781,19 @@ void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info, void wpa_bss_flush_by_age(struct wpa_supplicant *wpa_s, int age) { struct wpa_bss *bss, *n; - struct os_time t; + struct os_reltime t; if (dl_list_empty(&wpa_s->bss)) return; - os_get_time(&t); + os_get_reltime(&t); t.sec -= age; dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) { if (wpa_bss_in_use(wpa_s, bss)) continue; - if (os_time_before(&bss->last_update, &t)) { + if (os_reltime_before(&bss->last_update, &t)) { wpa_bss_remove(wpa_s, bss, __func__); } else break; @@ -900,7 +900,7 @@ struct wpa_bss * wpa_bss_get_bssid_latest(struct wpa_supplicant *wpa_s, if (os_memcmp(bss->bssid, bssid, ETH_ALEN) != 0) continue; if (found == NULL || - os_time_before(&found->last_update, &bss->last_update)) + os_reltime_before(&found->last_update, &bss->last_update)) found = bss; } return found; diff --git a/wpa_supplicant/bss.h b/wpa_supplicant/bss.h index 0d2693f..4deeb5f 100644 --- a/wpa_supplicant/bss.h +++ b/wpa_supplicant/bss.h @@ -84,7 +84,7 @@ struct wpa_bss { /** Timestamp of last Beacon/Probe Response frame */ u64 tsf; /** Time of the last update (i.e., Beacon or Probe Response RX) */ - struct os_time last_update; + struct os_reltime last_update; /** ANQP data */ struct wpa_bss_anqp *anqp; /** Length of the following IE field in octets (from Probe Response) */ @@ -98,7 +98,7 @@ struct wpa_bss { void wpa_bss_update_start(struct wpa_supplicant *wpa_s); void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s, struct wpa_scan_res *res, - struct os_time *fetch_time); + struct os_reltime *fetch_time); void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info, int new_scan); int wpa_bss_init(struct wpa_supplicant *wpa_s); diff --git a/wpa_supplicant/config_ssid.h b/wpa_supplicant/config_ssid.h index 0102da9..c8837eb 100644 --- a/wpa_supplicant/config_ssid.h +++ b/wpa_supplicant/config_ssid.h @@ -610,7 +610,7 @@ struct wpa_ssid { /** * disabled_until - Network block disabled until this time if non-zero */ - struct os_time disabled_until; + struct os_reltime disabled_until; /** * parent_cred - Pointer to parent wpa_cred entry diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index ebe08b3..e18c95c 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -3220,9 +3220,9 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, } if (mask & WPA_BSS_MASK_AGE) { - struct os_time now; + struct os_reltime now; - os_get_time(&now); + os_get_reltime(&now); ret = os_snprintf(pos, end - pos, "age=%d\n", (int) (now.sec - bss->last_update.sec)); if (ret < 0 || ret >= end - pos) diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 4493772..f49ddcd 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -53,12 +53,12 @@ static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, static int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) { - struct os_time now; + struct os_reltime now; if (ssid == NULL || ssid->disabled_until.sec == 0) return 0; - os_get_time(&now); + os_get_reltime(&now); if (ssid->disabled_until.sec > now.sec) return ssid->disabled_until.sec - now.sec; @@ -1435,12 +1435,12 @@ int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) #ifdef CONFIG_NO_SCAN_PROCESSING return -1; #else /* CONFIG_NO_SCAN_PROCESSING */ - struct os_time now; + struct os_reltime now; if (wpa_s->last_scan_res_used <= 0) return -1; - os_get_time(&now); + os_get_reltime(&now); if (now.sec - wpa_s->last_scan.sec > 5) { wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); return -1; @@ -1958,9 +1958,9 @@ static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, wpa_s->last_eapol_matches_bssid = 0; if (wpa_s->pending_eapol_rx) { - struct os_time now, age; - os_get_time(&now); - os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); + struct os_reltime now, age; + os_get_reltime(&now); + os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age); if (age.sec == 0 && age.usec < 100000 && os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == 0) { @@ -2190,11 +2190,11 @@ wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, union wpa_event_data *data) { int pairwise; - struct os_time t; + struct os_reltime t; wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); pairwise = (data && data->michael_mic_failure.unicast); - os_get_time(&t); + os_get_reltime(&t); if ((wpa_s->last_michael_mic_error && t.sec - wpa_s->last_michael_mic_error <= 60) || wpa_s->pending_mic_error_report) { diff --git a/wpa_supplicant/ibss_rsn.c b/wpa_supplicant/ibss_rsn.c index 47ef35e..3083dd8 100644 --- a/wpa_supplicant/ibss_rsn.c +++ b/wpa_supplicant/ibss_rsn.c @@ -590,7 +590,7 @@ int ibss_rsn_start(struct ibss_rsn *ibss_rsn, const u8 *addr) peer->authentication_status |= IBSS_RSN_AUTH_BY_US; return ibss_rsn_auth_init(ibss_rsn, peer); } else { - os_get_time(&peer->own_auth_tx); + os_get_reltime(&peer->own_auth_tx); eloop_register_timeout(1, 0, ibss_rsn_auth_timeout, peer, NULL); } @@ -834,9 +834,9 @@ static void ibss_rsn_handle_auth_1_of_2(struct ibss_rsn *ibss_rsn, if (peer && peer->authentication_status & IBSS_RSN_AUTH_EAPOL_BY_PEER) { if (peer->own_auth_tx.sec) { - struct os_time now, diff; - os_get_time(&now); - os_time_sub(&now, &peer->own_auth_tx, &diff); + struct os_reltime now, diff; + os_get_reltime(&now); + os_reltime_sub(&now, &peer->own_auth_tx, &diff); if (diff.sec == 0 && diff.usec < 500000) { wpa_printf(MSG_DEBUG, "RSN: Skip IBSS reinit since only %u usec from own Auth frame TX", (int) diff.usec); diff --git a/wpa_supplicant/ibss_rsn.h b/wpa_supplicant/ibss_rsn.h index 3089283..67fae2d 100644 --- a/wpa_supplicant/ibss_rsn.h +++ b/wpa_supplicant/ibss_rsn.h @@ -40,7 +40,7 @@ struct ibss_rsn_peer { struct wpa_state_machine *auth; int authentication_status; - struct os_time own_auth_tx; + struct os_reltime own_auth_tx; }; struct ibss_rsn { diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 226acd6..585f7f9 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -198,13 +198,13 @@ static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, for (i = 0; i < scan_res->num; i++) { struct wpa_scan_res *bss = scan_res->res[i]; - struct os_time time_tmp_age, entry_ts; + struct os_reltime time_tmp_age, entry_ts; const u8 *ies; size_t ies_len; time_tmp_age.sec = bss->age / 1000; time_tmp_age.usec = (bss->age % 1000) * 1000; - os_time_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts); + os_reltime_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts); ies = (const u8 *) (bss + 1); ies_len = bss->ie_len; @@ -311,7 +311,7 @@ static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq, } } } else { - os_get_time(&wpa_s->scan_trigger_time); + os_get_reltime(&wpa_s->scan_trigger_time); wpa_s->scan_res_handler = wpas_p2p_scan_res_handler; } @@ -842,7 +842,7 @@ static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s, network_id = ssid->id; if (!client) { wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0); - os_get_time(&wpa_s->global->p2p_go_wait_client); + os_get_reltime(&wpa_s->global->p2p_go_wait_client); } } @@ -1019,7 +1019,7 @@ static void p2p_go_configured(void *ctx, void *data) " [PERSISTENT]" : ""); } - os_get_time(&wpa_s->global->p2p_go_wait_client); + os_get_reltime(&wpa_s->global->p2p_go_wait_client); if (params->persistent_group) { network_id = wpas_p2p_store_persistent_group( wpa_s->parent, ssid, @@ -3747,7 +3747,7 @@ static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s, return 0; } - updated = os_time_before(&wpa_s->p2p_auto_started, &bss->last_update); + updated = os_reltime_before(&wpa_s->p2p_auto_started, &bss->last_update); wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at " "%ld.%06ld (%supdated in last scan)", bss->last_update.sec, bss->last_update.usec, @@ -3992,7 +3992,7 @@ static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq) */ ret = wpa_drv_scan(wpa_s, ¶ms); if (!ret) { - os_get_time(&wpa_s->scan_trigger_time); + os_get_reltime(&wpa_s->scan_trigger_time); wpa_s->scan_res_handler = wpas_p2p_scan_res_join; } @@ -4275,7 +4275,7 @@ int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, dev_addr); } if (auto_join) { - os_get_time(&wpa_s->p2p_auto_started); + os_get_reltime(&wpa_s->p2p_auto_started); wpa_printf(MSG_DEBUG, "P2P: Auto join started at " "%ld.%06ld", wpa_s->p2p_auto_started.sec, @@ -5025,7 +5025,7 @@ int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr, wpa_s->auto_pd_scan_retry = 0; wpas_p2p_stop_find(wpa_s); wpa_s->p2p_join_scan_count = 0; - os_get_time(&wpa_s->p2p_auto_started); + os_get_reltime(&wpa_s->p2p_auto_started); wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld", wpa_s->p2p_auto_started.sec, wpa_s->p2p_auto_started.usec); @@ -6100,8 +6100,8 @@ int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s) } if (!ret && wpa_s->global->p2p_go_wait_client.sec) { - struct os_time now; - os_get_time(&now); + struct os_reltime now; + os_get_reltime(&now); if (now.sec > wpa_s->global->p2p_go_wait_client.sec + P2P_MAX_INITIAL_CONN_WAIT_GO) { /* Wait for the first client has expired */ diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index cfac768..1e1ab92 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -228,7 +228,7 @@ int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s, wpa_supplicant_notify_scanning(wpa_s, 0); wpas_notify_scan_done(wpa_s, 0); } else { - os_get_time(&wpa_s->scan_trigger_time); + os_get_reltime(&wpa_s->scan_trigger_time); wpa_s->scan_runs++; wpa_s->normal_scans++; } @@ -875,7 +875,7 @@ scan: void wpa_supplicant_update_scan_int(struct wpa_supplicant *wpa_s, int sec) { - struct os_time remaining, new_int; + struct os_reltime remaining, new_int; int cancelled; cancelled = eloop_cancel_timeout_one(wpa_supplicant_scan, wpa_s, NULL, @@ -883,7 +883,7 @@ void wpa_supplicant_update_scan_int(struct wpa_supplicant *wpa_s, int sec) new_int.sec = sec; new_int.usec = 0; - if (cancelled && os_time_before(&remaining, &new_int)) { + if (cancelled && os_reltime_before(&remaining, &new_int)) { new_int.sec = remaining.sec; new_int.usec = remaining.usec; } @@ -1668,7 +1668,7 @@ wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s, * Make sure we have a valid timestamp if the driver wrapper * does not set this. */ - os_get_time(&scan_res->fetch_time); + os_get_reltime(&scan_res->fetch_time); } filter_scan_res(wpa_s, scan_res); diff --git a/wpa_supplicant/sme.c b/wpa_supplicant/sme.c index 87c14ae..3a96623 100644 --- a/wpa_supplicant/sme.c +++ b/wpa_supplicant/sme.c @@ -1151,9 +1151,9 @@ static const unsigned int sa_query_retry_timeout = 201; static int sme_check_sa_query_timeout(struct wpa_supplicant *wpa_s) { u32 tu; - struct os_time now, passed; - os_get_time(&now); - os_time_sub(&now, &wpa_s->sme.sa_query_start, &passed); + struct os_reltime now, passed; + os_get_reltime(&now); + os_reltime_sub(&now, &wpa_s->sme.sa_query_start, &passed); tu = (passed.sec * 1000000 + passed.usec) / 1024; if (sa_query_max_timeout < tu) { wpa_dbg(wpa_s, MSG_DEBUG, "SME: SA Query timed out"); @@ -1203,7 +1203,7 @@ static void sme_sa_query_timer(void *eloop_ctx, void *timeout_ctx) return; if (wpa_s->sme.sa_query_count == 0) { /* Starting a new SA Query procedure */ - os_get_time(&wpa_s->sme.sa_query_start); + os_get_reltime(&wpa_s->sme.sa_query_start); } trans_id = nbuf + wpa_s->sme.sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; wpa_s->sme.sa_query_trans_id = nbuf; diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 4388ad6..7aef80e 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -2276,7 +2276,7 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr, wpabuf_free(wpa_s->pending_eapol_rx); wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len); if (wpa_s->pending_eapol_rx) { - os_get_time(&wpa_s->pending_eapol_rx_time); + os_get_reltime(&wpa_s->pending_eapol_rx_time); os_memcpy(wpa_s->pending_eapol_rx_src, src_addr, ETH_ALEN); } @@ -3829,7 +3829,7 @@ void wpas_auth_failed(struct wpa_supplicant *wpa_s) { struct wpa_ssid *ssid = wpa_s->current_ssid; int dur; - struct os_time now; + struct os_reltime now; if (ssid == NULL) { wpa_printf(MSG_DEBUG, "Authentication failure but no known " @@ -3866,7 +3866,7 @@ void wpas_auth_failed(struct wpa_supplicant *wpa_s) else dur = 10; - os_get_time(&now); + os_get_reltime(&now); if (now.sec + dur <= ssid->disabled_until.sec) return; diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index eed1053..1815a2f 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -246,7 +246,7 @@ struct wpa_global { struct wpa_supplicant *p2p_group_formation; struct wpa_supplicant *p2p_invite_group; u8 p2p_dev_addr[ETH_ALEN]; - struct os_time p2p_go_wait_client; + struct os_reltime p2p_go_wait_client; struct dl_list p2p_srv_bonjour; /* struct p2p_srv_bonjour */ struct dl_list p2p_srv_upnp; /* struct p2p_srv_upnp */ int p2p_disabled; @@ -289,7 +289,7 @@ struct wps_ap_info { WPS_AP_SEL_REG_OUR } type; unsigned int tries; - struct os_time last_attempt; + struct os_reltime last_attempt; }; struct wpa_ssid_value { @@ -394,7 +394,7 @@ struct wpa_supplicant { unsigned int last_scan_res_used; unsigned int last_scan_res_size; int last_scan_full; - struct os_time last_scan; + struct os_reltime last_scan; struct wpa_driver_ops *driver; int interface_removed; /* whether the network interface has been @@ -464,7 +464,7 @@ struct wpa_supplicant { */ MANUAL_SCAN_REQ } scan_req; - struct os_time scan_trigger_time; + struct os_reltime scan_trigger_time; int scan_runs; /* number of scan runs since WPS was started */ int *next_scan_freqs; int scan_interval; /* time in sec between scans to find suitable AP */ @@ -502,7 +502,7 @@ struct wpa_supplicant { int blacklist_cleared; struct wpabuf *pending_eapol_rx; - struct os_time pending_eapol_rx_time; + struct os_reltime pending_eapol_rx_time; u8 pending_eapol_rx_src[ETH_ALEN]; unsigned int last_eapol_matches_bssid:1; @@ -536,7 +536,7 @@ struct wpa_supplicant { u8 *sa_query_trans_id; /* buffer of WLAN_SA_QUERY_TR_ID_LEN * * sa_query_count octets of pending * SA Query transaction identifiers */ - struct os_time sa_query_start; + struct os_reltime sa_query_start; u8 sched_obss_scan; u16 obss_scan_int; u16 bss_max_idle_period; @@ -647,7 +647,7 @@ struct wpa_supplicant { int p2p_persistent_id; int p2p_go_intent; int p2p_connect_freq; - struct os_time p2p_auto_started; + struct os_reltime p2p_auto_started; struct wpa_ssid *p2p_last_4way_hs_fail; #endif /* CONFIG_P2P */ diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index 4c40dac..abe19a6 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -2358,7 +2358,7 @@ extern int wpa_debug_level; static void wpas_wps_dump_ap_info(struct wpa_supplicant *wpa_s) { size_t i; - struct os_time now; + struct os_reltime now; if (wpa_debug_level > MSG_DEBUG) return; @@ -2366,7 +2366,7 @@ static void wpas_wps_dump_ap_info(struct wpa_supplicant *wpa_s) if (wpa_s->wps_ap == NULL) return; - os_get_time(&now); + os_get_reltime(&now); for (i = 0; i < wpa_s->num_wps_ap; i++) { struct wps_ap_info *ap = &wpa_s->wps_ap[i]; @@ -2479,5 +2479,5 @@ void wpas_wps_notify_assoc(struct wpa_supplicant *wpa_s, const u8 *bssid) if (ap == NULL) return; ap->tries++; - os_get_time(&ap->last_attempt); + os_get_reltime(&ap->last_attempt); }