diff --git a/infrastructure-centred/owlps-listener/owlps-listener.h b/infrastructure-centred/owlps-listener/owlps-listener.h index f859be6..dd920a9 100644 --- a/infrastructure-centred/owlps-listener/owlps-listener.h +++ b/infrastructure-centred/owlps-listener/owlps-listener.h @@ -26,7 +26,7 @@ // Pour la fonction get_mac_addr() : #include -#include +#include #include diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index 900a1f5..cab7635 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -314,11 +314,17 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *p BOOL check[15] ; // Champs présents unsigned char raw_packet_type ; // Type du packet reçu (beacon, data...) unsigned char raw_packet_flags ; // Flags de l'en-tête IEEE 802.11 + unsigned short llc_packet_type = 0 ; + struct iphdr *packet_ip_header = NULL ; // Pointeur sur l'éventuel en-tête IP du paquet + struct udphdr *packet_udp_header = NULL ; // Pointeur sur l'éventuel en-tête UDP du paquet char packet_type ; // Type de demande de localisation (demande, calibration) - unsigned short dst_port ; // Port destination du paquet capturé + BOOL is_explicit_packet = TRUE ; // Le paquet constitue-t-il une demande ? int i ; // Compteur + /* Traitements communs */ + + // TODO : traiter le boutisme avec ntohs memcpy(&rtap_bytes, &data[2], sizeof(unsigned short)) ; // Recopie les deux octets à partir du troisième octet de donnée qui est la taille de l'en-tête rtap (change avec des flags) #ifdef PLATFORM_ATHEROS rtap_bytes = ((rtap_bytes & 0xff00) >> 8) + ((rtap_bytes & 0xff) << 8) ; @@ -326,24 +332,51 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *p raw_packet_type = data[rtap_bytes] ; // Au bout de l'en-tête rtap il y a celle du 802.11 dont le premier determine le type (beacon ou pas) -#ifdef PLATFORM_ATHEROS - memcpy((unsigned char*) &dst_port, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + 2], 2) ; // On récupère le port de destination -#else // PLATFORM_ATHEROS - memcpy((unsigned char*) &dst_port, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + 3], 1) ; // On récupère le port de destination (mais il faut retourner les deux octets) - memcpy(&((unsigned char*) &dst_port)[1], &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + 2], 1) ; // Port de destination = troisième et quatrième octets suivant l'en-tête IP. -#endif // PLATFORM_ATHEROS + if (raw_packet_type == RAW_PACKET_TYPE_DATA) // Si le paquet est de type data, + { // on récupère le type de paquet (protocole, sur 2 octets) dans l'en-tête LLC : + memcpy((unsigned char*) &llc_packet_type, &data[rtap_bytes + IEEE80211_HEADER_SIZE + 6], 2) ; + llc_packet_type = ntohs(llc_packet_type) ; + + if (llc_packet_type == ETH_P_IP) // Si c'est un paquet IP on récupère l'IP source + { + packet_ip_header = (struct iphdr *) &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE] ; + memcpy(couple.mobile_ip_addr_bytes, &packet_ip_header->saddr, 4) ; + + if (GET_MODE() != MODE_PASSIVE) // Si on est en mode actif ou mixte + { + if (packet_ip_header->protocol == IPPROTO_UDP) // Le protocole du paquet est UDP pour une demande explicite + { // On teste le port de destination : + packet_udp_header = (struct udphdr *) &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + sizeof(struct iphdr)] ; + if (ntohs(packet_udp_header->dest) != GET_LISTENING_PORT()) + { + if (GET_MODE() == MODE_ACTIVE) + return ; + is_explicit_packet = FALSE ; + } + } + } + } + else if (GET_MODE() != MODE_ACTIVE) // Mode passif ou mixte + { + is_explicit_packet = FALSE ; + bzero(couple.mobile_ip_addr_bytes, 4) ; // On positionne l'IP à zéro + } + else // On est en mode actif et le paquet n'est pas IP donc pas une demande + return ; + } + else + { // Le paquet n'est pas de la donnée donc pas une demande + if (GET_MODE() == MODE_ACTIVE) + return ; + is_explicit_packet = FALSE ; + } raw_packet_flags = data[rtap_bytes+1] ; // On récupère les flags 802.11, qui sont dans l'en-tête 802.11. #ifdef DEBUG - if (raw_packet_type == RAW_PACKET_TYPE_DATA - && data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + 9] == RAW_PACKET_PROTO_UDP - && dst_port == GET_LISTENING_PORT()) - { - printf("raw_packet_flags : %02x\n", raw_packet_flags) ; - if (IS_RETRY(raw_packet_flags)) - printf("Retry : pas à traiter\n") ; - } + printf("raw_packet_flags : %02x\n", raw_packet_flags) ; + if (IS_RETRY(raw_packet_flags)) + printf("Ce paquet est un Retry.\n") ; #endif // DEBUG memcpy(couple.ap_mac_addr_bytes, mac, 6); // On copie la MAC de l'AP @@ -351,20 +384,14 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *p couple.start_time = header->ts ; // L'heure de capture du paquet est contenue dans l'en-tête pcap couple.request_time.tv_sec = 0 ; // L'heure d'envoi par le mobile est inconnue (à moins qu'il ne s'agisse d'un paquet explicite) couple.request_time.tv_usec = 0 ; - // TODO : if (est un paquet IP) - memcpy(couple.mobile_ip_addr_bytes, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + 12], 4); // L'adresse IP source est à la position 12 de l'en-tête IP - // TODO : else mettre l'IP à zéro /* Mode actif */ - if ((GET_MODE() == MODE_ACTIVE || GET_MODE() == MODE_MIXED) - && raw_packet_type == RAW_PACKET_TYPE_DATA // Si le paquet est de type data, - && data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + 9] == RAW_PACKET_PROTO_UDP // et de protocole UDP (9 : position du champ "Protocol" de l'en-tête IP), - && dst_port == GET_LISTENING_PORT() // et le port de destination est le bon, + if (is_explicit_packet + && (GET_MODE() == MODE_ACTIVE || GET_MODE() == MODE_MIXED) + // FIXME : faut-il toujours ignorer les retry ? && ! IS_RETRY(raw_packet_flags)) // et ce n'est pas un Retry. { - BOOL err = FALSE ; - - packet_type = data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + UDP_HEADER_SIZE] ; + packet_type = data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + sizeof(struct iphdr) + sizeof(struct udphdr)] ; switch(packet_type) { case PACKET_TYPE_NORMAL : @@ -379,20 +406,20 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *p case PACKET_TYPE_CALIBRATION : if (GET_VERBOSE()) printf("\nPaquet explicite de calibration reçu.\n") ; - couple.direction = data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + UDP_HEADER_SIZE + 9]; - memcpy(&couple.x_position, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + UDP_HEADER_SIZE + 10], sizeof(float)); - memcpy(&couple.y_position, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + UDP_HEADER_SIZE + 14], sizeof(float)); - memcpy(&couple.z_position, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + UDP_HEADER_SIZE + 18], sizeof(float)); + couple.direction = data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + sizeof(struct iphdr) + sizeof(struct udphdr) + 9]; + memcpy(&couple.x_position, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + sizeof(struct iphdr) + sizeof(struct udphdr) + 10], sizeof(float)); + memcpy(&couple.y_position, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + sizeof(struct iphdr) + sizeof(struct udphdr) + 14], sizeof(float)); + memcpy(&couple.z_position, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + sizeof(struct iphdr) + sizeof(struct udphdr) + 18], sizeof(float)); break ; default : if (GET_VERBOSE()) printf("\nPaquet explicite bizarre reçu.\n") ; fprintf(stderr, "Erreur ! Type de paquet explicite inconnu (%d).\n", packet_type) ; - err = TRUE ; + is_explicit_packet = FALSE ; } - if (err) + if (! is_explicit_packet) { if (GET_MODE() == MODE_ACTIVE) return ; @@ -400,7 +427,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *p printf("\nCe paquet explicite bizarre sera traité comme implicite.\n") ; } else - memcpy(&couple.request_time, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + IP_HEADER_SIZE + UDP_HEADER_SIZE + 1], sizeof(struct timeval)); + memcpy(&couple.request_time, &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE + sizeof(struct iphdr) + sizeof(struct udphdr) + 1], sizeof(struct timeval)); } else if (GET_MODE() == MODE_PASSIVE || GET_MODE() == MODE_MIXED) @@ -412,7 +439,10 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *p else // Mode actif uniquement, le paquet n'étant pas une demande explicite return ; + /* Traitement de l'en-tête Radiotap */ + + // TODO : traiter le boutisme avec ntohs memcpy(&rtap_presentflags, &data[RTAP_P_PRESENTFLAGS], RTAP_L_PRESENTFLAGS); // Récupère les flags de l'en-tête rtap #ifdef PLATFORM_ATHEROS rtap_presentflags = ((rtap_presentflags & 0xff000000) >> 24) + ((rtap_presentflags & 0xff0000) >> 8) + ((rtap_presentflags & 0xff00) << 8) + ((rtap_presentflags & 0xff) << 24) ; diff --git a/libowlps/owlps.h b/libowlps/owlps.h index eaa5121..a52de18 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -102,20 +102,11 @@ typedef struct _request{ /* Taille des en-têtes des paquets (en octets) */ #define IEEE80211_HEADER_SIZE 24 #define LLC_HEADER_SIZE 8 -#define IP_HEADER_SIZE 20 -#define UDP_HEADER_SIZE 8 /* Types des paquets capturés (en-tête IEEE 802.11) */ #define RAW_PACKET_TYPE_BEACON 0x80 #define RAW_PACKET_TYPE_DATA 0x08 -/* Protocoles des paquets capturés (en-tête IP) */ -#define RAW_PACKET_PROTO_UDP 0x11 -#define RAW_PACKET_PROTO_ICMP 0x01 - -/* Type de paquet ICMP : octet suivant la fin de l'en-tête IP (data[rtap_bytes+24+8+20]) */ -#define RAW_PACKET_ICMP_ECHO 0x08 - /* Position des champs fixes de l'en-tête radiotap (octets) */ #define RTAP_P_HREVISION 0 // Header revision