From fbe2cdec784e17bbf67744970cb1063ed663a7f6 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 27 Feb 2008 16:37:08 +0000 Subject: [PATCH] Thread monitor dans apd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A code/loc-mobile/TODO M code/loc-bts/ap/apd.c : Thread permettant de passer en mode Monitor lorsque l'interface Wi-Fi n'y est pas. M code/librtaputil/librtaputil.c : Vérification du mode avant le passage en Monitor dans iface_mode_monitor(). git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@22 785a6c6c-259e-4ff1-8b91-dc31627914f0 --- librtaputil/librtaputil.c | 22 ++++++++++++++++------ librtaputil/rtaputil.h | 5 ++++- loc-bts/ap/Makefile | 2 +- loc-bts/ap/ap.h | 1 + loc-bts/ap/apd.c | 20 +++++++++++++++++++- loc-bts/rtapaggregate/rtapaggregate.h | 11 ----------- loc-mobile/TODO | 1 + 7 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 loc-mobile/TODO diff --git a/librtaputil/librtaputil.c b/librtaputil/librtaputil.c index 2dc87c8..c42597c 100644 --- a/librtaputil/librtaputil.c +++ b/librtaputil/librtaputil.c @@ -186,19 +186,29 @@ int create_udp_listening_socket(int port) -/* Bascule l'interface Wi-Fi "iface" en mode Monitor */ +/* Bascule l'interface Wi-Fi "iface" en mode Monitor si elle n'y est pas déjà */ int iface_mode_monitor(char *iface) { struct iwreq wrq ; int sockfd = iw_sockets_open() ; - strncpy((&wrq)->ifr_name, iface, IFNAMSIZ) ; - wrq.u.mode = IW_MODE_MONITOR ; - if (ioctl(sockfd, SIOCSIWMODE, &wrq) == -1) + strncpy((&wrq)->ifr_name, iface, IFNAMSIZ) ; + + if (ioctl(sockfd, SIOCGIWMODE, &wrq) == -1) // Récupération du mode actuel { - perror("Erreur lors du passage en mode Monitor ") ; - return ERR_SETTING_MONITOR_MODE ; + perror("Erreur lors de la lecture du mode ") ; + return ERR_READING_MODE ; + } + + if (wrq.u.mode != IW_MODE_MONITOR) // Si on n'est pas déjà en mode Monitor + { + wrq.u.mode = IW_MODE_MONITOR ; + if (ioctl(sockfd, SIOCSIWMODE, &wrq) == -1) // on y passe. + { + perror("Erreur lors du passage en mode Monitor ") ; + return ERR_SETTING_MONITOR_MODE ; + } } return 0 ; diff --git a/librtaputil/rtaputil.h b/librtaputil/rtaputil.h index a930f25..f3b5ff8 100644 --- a/librtaputil/rtaputil.h +++ b/librtaputil/rtaputil.h @@ -11,6 +11,8 @@ #include #include +#include + #include #include @@ -153,7 +155,8 @@ BOOL run ; #define ERR_SETTING_MONITOR_MODE 101 #define ERR_SETTING_CHANNEL 102 #define ERR_READING_CHANNEL 103 -#define ERR_BAD_SIGNAL 104 +#define ERR_READING_MODE 104 +#define ERR_BAD_SIGNAL 111 /* En-têtes de fonctions */ // Fonctions utilitaires diff --git a/loc-bts/ap/Makefile b/loc-bts/ap/Makefile index 02af0bb..87ab141 100644 --- a/loc-bts/ap/Makefile +++ b/loc-bts/ap/Makefile @@ -21,7 +21,7 @@ CFLAGS=-O2 -W -Wall -Wstrict-prototypes -O -I. DEPFLAGS=-MMD XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS) PICFLAG=-fPIC -LIBS=-lm -lpcap ../../librtaputil/librtaputil.so.1.0 +LIBS=-lm -lpcap -lpthread ../../librtaputil/librtaputil.so.1.0 ## Cibles de compilation standard ## diff --git a/loc-bts/ap/ap.h b/loc-bts/ap/ap.h index dc615b2..e8ec883 100644 --- a/loc-bts/ap/ap.h +++ b/loc-bts/ap/ap.h @@ -27,6 +27,7 @@ enum {ARGV_AGGREG_IP=1, ARGV_RTAP_IFACE, ARGV_WIFI_IFACE} ; /* En-têtes des fonctions */ +void* keep_mode_monitor(char *iface) ; int capture(char *capture_iface, char *aggregated_ip, BOOL print_values) ; void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet, int sockfd, struct sockaddr_in *server, BOOL print_values) ; void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ; diff --git a/loc-bts/ap/apd.c b/loc-bts/ap/apd.c index 9ffee55..6c754cd 100644 --- a/loc-bts/ap/apd.c +++ b/loc-bts/ap/apd.c @@ -15,6 +15,7 @@ int main(int argc, char *argv[]) struct sigaction action ; // Structure de mise en place des gestionnaires de signaux char *mac_string ; // MAC de l'AP sous forme de chaîne int ret ; // Code de retour du programme + pthread_t thread ; // Thread pour le repassage en mode monitor if (argc != ARGC) { @@ -31,6 +32,9 @@ int main(int argc, char *argv[]) action.sa_handler = sigterm_handler ; sigaction(SIGTERM, &action, NULL) ; + /* Création du thread */ + pthread_create(&thread, NULL, (void *) &keep_mode_monitor, argv[ARGV_WIFI_IFACE]) ; + get_mac_addr(argv[ARGV_WIFI_IFACE], mac) ; mac_string = mac_bytes_to_string(mac) ; printf("Ma mac est : %s\n", mac_string) ; @@ -44,6 +48,20 @@ int main(int argc, char *argv[]) +/* Fonction du thread, qui surveille la liste et envoie les infos au serveur de localisation au bout du timeout */ +void* keep_mode_monitor(char *iface) +{ + while (run) + { + iface_mode_monitor(iface) ; // Passage de l'interface en mode Monitor. + sleep(5) ; // Pause de 5 secondes. + } + + return NULL ; +} + + + /* Capture des paquets en utilisant l'interface "capture_iface". * Les données capturées sont envoyées au serveur d'aggrégation dont l'IP est "aggregated_ip". @@ -285,7 +303,7 @@ void get_mac_addr(char *eth, unsigned char mac_bytes[6]) sockfd = socket(AF_INET, SOCK_DGRAM, 0) ; if(sockfd < 0) - printf("Can't open socket\n") ; + perror("Impossible d'ouvrir la socket pour récupérer l'adresse MAC ") ; strncpy(ifr.ifr_name, eth, IFNAMSIZ) ; diff --git a/loc-bts/rtapaggregate/rtapaggregate.h b/loc-bts/rtapaggregate/rtapaggregate.h index 790e6c0..ba1fc5a 100644 --- a/loc-bts/rtapaggregate/rtapaggregate.h +++ b/loc-bts/rtapaggregate/rtapaggregate.h @@ -7,17 +7,6 @@ #include "../../librtaputil/rtaputil.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #define AGGREGATE_TIMEOUT 500 // Timeout d'agrégation (en mili-secondes) diff --git a/loc-mobile/TODO b/loc-mobile/TODO new file mode 100644 index 0000000..b8c4cf5 --- /dev/null +++ b/loc-mobile/TODO @@ -0,0 +1 @@ +* Mettre l'interface Wi-Fi en paramètre du programme mobile.