Use ETHER_ADDR_LEN instead of 6

This commit is contained in:
Matteo Cypriani 2011-03-24 23:42:42 +01:00
parent d867f97eda
commit e8aa0838f4
6 changed files with 38 additions and 29 deletions

View File

@ -229,7 +229,7 @@ owl_timestamp owl_ntoh_timestamp(owl_timestamp date)
owl_bool owl_mac_equals(uint8_t *mac1, uint8_t *mac2)
{
int i ;
for(i=0 ; i < 6 ; i++)
for (i = 0 ; i < ETHER_ADDR_LEN ; ++i)
if(mac1[i] != mac2[i])
return FALSE ;
return TRUE ;

View File

@ -78,8 +78,8 @@ typedef struct _owl_timestamp
/* Message sent by the listener to the aggregator */
typedef struct _owl_captured_request
{
uint8_t ap_mac_addr_bytes[6] ; // MAC of the listener
uint8_t mobile_mac_addr_bytes[6] ; // MAC of the mobile involved
uint8_t ap_mac_addr_bytes[ETHER_ADDR_LEN] ; // MAC of the listener
uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; // MAC of the mobile
uint8_t mobile_ip_addr_bytes[4] ; // IP of the mobile
owl_timestamp request_time ; // Request ID (timestamp on the mobile)
owl_timestamp start_time ; // Timestamp of arrival on the listener
@ -96,7 +96,7 @@ typedef struct _owl_captured_request
* the main data of a request */
typedef struct _owl_request
{
uint8_t mobile_mac_addr_bytes[6] ; // MAC of the mobile
uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; // MAC of the mobile
owl_timestamp request_time ; // Request ID (timestamp on the mobile)
uint16_t nb_info ; // Number of (listener MAC;signal strength) couples
} owl_request ;
@ -107,7 +107,7 @@ typedef struct _owl_request
* signal strength */
typedef struct _owl_request_info
{
uint8_t ap_mac_addr_bytes[6] ; // MAC of the listener
uint8_t ap_mac_addr_bytes[ETHER_ADDR_LEN] ; // MAC of the listener
uint8_t antenna_signal_dbm ; // Signal strength measured by the listener
} owl_request_info ;
@ -115,7 +115,7 @@ typedef struct _owl_request_info
/* Hello message sent by the listener to the aggregator */
typedef struct _owl_autocalibration_hello
{
uint8_t ap_mac_addr_bytes[6] ;
uint8_t ap_mac_addr_bytes[ETHER_ADDR_LEN] ;
} owl_autocalibration_hello ;

View File

@ -39,7 +39,7 @@
typedef struct _request_info_list
{
// MAC address of the data sender (in bytes):
uint8_t ap_mac_addr_bytes[6] ;
uint8_t ap_mac_addr_bytes[ETHER_ADDR_LEN] ;
// Signal strength received by the AP from the mobile:
uint8_t antenna_signal_dbm ;
struct _request_info_list *next ;
@ -50,7 +50,8 @@ typedef struct _request_info_list
typedef struct _request_list
{
/* Request identifier */
uint8_t mobile_mac_addr_bytes[6] ; // Mobile MAC address (in bytes)
// Mobile MAC address (in bytes):
uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ;
owl_timestamp request_time ; // Request time on the mobile
/* Calibration data */
@ -71,7 +72,7 @@ typedef struct _request_list
/* Linked list of the known APs */
typedef struct _ap_list
{
uint8_t mac_addr_bytes[6] ;
uint8_t mac_addr_bytes[ETHER_ADDR_LEN] ;
char ip_addr[INET_ADDRSTRLEN] ;
owl_timestamp last_seen ;
@ -98,9 +99,10 @@ void print_request_info(request_info_list *info) ;
#endif // DEBUG
void* listen_for_aps(void *NULL_value) ;
void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[INET_ADDRSTRLEN]) ;
ap_list* find_ap(uint8_t mac_addr_bytes[6]) ;
ap_list* add_ap_front(uint8_t mac_addr_bytes[6]) ;
void update_ap(uint8_t mac_addr_bytes[ETHER_ADDR_LEN],
char ip_addr[INET_ADDRSTRLEN]) ;
ap_list* find_ap(uint8_t mac_addr_bytes[ETHER_ADDR_LEN]) ;
ap_list* add_ap_front(uint8_t mac_addr_bytes[ETHER_ADDR_LEN]) ;
void update_ap_ip_addr(ap_list *ap, char ip_addr[INET_ADDRSTRLEN]) ;
void update_ap_seen(ap_list *ap) ;
void push_ap(ap_list *ap) ;

View File

@ -567,7 +567,8 @@ void* monitor_requests(void *NULL_value)
request_ptr->direction) ;
memcpy(request.mobile_mac_addr_bytes,
request_ptr->mobile_mac_addr_bytes, 6) ;
request_ptr->mobile_mac_addr_bytes,
ETHER_ADDR_LEN) ;
request.request_time = request_ptr->request_time ;
request.nb_info = 0 ;
@ -592,7 +593,8 @@ void* monitor_requests(void *NULL_value)
{
// Send AP info to the localisation server
memcpy(info.ap_mac_addr_bytes,
request_info_ptr->ap_mac_addr_bytes, 6) ;
request_info_ptr->ap_mac_addr_bytes,
ETHER_ADDR_LEN) ;
info.antenna_signal_dbm =
request_info_ptr->antenna_signal_dbm - 0x100 ;
sendto(sockfd, &info, sizeof(info),
@ -675,7 +677,8 @@ void got_request(owl_captured_request request)
/* Create a new request */
tmp_info = malloc(sizeof(request_info_list)) ;
memcpy(tmp_info->ap_mac_addr_bytes, request.ap_mac_addr_bytes, 6) ;
memcpy(tmp_info->ap_mac_addr_bytes, request.ap_mac_addr_bytes,
ETHER_ADDR_LEN) ;
tmp_info->antenna_signal_dbm = request.antenna_signal_dbm ;
tmp_info->next = NULL ;
@ -686,7 +689,7 @@ void got_request(owl_captured_request request)
fprintf(stderr, "Creating request list.\n") ;
tmp_request = malloc(sizeof(request_list)) ; // create it.
memcpy(tmp_request->mobile_mac_addr_bytes,
request.mobile_mac_addr_bytes, 6) ;
request.mobile_mac_addr_bytes, ETHER_ADDR_LEN) ;
// Explicit packet:
if (! owl_timestamp_is_null(request.request_time))
// Transmission time on the mobile:
@ -743,7 +746,7 @@ void got_request(owl_captured_request request)
fprintf(stderr, "Create new request.\n") ;
tmp_request = malloc(sizeof(request_list)) ; // create it
memcpy(tmp_request->mobile_mac_addr_bytes,
request.mobile_mac_addr_bytes, 6) ;
request.mobile_mac_addr_bytes, ETHER_ADDR_LEN) ;
// Explicit packet:
if (! owl_timestamp_is_null(request.request_time))
// Transmission time on the mobile:
@ -867,7 +870,8 @@ void* listen_for_aps(void *NULL_value)
* 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.
*/
void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[INET_ADDRSTRLEN])
void update_ap(uint8_t mac_addr_bytes[ETHER_ADDR_LEN],
char ip_addr[INET_ADDRSTRLEN])
{
ap_list *found ;
@ -886,7 +890,7 @@ void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[INET_ADDRSTRLEN])
* Searches the AP list for an AP with the given MAC address and returns
* it.
*/
ap_list* find_ap(uint8_t mac_addr_bytes[6])
ap_list* find_ap(uint8_t mac_addr_bytes[ETHER_ADDR_LEN])
{
ap_list *found ;
@ -909,7 +913,7 @@ ap_list* find_ap(uint8_t mac_addr_bytes[6])
/*
* Adds a new AP in front of the AP list.
*/
ap_list* add_ap_front(uint8_t mac_addr_bytes[6])
ap_list* add_ap_front(uint8_t mac_addr_bytes[ETHER_ADDR_LEN])
{
#ifdef DEBUG
char *mac_str = owl_mac_bytes_to_string(mac_addr_bytes) ;
@ -918,7 +922,7 @@ ap_list* add_ap_front(uint8_t mac_addr_bytes[6])
#endif // DEBUG
ap_list *ap = malloc(sizeof(ap_list)) ;
memcpy(ap->mac_addr_bytes, mac_addr_bytes, 6) ;
memcpy(ap->mac_addr_bytes, mac_addr_bytes, ETHER_ADDR_LEN) ;
update_ap_seen(ap) ;
push_ap(ap) ;
return ap ;

View File

@ -87,7 +87,7 @@ void* keep_mode_monitor(void *iface) ;
int capture(void) ;
void read_packet(u_char *args, const struct pcap_pkthdr *header,
const u_char *packet) ;
void get_mac_addr(char *eth, uint8_t mac_bytes[6]) ;
void get_mac_addr(char *eth, uint8_t mac_bytes[ETHER_ADDR_LEN]) ;
void get_ip_addr(char *eth, char *ip_bytes) ;
#ifdef USE_PTHREAD

View File

@ -8,7 +8,7 @@
char *program_name = NULL ;
uint8_t my_mac_bytes[6] ; // AP MAC address
uint8_t my_mac_bytes[ETHER_ADDR_LEN] ; // AP MAC address
char my_ip[INET_ADDRSTRLEN] ; // AP IP address
pcap_t *capture_handler = NULL ; // Packet capture descriptor
@ -729,13 +729,15 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
#endif // DEBUG
// Source MAC address is 10 bytes after the 802.11 packet type:
memcpy(request.mobile_mac_addr_bytes, &packet[rtap_bytes+10], 6) ;
memcpy(request.mobile_mac_addr_bytes, &packet[rtap_bytes+10],
ETHER_ADDR_LEN) ;
// Drop the packet if it comes from the AP itself:
if (owl_mac_equals(my_mac_bytes, request.mobile_mac_addr_bytes))
return ;
memcpy(request.ap_mac_addr_bytes, my_mac_bytes, 6) ; // Copy AP MAC
// Copy AP MAC :
memcpy(request.ap_mac_addr_bytes, my_mac_bytes, ETHER_ADDR_LEN) ;
// Capture time is in the pcap header (net-endian):
request.start_time = owl_timeval_to_timestamp(header->ts) ;
// Transmission time on the mobile is unknown (unless the packet is
@ -975,12 +977,13 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
/*
* Get our own MAC address and copy it to 'mac_bytes'.
*/
void get_mac_addr(char *eth, uint8_t mac_bytes[6])
void get_mac_addr(char *eth, uint8_t mac_bytes[ETHER_ADDR_LEN])
{
struct ifreq ifr;
int sockfd ;
memset(mac_bytes, 0, sizeof(uint8_t) * 6) ; // Empty mac_bytes
// Empty mac_bytes:
memset(mac_bytes, 0, sizeof(uint8_t) * ETHER_ADDR_LEN) ;
sockfd = socket(AF_INET, SOCK_DGRAM, 0) ;
if(sockfd < 0)
@ -994,7 +997,7 @@ void get_mac_addr(char *eth, uint8_t mac_bytes[6])
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0)
return ;
memcpy(mac_bytes, ifr.ifr_hwaddr.sa_data, 6) ;
memcpy(mac_bytes, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN) ;
}
@ -1046,7 +1049,7 @@ void* autocalibrate_hello(void *NULL_value)
&serv, NULL) ;
pthread_cleanup_push(&owl_close_fd, &send_sockfd) ;
memcpy(&message.ap_mac_addr_bytes, my_mac_bytes, 6) ;
memcpy(&message.ap_mac_addr_bytes, my_mac_bytes, ETHER_ADDR_LEN) ;
while (run)
{