Track endianess issues
Add some comments, add/remove some endianess conversions. That should be OK now. Noticeable changes in owlps.h: - Type DIRECTION is now an alias for uint8_t instead of an enum. - Type autocalibration_order now contains an uint8_t instead of an enum.
This commit is contained in:
parent
795ac90614
commit
3782ca9012
3
TODO
3
TODO
|
@ -1,8 +1,5 @@
|
|||
* Global
|
||||
|
||||
- Fix endianess issues
|
||||
Check carefully the network exchanges to track every non-conversion
|
||||
of endianess.
|
||||
- Mark arguments as const in function headers if needed
|
||||
That is done in the owlps-positioning C++ code, but not constantly
|
||||
in C modules.
|
||||
|
|
|
@ -349,6 +349,10 @@ int read_loop(int sockfd)
|
|||
break ;
|
||||
}
|
||||
|
||||
// Endianess conversions:
|
||||
message.request_time = owl_ntoh_timestamp(message.request_time) ;
|
||||
message.start_time = owl_ntoh_timestamp(message.start_time) ;
|
||||
|
||||
if (cfg_getbool(cfg, "verbose"))
|
||||
{
|
||||
ap_mac_str =
|
||||
|
@ -503,12 +507,18 @@ void* monitor_couples()
|
|||
demande.request_time = couple_ptr->request_time ;
|
||||
demande.nb_couples = 0 ;
|
||||
|
||||
// Count the couples:
|
||||
couple_info_ptr = couple_ptr->info ;
|
||||
while (couple_info_ptr != NULL)
|
||||
{
|
||||
demande.nb_couples++;
|
||||
couple_info_ptr = couple_info_ptr->next ;
|
||||
}
|
||||
// Endianess conversions:
|
||||
demande.nb_couples = htons(demande.nb_couples) ;
|
||||
demande.request_time =
|
||||
owl_hton_timestamp(demande.request_time) ;
|
||||
// Send the request:
|
||||
sendto(sockfd, (void *)&demande, sizeof(request), 0,
|
||||
(struct sockaddr *)&serv, serv_len) ;
|
||||
|
||||
|
@ -1006,7 +1016,7 @@ void order_send(ap_list *ap)
|
|||
cfg_getint(cfg, "autocalibration_port"),
|
||||
&serv, &client) ;
|
||||
|
||||
message.order = htonl(AUTOCALIBRATION_ORDER_SEND) ;
|
||||
message.order = AUTOCALIBRATION_ORDER_SEND ;
|
||||
nsent = sendto(sockfd, (void *)&message, sizeof(message), 0,
|
||||
(struct sockaddr *)&serv, serv_len) ;
|
||||
if (nsent != (ssize_t) sizeof(message))
|
||||
|
|
|
@ -305,6 +305,8 @@ void make_packet()
|
|||
TIMESTAMP request_time ;
|
||||
char request_time_str[TIMESTAMP_STR_LEN] ;
|
||||
|
||||
// Get the current time and copy it as a string before to switch it to
|
||||
// network endianess:
|
||||
owl_timestamp_now(&request_time) ;
|
||||
owl_timestamp_to_string(request_time_str, request_time) ;
|
||||
request_time = owl_hton_timestamp(request_time) ;
|
||||
|
|
|
@ -618,6 +618,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
|
||||
if (GET_MODE() != MODE_PASSIVE) // If mode is active or mixed
|
||||
{
|
||||
uint_fast16_t dest_port ;
|
||||
|
||||
// Protocol for an explicit request is UDP
|
||||
if (packet_ip_header->protocol != IPPROTO_UDP)
|
||||
goto not_explicit_packet ;
|
||||
|
@ -626,12 +628,13 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
packet_udp_header = (struct udphdr *)
|
||||
&packet[rtap_bytes + ieee80211_header_size +
|
||||
LLC_HEADER_SIZE + sizeof(struct iphdr)] ;
|
||||
dest_port = ntohs(packet_udp_header->dest) ;
|
||||
|
||||
if (GET_AUTOCALIBRATION() && ntohs(packet_udp_header->dest) ==
|
||||
GET_AUTOCALIBRATION_REQUEST_PORT())
|
||||
if (GET_AUTOCALIBRATION() && dest_port ==
|
||||
(uint_fast16_t) GET_AUTOCALIBRATION_REQUEST_PORT())
|
||||
uses_autocalibration_request_port = TRUE ;
|
||||
|
||||
else if (ntohs(packet_udp_header->dest) != GET_LISTENING_PORT())
|
||||
else if (dest_port != (uint_fast16_t) GET_LISTENING_PORT())
|
||||
goto not_explicit_packet ;
|
||||
}
|
||||
|
||||
|
@ -660,7 +663,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
return ;
|
||||
|
||||
memcpy(couple.ap_mac_addr_bytes, my_mac_bytes, 6) ; // Copy AP MAC
|
||||
// Capture time is in the pcap header:
|
||||
// Capture time is in the pcap header (net-endian):
|
||||
couple.start_time = owl_timeval_to_timestamp(header->ts) ;
|
||||
// Transmission time on the mobile is unknown (unless the packet is
|
||||
// an explicit request):
|
||||
|
@ -734,6 +737,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
" an implicit one.\n") ;
|
||||
}
|
||||
else
|
||||
// Copy the timestamp "as is" (i.e. without changing endianess)
|
||||
// because it will return to the network soon:
|
||||
memcpy(&couple.request_time,
|
||||
&packet[rtap_bytes + ieee80211_header_size +
|
||||
LLC_HEADER_SIZE + sizeof(struct iphdr) +
|
||||
|
@ -851,8 +856,10 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
char
|
||||
request_time_str[TIMESTAMP_STR_LEN],
|
||||
start_time_str[TIMESTAMP_STR_LEN] ;
|
||||
owl_timestamp_to_string(request_time_str, couple.request_time) ;
|
||||
owl_timestamp_to_string(start_time_str, couple.start_time) ;
|
||||
owl_timestamp_to_string(request_time_str,
|
||||
owl_ntoh_timestamp(couple.request_time)) ;
|
||||
owl_timestamp_to_string(start_time_str,
|
||||
owl_ntoh_timestamp(couple.start_time)) ;
|
||||
printf("*** Couple to send ***\n"
|
||||
"\tMAC AP: %s\n"
|
||||
"\tMobile MAC: %s\n"
|
||||
|
@ -1019,7 +1026,7 @@ void autocalibrate()
|
|||
continue ;
|
||||
}
|
||||
|
||||
if (ntohl(message.order) == AUTOCALIBRATION_ORDER_SEND)
|
||||
if (message.order == AUTOCALIBRATION_ORDER_SEND)
|
||||
{
|
||||
if (GET_VERBOSE())
|
||||
fprintf(stderr, "I was just ordered to send an"
|
||||
|
@ -1072,6 +1079,8 @@ uint_fast16_t make_packet(uint8_t **packet)
|
|||
printf("Autocalibration time: %s\n", request_time_str) ;
|
||||
}
|
||||
|
||||
request_time = owl_hton_timestamp(request_time) ;
|
||||
|
||||
size = sizeof(char) + sizeof(TIMESTAMP) ;
|
||||
pkt = malloc(size) ;
|
||||
|
||||
|
|
|
@ -57,7 +57,8 @@ typedef enum {FALSE, TRUE} BOOL ;
|
|||
|
||||
|
||||
/* Direction type */
|
||||
typedef enum {NORTH = 1, EAST, SOUTH, WEST} DIRECTION ;
|
||||
enum {NORTH = 1, EAST, SOUTH, WEST} ;
|
||||
typedef uint8_t DIRECTION ;
|
||||
|
||||
|
||||
/* Timestamp type (struct timespec clone with fix-sized fields) */
|
||||
|
@ -96,7 +97,7 @@ typedef struct _request
|
|||
{
|
||||
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
|
||||
uint16_t nb_couples; // Number of (listener MAC;signal strength) couples
|
||||
} request;
|
||||
|
||||
/* Hello message sent by the listener to the aggregator */
|
||||
|
@ -106,9 +107,10 @@ typedef struct _autocalibration_hello
|
|||
} autocalibration_hello ;
|
||||
|
||||
/* Message sent to the listener to order an emission */
|
||||
#define AUTOCALIBRATION_ORDER_SEND 1
|
||||
typedef struct _autocalibration_order
|
||||
{
|
||||
enum {AUTOCALIBRATION_ORDER_SEND = 1} order ;
|
||||
uint8_t order ;
|
||||
} autocalibration_order ;
|
||||
|
||||
/* Positioning request types */
|
||||
|
|
Loading…
Reference in New Issue