Ajouts dans mobile.c et librtaputil

M    code/loc-mobile/mobile/mobile.c : Passage en mode Monitor avant la
     capture.
M    code/librtaputil/librtaputil.c : Ajout des fonctions
     iface_mode_monitor(), iface_set_channel(), iface_channel_hop().
M    code/librtaputil/rtaputil.h
D    code/loc-mobile/client : Réparation de l'erreur précédente.

git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@21 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
Matteo Cypriani 2008-02-26 15:51:49 +00:00
parent ac937d1471
commit 2f245fc09a
6 changed files with 127 additions and 25 deletions

View File

@ -55,7 +55,8 @@ purge :
help :
@echo "Bibliothèques nécessaires à la compilation :\n\
aucune\n\
libpcap0.8-dev\n\
libiw-dev\n\
\n\
Cibles possibles :\n\
all (cible par défaut) : Compile tous les modules.\n\

View File

@ -34,7 +34,7 @@ CFLAGS=-O2 -W -Wall -Wstrict-prototypes -O -I.
DEPFLAGS=-MMD
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG=-fPIC
LIBS=
LIBS=-liw
#STRIPFLAGS= -Wl,-s
@ -112,7 +112,8 @@ purge : clean
## Aide ##
help :
@echo "Aucune bibliothèques nécessaires à la compilation.\n\
@echo "Bibliothèques nécessaires à la compilation :\n\
libiw-dev\n\
\n\
Cibles possibles :\n\
all (cible par défaut) : Compile la bibliothèque et le programme d'exemple (tx).\n\

View File

@ -32,46 +32,46 @@ char frequency_to_channel(unsigned short channel)
switch (channel)
{
case 2412 :
case CHANNEL_1 :
c = 1 ;
break ;
case 2417 :
case CHANNEL_2 :
c = 2 ;
break ;
case 2422 :
case CHANNEL_3 :
c = 3 ;
break ;
case 2427 :
case CHANNEL_4 :
c = 4 ;
break ;
case 2432 :
case CHANNEL_5 :
c = 5 ;
break ;
case 2437 :
case CHANNEL_6 :
c = 6 ;
break ;
case 2442 :
case CHANNEL_7 :
c = 7 ;
break ;
case 2447 :
case CHANNEL_8 :
c = 8 ;
break ;
case 2452 :
case CHANNEL_9 :
c = 9 ;
break ;
case 2457 :
case CHANNEL_10 :
c = 10 ;
break ;
case 2462 :
case CHANNEL_11 :
c = 11 ;
break ;
case 2467 :
case CHANNEL_12 :
c = 12 ;
break ;
case 2472 :
case CHANNEL_13 :
c = 13 ;
break ;
case 2477 :
case CHANNEL_14 :
c = 14 ;
break ;
}
@ -128,7 +128,7 @@ int create_udp_sending_socket(char *server_address, int server_port, struct sock
if (sockfd < 0)
{
perror("Échec de la création de la socket ") ;
return(sockfd) ;
return sockfd ;
}
/* Remise à zéro et initialisation de la structure du client */
@ -143,7 +143,7 @@ int create_udp_sending_socket(char *server_address, int server_port, struct sock
server_description->sin_addr.s_addr = inet_addr(server_address) ; // Adresse du serveur
server_description->sin_port = htons(server_port) ; // Port d'écoute du serveur
return (sockfd) ; // On retourne le descripteur de la socket créée
return sockfd ; // On retourne le descripteur de la socket créée
}
@ -163,7 +163,7 @@ int create_udp_listening_socket(int port)
if (sockfd < 0)
{
perror("Échec de la création de la socket ") ;
return(sockfd) ;
return sockfd ;
}
/* Remise à zéro et initialisation de la structure du serveur */
@ -186,12 +186,81 @@ int create_udp_listening_socket(int port)
/* Bascule l'interface Wi-Fi "iface" en mode Monitor */
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)
{
perror("Erreur lors du passage en mode Monitor ") ;
return ERR_SETTING_MONITOR_MODE ;
}
return 0 ;
}
/* Change le canal de l'interface Wi-Fi "iface" avec la valeur "channel" */
int iface_set_channel(char *iface, int channel)
{
struct iwreq wrq ;
int sockfd = iw_sockets_open() ;
strncpy((&wrq)->ifr_name, iface, IFNAMSIZ) ;
iw_float2freq(channel, &(wrq.u.freq)) ;
wrq.u.freq.flags = IW_FREQ_FIXED ;
if (ioctl(sockfd, SIOCSIWFREQ, &wrq) == -1)
{
perror("Erreur lors du changement de canal ") ;
return ERR_SETTING_CHANNEL ;
}
return 0 ;
}
/* Fait varier le canal de l'interface Wi-Fi "iface" entre les canaux 4 et 11 */
int iface_channel_hop(char *iface)
{
unsigned short channel ;
struct iwreq wrq ;
int sockfd = iw_sockets_open() ;
strncpy((&wrq)->ifr_name, iface, IFNAMSIZ) ;
if (ioctl(sockfd, SIOCGIWFREQ, &wrq) == -1)
{
perror("Erreur lors de la lecture de la fréquence ") ;
return ERR_READING_CHANNEL ;
}
channel = wrq.u.freq.m / 100000 ; // Un peu gruik : il vaudrait mieux utiliser iw_freq2float(), iw_freq_to_channel() et compagnie (cf. /usr/include/{iwlib.h,wireless.h}).
if (channel > 1000) // Si la valeur est en Hz,
channel = frequency_to_channel(channel) ; // on la convertit en numéro de canal (avec notre fonction maison, toujours un peu gruik).
/* Changement de canal */
if (channel == 4) // Si le canal est déjà à 4,
return iface_set_channel(iface, 11) ; // on le passe à 11 ;
else
return iface_set_channel(iface, 4) ; // sinon on le met à 4.
}
void sigint_handler(int num)
{
if (num != SIGINT)
{
fprintf(stderr, "Erreur ! Gestionnaire de SIGINT appelé mais le signal n'est pas SIGINT.\n") ;
exit(1) ;
exit(ERR_BAD_SIGNAL) ;
}
run = FALSE ;
@ -207,7 +276,7 @@ void sigterm_handler(int num)
if (num != SIGTERM)
{
fprintf(stderr, "Erreur ! Gestionnaire de SIGTERM appelé mais le signal n'est pas SIGINT.\n") ;
exit(1) ;
exit(ERR_BAD_SIGNAL) ;
}
sigint_handler(SIGINT) ;

View File

@ -29,6 +29,10 @@
#include <netdb.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <iwlib.h>
#include <wireless.h>
#define LOC_REQUEST_DEFAULT_PORT 9900 // Port sur lequel est envoyée la requête de localisation depuis le mobile
#define AGGREGATE_DEFAULT_PORT 9901 // Port d'échange des données entre AP et serveur d'aggrégation
@ -124,10 +128,33 @@ typedef struct _couple_message
#define RTAP_FCS 14
/* Fréquences des canaux Wi-Fi en Hz */
#define CHANNEL_1 2412
#define CHANNEL_2 2417
#define CHANNEL_3 2422
#define CHANNEL_4 2427
#define CHANNEL_5 2432
#define CHANNEL_6 2437
#define CHANNEL_7 2442
#define CHANNEL_8 2447
#define CHANNEL_9 2452
#define CHANNEL_10 2457
#define CHANNEL_11 2462
#define CHANNEL_12 2467
#define CHANNEL_13 2472
#define CHANNEL_14 2477
/* Variables globales */
BOOL run ;
/* Codes d'erreur des fonctions */
#define ERR_SETTING_MONITOR_MODE 101
#define ERR_SETTING_CHANNEL 102
#define ERR_READING_CHANNEL 103
#define ERR_BAD_SIGNAL 104
/* En-têtes de fonctions */
// Fonctions utilitaires
char* mac_bytes_to_string(unsigned char *mac_binary) ;
@ -143,6 +170,9 @@ void sigterm_handler(int num) ;
// Réseau
int create_udp_listening_socket(int port) ;
int create_udp_sending_socket(char *server_address, int server_port, struct sockaddr_in *server_description, struct sockaddr_in * client_description) ;
int iface_mode_monitor(char *iface) ;
int iface_set_channel(char *iface, int channel) ;
int iface_channel_hop(char *iface) ;
#endif

View File

@ -13,7 +13,6 @@
#include <netinet/if_ether.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <sys/ioctl.h>
/* Codes d'erreurs */

View File

@ -4,7 +4,7 @@
*/
#include "rtapscanmob.h"
#include "../librtapscanmob/rtapscanmob.h"
@ -218,7 +218,7 @@ void read_options(int argc, char **argv, BOOL *options, char *capture_iface, int
print_usage_only(argv[0]) ;
exit(ERR_OPT_INPUT_OUTPUT) ;
}
if (! (options[NUM_OPT_DIRECTION] && options[NUM_OPT_POSX] && options[NUM_OPT_POSY] && options[NUM_OPT_POSZ]))
if ((options[NUM_OPT_DIRECTION] || options[NUM_OPT_POSX] || options[NUM_OPT_POSY] || options[NUM_OPT_POSZ]) && ! (options[NUM_OPT_DIRECTION] && options[NUM_OPT_POSX] && options[NUM_OPT_POSY] && options[NUM_OPT_POSZ]))
{
fprintf(stderr, "Vous devez spécifier toutes les options de calibration ou aucune !\n") ;
print_usage_only(argv[0]) ;
@ -253,6 +253,8 @@ int main(int argc, char **argv)
printf("Interface de capture : %s\nTemps de capture : %d\n\n", capture_iface, capture_time) ;
iface_mode_monitor("eth2") ; // Passage de l'interface Wi-Fi en mode Monitor. FIXME ! mettre l'interface Wi-Fi en paramètre du programme (wifi_iface != capture_iface, cf. apd.c).
if ((ret = capture(capture_iface, capture_time, &results, options[NUM_OPT_VERB])) != 0) // Capture de paquets.
return ret ; // On quitte avec le code d'erreur si la capture a mal fini.