Switch to stdint types where possible
The use of integer types from inttypes.h & stdint.h should help with portability issues. It will also force the data transmission between different architectures to work as intended (if we handle endianess conversions correctly!).
This commit is contained in:
parent
00c6cccfa2
commit
8123ee3096
1
TODO
1
TODO
|
@ -1 +0,0 @@
|
|||
Abandonner int, long & Cie pour les échanges de données, passer à stdint.h
|
|
@ -12,7 +12,8 @@
|
|||
* 'iface' if specified (if you want the interface to be selected,
|
||||
* automatically, this parameter should be NULL or an empty string).
|
||||
*/
|
||||
int owlps_create_socket_to_aggregator(char *dest_ip, int dest_port,
|
||||
int owlps_create_socket_to_aggregator(char *dest_ip,
|
||||
uint_fast16_t dest_port,
|
||||
struct sockaddr_in *server,
|
||||
char *iface)
|
||||
{
|
||||
|
@ -52,10 +53,10 @@ void owlps_use_iface(int sockfd, char *iface)
|
|||
|
||||
|
||||
void owlps_send_request(int sockfd, struct sockaddr_in *server,
|
||||
char *packet, int packet_size,
|
||||
short nb_pkt, long delay)
|
||||
void *packet, uint_fast16_t packet_size,
|
||||
uint_fast16_t nb_pkt, uint_fast32_t delay)
|
||||
{
|
||||
int i ;
|
||||
uint_fast16_t i ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Sent packets: ") ;
|
||||
|
@ -79,7 +80,7 @@ void owlps_send_request(int sockfd, struct sockaddr_in *server,
|
|||
|
||||
|
||||
void owlps_send_packet(int sockfd, struct sockaddr_in *server,
|
||||
void *packet, int packet_size)
|
||||
void *packet, uint_fast16_t packet_size)
|
||||
{
|
||||
ssize_t nsent = sendto(sockfd, packet, packet_size, 0,
|
||||
(struct sockaddr *) server,
|
||||
|
|
|
@ -14,15 +14,16 @@
|
|||
|
||||
|
||||
/* Function headers */
|
||||
int owlps_create_socket_to_aggregator(char *dest_ip, int dest_port,
|
||||
int owlps_create_socket_to_aggregator(char *dest_ip,
|
||||
uint_fast16_t dest_port,
|
||||
struct sockaddr_in *server,
|
||||
char *iface) ;
|
||||
void owlps_use_iface(int sockfd, char *iface) ;
|
||||
void owlps_send_request(int sockfd, struct sockaddr_in *server,
|
||||
char *packet, int packet_size,
|
||||
short nb_pkt, long delay) ;
|
||||
void *packet, uint_fast16_t packet_size,
|
||||
uint_fast16_t nb_pkt, uint_fast32_t delay) ;
|
||||
void owlps_send_packet(int sockfd, struct sockaddr_in *server,
|
||||
void *packet, int packet_size) ;
|
||||
void *packet, uint_fast16_t packet_size) ;
|
||||
|
||||
|
||||
#endif // _LIBOWLPS_CLIENT_
|
||||
|
|
|
@ -37,9 +37,9 @@
|
|||
typedef struct _couple_info_list
|
||||
{
|
||||
// MAC address of the data sender (in bytes):
|
||||
unsigned char ap_mac_addr_bytes[6] ;
|
||||
uint8_t ap_mac_addr_bytes[6] ;
|
||||
// Signal strength received by the AP from the mobile:
|
||||
unsigned char antenna_signal_dbm ;
|
||||
uint8_t antenna_signal_dbm ;
|
||||
struct _couple_info_list *next ;
|
||||
} couple_info_list ;
|
||||
|
||||
|
@ -48,7 +48,7 @@ typedef struct _couple_info_list
|
|||
typedef struct _couple_list
|
||||
{
|
||||
/* Numéro de séquence de la demande de localisation du mobile */
|
||||
unsigned char mobile_mac_addr_bytes[6] ; // Mobile MAC address (in bytes)
|
||||
uint8_t mobile_mac_addr_bytes[6] ; // Mobile MAC address (in bytes)
|
||||
TIMESTAMP request_time ; // Request time on the mobile
|
||||
|
||||
/* Calibration data */
|
||||
|
@ -69,7 +69,7 @@ typedef struct _couple_list
|
|||
/* Linked list of the known APs */
|
||||
typedef struct _ap_list
|
||||
{
|
||||
unsigned char mac_addr_bytes[6] ;
|
||||
uint8_t mac_addr_bytes[6] ;
|
||||
char ip_addr[16] ;
|
||||
|
||||
TIMESTAMP last_seen ;
|
||||
|
@ -96,9 +96,9 @@ void print_couple_info(couple_info_list *info) ;
|
|||
#endif // DEBUG
|
||||
|
||||
void listen_for_aps(void) ;
|
||||
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* add_ap_front(unsigned char mac_addr_bytes[6]) ;
|
||||
void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[16]) ;
|
||||
ap_list* find_ap(uint8_t mac_addr_bytes[6]) ;
|
||||
ap_list* add_ap_front(uint8_t mac_addr_bytes[6]) ;
|
||||
void update_ap_ip_addr(ap_list *ap, char ip_addr[16]) ;
|
||||
void update_ap_seen(ap_list *ap) ;
|
||||
void push_ap(ap_list *ap) ;
|
||||
|
@ -110,7 +110,7 @@ void unlink_ap(ap_list *ap) ;
|
|||
void order_send(ap_list *ap) ;
|
||||
void free_ap_list(void) ;
|
||||
|
||||
char* ip_bytes_to_string(unsigned char *ip_binary) ;
|
||||
char* ip_bytes_to_string(uint8_t ip_binary[4]) ;
|
||||
void print_usage(void) ;
|
||||
|
||||
#endif // _OWLPS_AGGREGATOR_H_
|
||||
|
|
|
@ -13,7 +13,7 @@ char *program_name = NULL ;
|
|||
cfg_t *cfg = NULL ; // Configuration structure
|
||||
couple_list *couples = NULL ; // Computed data list
|
||||
ap_list *token_aps = NULL ; // Token ring of the APs
|
||||
unsigned int nb_aps = 0 ; // Number of APs in the AP ring
|
||||
uint_fast16_t nb_aps = 0 ; // Number of APs in the AP ring
|
||||
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ int main(int argc, char **argv)
|
|||
monitor_thread, // Aggregated data monitoring thread
|
||||
monitor_aps_thread, // APs monitoring thread
|
||||
autocalibration_hello_thread ; // Hello messages reception thread
|
||||
unsigned int listening_port ;
|
||||
uint_fast16_t listening_port ;
|
||||
int sockfd ; // UDP listening socket
|
||||
|
||||
program_name = argv[0] ;
|
||||
|
@ -43,7 +43,8 @@ int main(int argc, char **argv)
|
|||
if ((sockfd = create_udp_listening_socket(listening_port)) < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Error! Cannot listen on port %u.\n", listening_port) ;
|
||||
"Error! Cannot listen on port %"PRIuFAST16".\n",
|
||||
listening_port) ;
|
||||
return ERR_CREATING_SOCKET ;
|
||||
}
|
||||
|
||||
|
@ -337,8 +338,8 @@ int read_loop(int sockfd)
|
|||
"\tAP MAC: %s\n"
|
||||
"\tMobile MAC: %s\n"
|
||||
"\tMobile IP: %s\n"
|
||||
"\tSequence number (request timestamp): %llu\n"
|
||||
"\tRequest arrival time on the AP: %llu\n"
|
||||
"\tSequence number (request timestamp): %"PRIu64"\n"
|
||||
"\tRequest arrival time on the AP: %"PRIu64"\n"
|
||||
"\tSignal: %d dBm\n"
|
||||
"\tPosition X: %f\n"
|
||||
"\tPosition Y: %f\n"
|
||||
|
@ -390,12 +391,11 @@ void* monitor_couples()
|
|||
TIMESTAMP current_time ;
|
||||
FILE *fd = NULL ;
|
||||
char *mac_string ;
|
||||
unsigned long sub ; // time_elapsed() result
|
||||
uint_fast32_t sub ; // time_elapsed() result
|
||||
|
||||
unsigned long aggregate_timeout =
|
||||
(unsigned long) cfg_getint(cfg, "aggregate_timeout") ;
|
||||
unsigned long keep_timeout =
|
||||
(unsigned long) cfg_getint(cfg, "keep_timeout") ;
|
||||
uint_fast32_t aggregate_timeout =
|
||||
cfg_getint(cfg, "aggregate_timeout") ;
|
||||
uint_fast32_t keep_timeout = cfg_getint(cfg, "keep_timeout") ;
|
||||
|
||||
struct sockaddr_in serv;
|
||||
struct sockaddr_in client ;
|
||||
|
@ -440,7 +440,8 @@ void* monitor_couples()
|
|||
{
|
||||
printf("* Timeout reached.") ;
|
||||
#ifdef DEBUG
|
||||
printf(" sub=%lu > aggregate_timeout=%ld\n",
|
||||
printf(" sub=%"PRIuFAST32" >"
|
||||
" aggregate_timeout=%"PRIuFAST32"\n",
|
||||
sub, aggregate_timeout) ;
|
||||
#else // DEBUG
|
||||
putchar('\n') ;
|
||||
|
@ -448,7 +449,7 @@ void* monitor_couples()
|
|||
|
||||
#ifdef USE_TIMESTAMP
|
||||
// Print request mobile timestamp to the output file
|
||||
fprintf(fd, "%llu;",
|
||||
fprintf(fd, "%"PRIu64";",
|
||||
timestamp_to_ms(couple_ptr->request_time)) ;
|
||||
#endif // USE_TIMESTAMP
|
||||
|
||||
|
@ -515,7 +516,8 @@ void* monitor_couples()
|
|||
|
||||
printf("* Keep timeout reached.") ;
|
||||
#ifdef DEBUG
|
||||
printf(" sub=%lu > keep_timeout=%ld\n",
|
||||
printf(" sub=%"PRIuFAST32" >"
|
||||
" keep_timeout=%"PRIuFAST32"\n",
|
||||
sub, keep_timeout) ;
|
||||
#else // DEBUG
|
||||
putchar('\n') ;
|
||||
|
@ -748,7 +750,7 @@ void listen_for_aps(void)
|
|||
* 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(unsigned char mac_addr_bytes[6], char ip_addr[16])
|
||||
void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[16])
|
||||
{
|
||||
ap_list *found ;
|
||||
|
||||
|
@ -767,7 +769,7 @@ void update_ap(unsigned char mac_addr_bytes[6], char ip_addr[16])
|
|||
* Searches the AP list for an AP with the given MAC address and returns
|
||||
* it.
|
||||
*/
|
||||
ap_list* find_ap(unsigned char mac_addr_bytes[6])
|
||||
ap_list* find_ap(uint8_t mac_addr_bytes[6])
|
||||
{
|
||||
ap_list *found ;
|
||||
|
||||
|
@ -790,7 +792,7 @@ ap_list* find_ap(unsigned char mac_addr_bytes[6])
|
|||
/*
|
||||
* Adds a new AP in front of the AP list.
|
||||
*/
|
||||
ap_list* add_ap_front(unsigned char mac_addr_bytes[6])
|
||||
ap_list* add_ap_front(uint8_t mac_addr_bytes[6])
|
||||
{
|
||||
#ifdef DEBUG
|
||||
char *mac = mac_bytes_to_string(mac_addr_bytes) ;
|
||||
|
@ -889,7 +891,7 @@ void delete_old_aps()
|
|||
|
||||
while (token_aps != NULL)
|
||||
if (time_elapsed(token_aps->last_seen, now) >
|
||||
(unsigned long) cfg_getint(cfg, "ap_keep_timeout") * 1000)
|
||||
(uint_fast32_t) cfg_getint(cfg, "ap_keep_timeout") * 1000)
|
||||
delete_ap(token_aps) ;
|
||||
else
|
||||
return ;
|
||||
|
@ -1027,8 +1029,8 @@ void print_couple_list()
|
|||
mobile_mac_string =
|
||||
mac_bytes_to_string(couple_ptr->mobile_mac_addr_bytes) ;
|
||||
printf("Mobile MAC: %s\n"
|
||||
"Sequence number: %llu\n"
|
||||
"Reception timestamp: %llu\n"
|
||||
"Sequence number: %"PRIu64"\n"
|
||||
"Reception timestamp: %"PRIu64"\n"
|
||||
"\n",
|
||||
mobile_mac_string,
|
||||
timestamp_to_ms(couple_ptr->request_time),
|
||||
|
@ -1073,9 +1075,9 @@ void print_couple_info(couple_info_list *info)
|
|||
|
||||
|
||||
|
||||
char* ip_bytes_to_string(unsigned char *ip_binary)
|
||||
char* ip_bytes_to_string(uint8_t ip_binary[4])
|
||||
{
|
||||
int
|
||||
int_fast8_t
|
||||
size = 16,
|
||||
i = 0 ;
|
||||
|
||||
|
@ -1089,7 +1091,7 @@ char* ip_bytes_to_string(unsigned char *ip_binary)
|
|||
|
||||
char *ret = malloc(sizeof(char) * size) ;
|
||||
|
||||
sprintf(ret, "%d.%d.%d.%d",
|
||||
sprintf(ret, "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8,
|
||||
ip_binary[0], ip_binary[1],
|
||||
ip_binary[2], ip_binary[3]) ;
|
||||
ret[size-1] = '\0' ;
|
||||
|
|
|
@ -40,11 +40,11 @@ void print_usage(void) ;
|
|||
/* Options */
|
||||
struct {
|
||||
char dest_ip[16] ; // Destination IP of the packets
|
||||
long dest_port ;
|
||||
uint_fast16_t dest_port ;
|
||||
char iface[IFNAMSIZ + 1] ; // Source network interface
|
||||
long delay ; // Time between two packet transmissions
|
||||
short nb_pkt ; // Number of packets to send
|
||||
long listening_port ;
|
||||
int_fast32_t delay ; // Time between two packet transmissions
|
||||
uint_fast16_t nb_pkt ; // Number of packets to send
|
||||
uint_fast16_t listening_port ;
|
||||
// Calibration data:
|
||||
DIRECTION direction ;
|
||||
float x ;
|
||||
|
@ -55,8 +55,8 @@ struct {
|
|||
LOC_REQUEST_DEFAULT_PORT,
|
||||
"",
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0, 0, 0, 0
|
||||
} ;
|
||||
|
||||
|
@ -68,8 +68,8 @@ BOOL is_calibration_request = FALSE ;
|
|||
|
||||
int sockfd ; // Sending socket descriptor
|
||||
struct sockaddr_in server ; // Server info
|
||||
char *packet = NULL ; // Packet to send
|
||||
int packet_size ; // Packet size
|
||||
uint8_t *packet = NULL ; // Packet to send
|
||||
uint_fast16_t packet_size ; // Packet size
|
||||
|
||||
|
||||
|
||||
|
@ -84,7 +84,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
(void) close(sockfd) ;
|
||||
|
||||
if (options.listening_port != -1)
|
||||
if (options.listening_port > 0)
|
||||
receive_position() ;
|
||||
|
||||
return 0 ;
|
||||
|
@ -228,13 +228,13 @@ void check_configuration()
|
|||
|
||||
// We want to send a calibration request AND to be located, which is
|
||||
// not allowed:
|
||||
if (is_calibration_request && options.listening_port != -1)
|
||||
if (is_calibration_request && options.listening_port > 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Warning! You cannot wait for a server answer when"
|
||||
" you calibrate. Option -l ignored…\n") ;
|
||||
#endif // DEBUG
|
||||
options.listening_port = -1 ;
|
||||
options.listening_port = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,11 +245,11 @@ void print_configuration()
|
|||
{
|
||||
fprintf(stderr, "Options:\n"
|
||||
"\tDestination IP: %s\n"
|
||||
"\tDestination port: %ld\n"
|
||||
"\tDestination port: %"PRIuFAST16"\n"
|
||||
"\tInterface: %s\n"
|
||||
"\tDelay: %ld\n"
|
||||
"\tNumber of packets: %d\n"
|
||||
"\tListening port: %ld\n"
|
||||
"\tDelay: %"PRIuFAST32"\n"
|
||||
"\tNumber of packets: %"PRIuFAST16"\n"
|
||||
"\tListening port: %"PRIuFAST16"\n"
|
||||
"\tDirection: %d\n"
|
||||
"\tX: %f\n"
|
||||
"\tY: %f\n"
|
||||
|
@ -283,14 +283,15 @@ void create_socket()
|
|||
/* Creates the packet to send. */
|
||||
void make_packet()
|
||||
{
|
||||
int offset ; // Index used to create the packet
|
||||
uint_fast16_t offset ; // Index used to create the packet
|
||||
TIMESTAMP request_time ;
|
||||
|
||||
timestamp_now(&request_time) ;
|
||||
|
||||
if (is_calibration_request) // Calibration packet
|
||||
{
|
||||
printf("Calibration time: %llu\n", timestamp_to_ms(request_time)) ;
|
||||
printf("Calibration time: %"PRIu64"\n",
|
||||
timestamp_to_ms(request_time)) ;
|
||||
|
||||
offset = 0 ;
|
||||
packet_size =
|
||||
|
@ -314,7 +315,8 @@ void make_packet()
|
|||
|
||||
else // Standard packet
|
||||
{
|
||||
printf("Request time: %llu\n", timestamp_to_ms(request_time)) ;
|
||||
printf("Request time: %"PRIu64"\n",
|
||||
timestamp_to_ms(request_time)) ;
|
||||
packet_size = sizeof(char) + sizeof(TIMESTAMP) ;
|
||||
packet = malloc(packet_size) ;
|
||||
packet[0] = PACKET_TYPE_NORMAL ; // Packet type
|
||||
|
|
|
@ -86,14 +86,14 @@ void keep_mode_monitor(char *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, unsigned char mac_bytes[6]) ;
|
||||
void get_mac_addr(char *eth, uint8_t mac_bytes[6]) ;
|
||||
void get_ip_addr(char *eth, char *ip_bytes) ;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
void autocalibrate(void) ;
|
||||
void autocalibrate_hello(void) ;
|
||||
void send_autocalibration_request(void) ;
|
||||
int make_packet(char **packet) ;
|
||||
uint_fast16_t make_packet(uint8_t **packet) ;
|
||||
#endif // USE_PTHREAD
|
||||
|
||||
void print_usage(void) ;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
char *program_name = NULL ;
|
||||
unsigned char my_mac[6] ; // AP MAC address
|
||||
uint8_t my_mac[6] ; // AP MAC address
|
||||
char my_ip[16] ; // AP IP address
|
||||
|
||||
int aggregation_sockfd ;
|
||||
|
@ -26,8 +26,8 @@ cfg_t *cfg ; // Configuration structure
|
|||
struct {
|
||||
char mode ;
|
||||
char aggregation_ip[16] ;
|
||||
long aggregation_port ;
|
||||
long listening_port ;
|
||||
uint_fast16_t aggregation_port ;
|
||||
uint_fast16_t listening_port ;
|
||||
#ifdef USE_PTHREAD
|
||||
BOOL keep_monitor ;
|
||||
#endif // USE_PTHREAD
|
||||
|
@ -36,11 +36,11 @@ struct {
|
|||
#ifdef USE_PTHREAD
|
||||
BOOL autocalibration ;
|
||||
char autocalibration_ip[16] ;
|
||||
long autocalibration_request_port ;
|
||||
long autocalibration_port ;
|
||||
long autocalibration_hello_delay ;
|
||||
long autocalibration_delay ;
|
||||
int autocalibration_nb_packets ;
|
||||
uint_fast16_t autocalibration_request_port ;
|
||||
uint_fast16_t autocalibration_port ;
|
||||
uint_fast32_t autocalibration_hello_delay ;
|
||||
uint_fast32_t autocalibration_delay ;
|
||||
uint_fast16_t autocalibration_nb_packets ;
|
||||
#endif // USE_PTHREAD
|
||||
BOOL verbose ;
|
||||
BOOL display_captured ;
|
||||
|
@ -411,19 +411,19 @@ void print_configuration()
|
|||
fprintf(stderr,
|
||||
"mode = %c\n"
|
||||
"aggregation_ip = \"%s\"\n"
|
||||
"aggregation_port = %ld\n"
|
||||
"listening_port = %ld\n"
|
||||
"aggregation_port = %"PRIuFAST16"\n"
|
||||
"listening_port = %"PRIuFAST16"\n"
|
||||
"rtap_iface = \"%s\"\n"
|
||||
"wifi_iface = \"%s\"\n"
|
||||
#ifdef USE_PTHREAD
|
||||
"keep_monitor = %s\n"
|
||||
"autocalibration = %s\n"
|
||||
"autocalibration_ip = %s\n"
|
||||
"autocalibration_request_port = %ld\n"
|
||||
"autocalibration_port = %ld\n"
|
||||
"autocalibration_hello_delay = %ld\n"
|
||||
"autocalibration_delay = %ld\n"
|
||||
"autocalibration_nb_packets = %d\n"
|
||||
"autocalibration_request_port = %"PRIuFAST16"\n"
|
||||
"autocalibration_port = %"PRIuFAST16"\n"
|
||||
"autocalibration_hello_delay = %"PRIuFAST32"\n"
|
||||
"autocalibration_delay = %"PRIuFAST32"\n"
|
||||
"autocalibration_nb_packets = %"PRIuFAST16"\n"
|
||||
#endif // USE_PTHREAD
|
||||
"verbose = %s\n"
|
||||
"display_captured = %s\n"
|
||||
|
@ -515,26 +515,25 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
const u_char *packet)
|
||||
{
|
||||
// Copy packet address into data:
|
||||
unsigned char *data = (unsigned char *) packet ;
|
||||
unsigned short rtap_bytes ; // Received data size
|
||||
unsigned int
|
||||
rtap_presentflags,
|
||||
rtap_position ;
|
||||
const u_char *data = packet ;
|
||||
uint16_t rtap_bytes ; // Received data size
|
||||
uint32_t rtap_presentflags ;
|
||||
uint_fast16_t rtap_position ;
|
||||
couple_message couple ; // Message to send to the aggregator
|
||||
ssize_t nsent ; // sendto return value
|
||||
BOOL check[15] ; // Present flags
|
||||
unsigned char raw_packet_fc1 ; // First byte of the received frame's FC
|
||||
unsigned char raw_packet_fc2 ; // Second byte of the received frame's FC
|
||||
unsigned char raw_packet_flags ; // IEEE 802.11 header flags
|
||||
uint8_t raw_packet_fc1 ; // First byte of the received frame's FC
|
||||
uint8_t raw_packet_fc2 ; // Second byte of the received frame's FC
|
||||
uint8_t raw_packet_flags ; // IEEE 802.11 header flags
|
||||
// Size of the IEEE 802.11 header:
|
||||
int ieee80211_header_size = IEEE80211_HEADER_SIZE_DATA ;
|
||||
unsigned short llc_packet_type = 0 ;
|
||||
uint_fast8_t ieee80211_header_size = IEEE80211_HEADER_SIZE_DATA ;
|
||||
uint16_t llc_packet_type = 0 ;
|
||||
// Pointer to the (possible) IP header of the packet:
|
||||
struct iphdr *packet_ip_header = NULL ;
|
||||
// Pointer to the (possible) UDP header of the packet:
|
||||
struct udphdr *packet_udp_header = NULL ;
|
||||
// Localisation request type (request, calibration, autocalibration):
|
||||
unsigned char packet_type ;
|
||||
uint8_t packet_type ;
|
||||
BOOL is_explicit_packet = TRUE ; // Is the packet an explicit request?
|
||||
// Is the packet an autocalibration positioning request?
|
||||
BOOL uses_autocalibration_request_port = FALSE ;
|
||||
|
@ -546,7 +545,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
|
||||
// Copy 2 bytes from the 3rd data byte, that is the size of the rtap
|
||||
// header (changes with the flags):
|
||||
memcpy(&rtap_bytes, &data[2], sizeof(unsigned short)) ;
|
||||
memcpy(&rtap_bytes, &data[2], sizeof(rtap_bytes)) ;
|
||||
// Radiotap header is little-endian
|
||||
rtap_bytes = le16toh(rtap_bytes) ;
|
||||
|
||||
|
@ -573,7 +572,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
goto not_explicit_packet ;
|
||||
|
||||
// Get the packet type (protocol, 2 bytes) from the LLC header:
|
||||
memcpy((unsigned char*) &llc_packet_type,
|
||||
memcpy(&llc_packet_type,
|
||||
&data[rtap_bytes + ieee80211_header_size + 6], 2) ;
|
||||
llc_packet_type = ntohs(llc_packet_type) ;
|
||||
|
||||
|
@ -819,8 +818,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
printf("*** Couple to send ***\n"
|
||||
"\tMAC AP: %s\n"
|
||||
"\tMobile MAC: %s\n"
|
||||
"\tSequence number (request time): %llu\n"
|
||||
"\tRequest arrival time on the AP: %llu\n"
|
||||
"\tSequence number (request time): %"PRIu64"\n"
|
||||
"\tRequest arrival time on the AP: %"PRIu64"\n"
|
||||
"\tSignal: %d dBm\n"
|
||||
"\tPosition X: %f\n"
|
||||
"\tPosition Y: %f\n"
|
||||
|
@ -858,12 +857,12 @@ 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, unsigned char mac_bytes[6])
|
||||
void get_mac_addr(char *eth, uint8_t mac_bytes[6])
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int sockfd ;
|
||||
|
||||
memset(mac_bytes, 0, sizeof(unsigned char) * 6) ; // Empty mac_bytes
|
||||
memset(mac_bytes, 0, sizeof(uint8_t) * 6) ; // Empty mac_bytes
|
||||
|
||||
sockfd = socket(AF_INET, SOCK_DGRAM, 0) ;
|
||||
if(sockfd < 0)
|
||||
|
@ -1000,8 +999,8 @@ void autocalibrate()
|
|||
|
||||
void send_autocalibration_request()
|
||||
{
|
||||
char *packet ;
|
||||
int packet_size = make_packet(&packet) ;
|
||||
uint8_t *packet ;
|
||||
uint_fast16_t packet_size = make_packet(&packet) ;
|
||||
|
||||
owlps_send_request(autocalibration_send_sockfd,
|
||||
&autocalibration_send_server,
|
||||
|
@ -1019,22 +1018,22 @@ void send_autocalibration_request()
|
|||
* The packet must be freed by the calling function.
|
||||
* Returns the size of the packet.
|
||||
*/
|
||||
int make_packet(char **packet)
|
||||
uint_fast16_t make_packet(uint8_t **packet)
|
||||
{
|
||||
char *pkt ;
|
||||
int size ; // Packet size
|
||||
uint8_t *pkt ;
|
||||
uint_fast16_t size ; // Packet size
|
||||
TIMESTAMP request_time ;
|
||||
|
||||
timestamp_now(&request_time) ;
|
||||
|
||||
if (GET_VERBOSE())
|
||||
printf("Autocalibration time: %llu\n",
|
||||
printf("Autocalibration time: %"PRIu64"\n",
|
||||
timestamp_to_ms(request_time)) ;
|
||||
|
||||
size = sizeof(char) + sizeof(TIMESTAMP) ;
|
||||
pkt = malloc(size) ;
|
||||
|
||||
pkt[0] = PACKET_TYPE_AUTOCALIBRATION ; // Packet type
|
||||
memset(&pkt[0], PACKET_TYPE_AUTOCALIBRATION, 1) ; // Packet type
|
||||
memcpy(&pkt[1], &request_time, sizeof(request_time)) ;
|
||||
|
||||
*packet = pkt ;
|
||||
|
|
|
@ -17,7 +17,7 @@ BOOL run = TRUE ;
|
|||
* Converts a MAC address from bytes to string.
|
||||
* /!\ You *must* manually free the returned string /!\
|
||||
*/
|
||||
char* mac_bytes_to_string(unsigned char *mac_binary)
|
||||
char* mac_bytes_to_string(uint8_t *mac_binary)
|
||||
{
|
||||
char *ret = malloc(sizeof(char) * 18) ;
|
||||
|
||||
|
@ -35,9 +35,9 @@ char* mac_bytes_to_string(unsigned char *mac_binary)
|
|||
* Converts a IEEE 802.11 frequency into a channel number.
|
||||
* Returns 0 if the frequency does not correspond to an official channel.
|
||||
*/
|
||||
char frequency_to_channel(unsigned short channel)
|
||||
uint_fast8_t frequency_to_channel(uint_fast16_t channel)
|
||||
{
|
||||
char c = 0 ; // Result
|
||||
uint_fast8_t c = 0 ; // Result
|
||||
|
||||
switch (channel)
|
||||
{
|
||||
|
@ -142,7 +142,7 @@ TIMESTAMP timeval_to_timestamp(const struct timeval d)
|
|||
/*
|
||||
* Converts a TIMESTAMP date value into milliseconds.
|
||||
*/
|
||||
unsigned long long timestamp_to_ms(TIMESTAMP d)
|
||||
uint64_t timestamp_to_ms(TIMESTAMP d)
|
||||
{
|
||||
return d.tv_sec * 1000 + d.tv_nsec / 1000000 ;
|
||||
}
|
||||
|
@ -152,11 +152,11 @@ unsigned long long timestamp_to_ms(TIMESTAMP d)
|
|||
/*
|
||||
* Returns the time (in milliseconds) between two dates.
|
||||
*/
|
||||
unsigned long time_elapsed(TIMESTAMP sup, TIMESTAMP inf)
|
||||
uint_fast32_t time_elapsed(TIMESTAMP sup, TIMESTAMP inf)
|
||||
{
|
||||
unsigned long sub = abs(timestamp_to_ms(sup) - timestamp_to_ms(inf)) ;
|
||||
uint_fast32_t sub = abs(timestamp_to_ms(sup) - timestamp_to_ms(inf)) ;
|
||||
#ifdef DEBUG
|
||||
printf("time_elapsed(): %lu\n", sub) ;
|
||||
printf("time_elapsed(): %"PRIuFAST32"\n", sub) ;
|
||||
#endif
|
||||
return sub ;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ unsigned long time_elapsed(TIMESTAMP sup, TIMESTAMP inf)
|
|||
* Compares two MAC addresses.
|
||||
* Returns TRUE if they are identical, FALSE otherwise.
|
||||
*/
|
||||
BOOL mac_equals(unsigned char *mac1, unsigned char *mac2)
|
||||
BOOL mac_equals(uint8_t *mac1, uint8_t *mac2)
|
||||
{
|
||||
int i ;
|
||||
for(i=0 ; i < 6 ; i++)
|
||||
|
@ -188,7 +188,8 @@ BOOL mac_equals(unsigned char *mac1, unsigned char *mac2)
|
|||
* - client_description (in/out): the structure in which the client
|
||||
* description will be saved.
|
||||
*/
|
||||
int create_udp_sending_socket(char *server_address, int server_port,
|
||||
int create_udp_sending_socket(char *server_address,
|
||||
uint_fast16_t server_port,
|
||||
struct sockaddr_in *server_description,
|
||||
struct sockaddr_in * client_description)
|
||||
{
|
||||
|
@ -225,7 +226,7 @@ int create_udp_sending_socket(char *server_address, int server_port,
|
|||
* Parameters:
|
||||
* - port: port on which the socket listens.
|
||||
*/
|
||||
int create_udp_listening_socket(int port)
|
||||
int create_udp_listening_socket(uint_fast16_t port)
|
||||
{
|
||||
int sockfd ; // Socket descriptor
|
||||
struct sockaddr_in server_description ; // Server structure
|
||||
|
@ -299,7 +300,7 @@ int iface_mode_monitor(char *iface)
|
|||
* Sets the IEEE 802.11 channel of the interface 'iface'.
|
||||
* 'channel' must be an integer between 1 and 14.
|
||||
*/
|
||||
int iface_set_channel(char *iface, int channel)
|
||||
int iface_set_channel(char *iface, uint_fast8_t channel)
|
||||
{
|
||||
struct iwreq wrq ;
|
||||
int sockfd = iw_sockets_open() ;
|
||||
|
@ -327,7 +328,7 @@ int iface_set_channel(char *iface, int channel)
|
|||
*/
|
||||
int iface_channel_hop(char *iface)
|
||||
{
|
||||
unsigned short channel ;
|
||||
uint_fast16_t channel ;
|
||||
struct iwreq wrq ;
|
||||
int sockfd = iw_sockets_open() ;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
|
@ -66,12 +67,12 @@ typedef struct timespec TIMESTAMP ;
|
|||
/* Message sent by the listener to the aggregator */
|
||||
typedef struct _couple_message
|
||||
{
|
||||
unsigned char ap_mac_addr_bytes[6] ; // MAC of the listener
|
||||
unsigned char mobile_mac_addr_bytes[6] ; // MAC of the mobile involved
|
||||
unsigned char mobile_ip_addr_bytes[4] ; // IP of the mobile
|
||||
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 mobile_ip_addr_bytes[4] ; // IP of the mobile
|
||||
TIMESTAMP request_time ; // Request ID (timestamp on the mobile)
|
||||
TIMESTAMP start_time ; // Timestamp of arrival on the listener
|
||||
unsigned char antenna_signal_dbm ; // Signal strength measured by the listener
|
||||
uint8_t antenna_signal_dbm ; // Signal strength measured by the listener
|
||||
/* Calibration data */
|
||||
float x_position ;
|
||||
float y_position ;
|
||||
|
@ -81,13 +82,13 @@ typedef struct _couple_message
|
|||
|
||||
typedef struct _couple_info
|
||||
{
|
||||
unsigned char ap_mac_addr_bytes[6] ; // MAC of the listener
|
||||
unsigned char antenna_signal_dbm ; // Signal strength measured by the listener
|
||||
uint8_t ap_mac_addr_bytes[6] ; // MAC of the listener
|
||||
uint8_t antenna_signal_dbm ; // Signal strength measured by the listener
|
||||
} couple_info ;
|
||||
|
||||
typedef struct _request
|
||||
{
|
||||
unsigned char mobile_mac_addr_bytes[6]; // MAC of the mobile
|
||||
uint8_t mobile_mac_addr_bytes[6]; // MAC of the mobile
|
||||
TIMESTAMP request_time ; // Request ID (timestamp on the mobile)
|
||||
int nb_couples; // Number of (listener MAC;signal strength) couples
|
||||
} request;
|
||||
|
@ -95,7 +96,7 @@ typedef struct _request
|
|||
/* Hello message sent by the listener to the aggregator */
|
||||
typedef struct _autocalibration_hello
|
||||
{
|
||||
unsigned char ap_mac_addr_bytes[6];
|
||||
uint8_t ap_mac_addr_bytes[6];
|
||||
} autocalibration_hello ;
|
||||
|
||||
/* Message sent to the listener to order an emission */
|
||||
|
@ -217,25 +218,26 @@ BOOL run ;
|
|||
|
||||
/* Function headers */
|
||||
// Misc
|
||||
char* mac_bytes_to_string(unsigned char *mac_binary) ;
|
||||
BOOL mac_equals(unsigned char *mac1, unsigned char *mac2) ;
|
||||
char frequency_to_channel(unsigned short channel) ;
|
||||
char* mac_bytes_to_string(uint8_t *mac_binary) ;
|
||||
BOOL mac_equals(uint8_t *mac1, uint8_t *mac2) ;
|
||||
uint_fast8_t frequency_to_channel(uint_fast16_t channel) ;
|
||||
|
||||
// Time
|
||||
void timestamp_now(TIMESTAMP *now) ;
|
||||
BOOL timestamp_now_ns(TIMESTAMP *now) ;
|
||||
void timestamp_round_to_ms(TIMESTAMP *now) ;
|
||||
TIMESTAMP timeval_to_timestamp(const struct timeval d) ;
|
||||
unsigned long long timestamp_to_ms(TIMESTAMP date) ;
|
||||
unsigned long time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
||||
uint64_t timestamp_to_ms(TIMESTAMP date) ;
|
||||
uint_fast32_t time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
||||
|
||||
// Network
|
||||
int create_udp_sending_socket(char *server_address, int server_port,
|
||||
int create_udp_sending_socket(char *server_address,
|
||||
uint_fast16_t server_port,
|
||||
struct sockaddr_in *server_description,
|
||||
struct sockaddr_in * client_description) ;
|
||||
int create_udp_listening_socket(int port) ;
|
||||
int create_udp_listening_socket(uint_fast16_t port) ;
|
||||
int iface_mode_monitor(char *iface) ;
|
||||
int iface_set_channel(char *iface, int channel) ;
|
||||
int iface_set_channel(char *iface, uint_fast8_t channel) ;
|
||||
int iface_channel_hop(char *iface) ;
|
||||
|
||||
// Signals
|
||||
|
|
Loading…
Reference in New Issue