[Aggregator] Handle AP IP address (from Hello)
This commit is contained in:
parent
fe0ea4bcdc
commit
074cd5a27a
|
@ -67,6 +67,7 @@ typedef struct _couple_list
|
||||||
typedef struct _ap_list
|
typedef struct _ap_list
|
||||||
{
|
{
|
||||||
unsigned char mac_addr_bytes[6] ;
|
unsigned char mac_addr_bytes[6] ;
|
||||||
|
char ip_addr[16] ;
|
||||||
|
|
||||||
struct timeval last_seen ;
|
struct timeval last_seen ;
|
||||||
|
|
||||||
|
@ -92,9 +93,10 @@ void print_couple_info(couple_info_list *info) ;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
void listen_for_aps(void) ;
|
void listen_for_aps(void) ;
|
||||||
void update_ap(unsigned char mac_addr_bytes[6]) ;
|
void update_ap(unsigned char mac_addr_bytes[6], char ip_addr[16]) ;
|
||||||
ap_list* find_ap(unsigned char mac_addr_bytes[6]) ;
|
ap_list* find_ap(unsigned char mac_addr_bytes[6]) ;
|
||||||
void add_ap_front(unsigned char mac_addr_bytes[6]) ;
|
ap_list* add_ap_front(unsigned char mac_addr_bytes[6]) ;
|
||||||
|
void update_ap_ip_addr(ap_list *ap, char ip_addr[16]) ;
|
||||||
void update_ap_seen(ap_list *ap) ;
|
void update_ap_seen(ap_list *ap) ;
|
||||||
void push_ap(ap_list *ap) ;
|
void push_ap(ap_list *ap) ;
|
||||||
|
|
||||||
|
|
|
@ -630,7 +630,6 @@ void listen_for_aps(void)
|
||||||
struct sockaddr_in client; // UDP client structure
|
struct sockaddr_in client; // UDP client structure
|
||||||
socklen_t client_len = sizeof(client) ; // Size of clients
|
socklen_t client_len = sizeof(client) ; // Size of clients
|
||||||
autocalibration_hello message ;
|
autocalibration_hello message ;
|
||||||
unsigned char ap_mac_addr_bytes[6] ;
|
|
||||||
|
|
||||||
listen_sockfd =
|
listen_sockfd =
|
||||||
create_udp_listening_socket(cfg_getint(cfg,
|
create_udp_listening_socket(cfg_getint(cfg,
|
||||||
|
@ -654,8 +653,7 @@ void listen_for_aps(void)
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&ap_mac_addr_bytes, message.ap_mac_addr_bytes, 6) ;
|
update_ap(message.ap_mac_addr_bytes, message.ap_ip_addr) ;
|
||||||
update_ap(ap_mac_addr_bytes) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) close(listen_sockfd) ;
|
(void) close(listen_sockfd) ;
|
||||||
|
@ -667,12 +665,15 @@ void listen_for_aps(void)
|
||||||
* Updates the timestamp of the AP with the given MAC address if it is in
|
* Updates the timestamp of the AP with the given MAC address if it is in
|
||||||
* the AP list, or add a new AP with this MAC address to the AP list.
|
* the AP list, or add a new AP with this MAC address to the AP list.
|
||||||
*/
|
*/
|
||||||
void update_ap(unsigned char mac_addr_bytes[6])
|
void update_ap(unsigned char mac_addr_bytes[6], char ip_addr[16])
|
||||||
{
|
{
|
||||||
ap_list *found ;
|
ap_list *found ;
|
||||||
|
|
||||||
if ((found = find_ap(mac_addr_bytes)) == NULL)
|
if ((found = find_ap(mac_addr_bytes)) == NULL)
|
||||||
add_ap_front(mac_addr_bytes) ;
|
{
|
||||||
|
ap_list *new_ap = add_ap_front(mac_addr_bytes) ;
|
||||||
|
update_ap_ip_addr(new_ap, ip_addr) ;
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
update_ap_seen(found) ;
|
update_ap_seen(found) ;
|
||||||
|
@ -699,13 +700,20 @@ ap_list* find_ap(unsigned char mac_addr_bytes[6])
|
||||||
|
|
||||||
|
|
||||||
/* Adds a new AP in front of the AP list. */
|
/* Adds a new AP in front of the AP list. */
|
||||||
inline void add_ap_front(unsigned char mac_addr_bytes[6])
|
inline ap_list* add_ap_front(unsigned char mac_addr_bytes[6])
|
||||||
{
|
{
|
||||||
ap_list *ap = malloc(sizeof(ap_list)) ;
|
ap_list *ap = malloc(sizeof(ap_list)) ;
|
||||||
memcpy(ap->mac_addr_bytes, mac_addr_bytes, 6) ;
|
memcpy(ap->mac_addr_bytes, mac_addr_bytes, 6) ;
|
||||||
update_ap_seen(ap) ;
|
update_ap_seen(ap) ;
|
||||||
push_ap(ap) ;
|
push_ap(ap) ;
|
||||||
++nb_aps ;
|
++nb_aps ;
|
||||||
|
return ap ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void update_ap_ip_addr(ap_list *ap, char ip_addr[16])
|
||||||
|
{
|
||||||
|
strncpy(ap->ip_addr, ip_addr, 16) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue