2008-02-14 08:54:51 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the rtap localisation project.
|
|
|
|
*/
|
|
|
|
|
2010-08-05 17:03:21 +02:00
|
|
|
#ifndef _LIBOWLPS_H_
|
|
|
|
#define _LIBOWLPS_H_
|
2008-02-22 16:04:49 +01:00
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-02-16 10:58:12 +01:00
|
|
|
|
2008-02-27 17:37:08 +01:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
2008-02-16 10:58:12 +01:00
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
#include <sys/types.h>
|
2008-02-16 10:58:12 +01:00
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
#include <math.h>
|
2008-02-16 10:58:12 +01:00
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
#include <signal.h>
|
2008-02-16 10:58:12 +01:00
|
|
|
#include <errno.h>
|
|
|
|
|
2008-02-22 16:04:49 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
2008-02-16 10:58:12 +01:00
|
|
|
#include <net/if.h>
|
2008-02-14 08:54:51 +01:00
|
|
|
|
2008-02-26 16:51:49 +01:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <iwlib.h>
|
|
|
|
#include <wireless.h>
|
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
|
2010-08-05 17:03:21 +02:00
|
|
|
// Port on which the positioning request is sent by the mobile:
|
|
|
|
#define LOC_REQUEST_DEFAULT_PORT 9900
|
|
|
|
// Port on which listeners and aggregator communicate:
|
|
|
|
#define AGGREGATE_DEFAULT_PORT 9901
|
|
|
|
// Port on which aggregator and positioning server communicate:
|
|
|
|
#define POSITIONER_DEFAULT_PORT 9902
|
2010-10-08 16:57:40 +02:00
|
|
|
// Port on which listener listens for order from aggregator:
|
|
|
|
#define LISTENER_DEFAULT_PORT 9903
|
2010-10-14 18:30:41 +02:00
|
|
|
#define DEFAULT_AUTOCALIBRATION_PORT 9904
|
2010-08-05 17:03:21 +02:00
|
|
|
// Port on which the mobile listens for its position:
|
|
|
|
#define MOBILE_DEFAULT_PORT 9910
|
2008-02-14 08:54:51 +01:00
|
|
|
|
2010-10-08 16:57:40 +02:00
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
/* Type booléen */
|
|
|
|
typedef enum {FALSE, TRUE} BOOL ;
|
|
|
|
|
|
|
|
|
|
|
|
/* Type direction */
|
|
|
|
typedef enum {NORTH = 1, EAST, SOUTH, WEST} DIRECTION ;
|
|
|
|
|
|
|
|
|
|
|
|
/* Message envoyé par l'AP à l'agrégateur */
|
|
|
|
typedef struct _couple_message
|
|
|
|
{
|
|
|
|
unsigned char ap_mac_addr_bytes[6] ; // Adresse MAC de l'AP émetteur de l'info en octets
|
|
|
|
unsigned char mobile_mac_addr_bytes[6] ; // Adresse MAC du mobile en octets
|
2009-05-29 17:02:20 +02:00
|
|
|
unsigned char mobile_ip_addr_bytes[4] ; // Adresse IP du mobile en octets
|
2008-02-14 08:54:51 +01:00
|
|
|
struct timeval request_time ; // Identifiant du paquet = date sur le client
|
2008-03-14 11:31:04 +01:00
|
|
|
struct timeval start_time ; // Heure d'arrivée du paquet sur l'AP
|
2008-02-14 08:54:51 +01:00
|
|
|
unsigned char antenna_signal_dbm ; // Puissance du signal reçu par l'AP du mobile
|
|
|
|
/* Données pour la calibration */
|
|
|
|
float x_position ;
|
|
|
|
float y_position ;
|
|
|
|
float z_position ;
|
|
|
|
DIRECTION direction ; // Orientation de la demande de localisation
|
|
|
|
} couple_message ;
|
|
|
|
|
2009-05-29 17:02:20 +02:00
|
|
|
typedef struct _couple_info
|
|
|
|
{
|
|
|
|
unsigned char ap_mac_addr_bytes[6] ; // Adresse MAC de l'AP
|
|
|
|
unsigned char antenna_signal_dbm ; // Puissance du signal reçu par l'AP
|
|
|
|
} couple_info ;
|
|
|
|
|
2010-08-05 17:03:21 +02:00
|
|
|
typedef struct _request
|
|
|
|
{
|
2009-05-29 17:02:20 +02:00
|
|
|
unsigned char mobile_mac_addr_bytes[6]; //Adresse MAC du mobile
|
|
|
|
struct timeval request_time; // Date sur le client
|
|
|
|
int nb_couples; // Nombre couples (MAC AP;Puissance)
|
|
|
|
} request;
|
2008-02-14 08:54:51 +01:00
|
|
|
|
2010-10-11 09:54:35 +02:00
|
|
|
typedef struct _autocalibration_hello
|
|
|
|
{
|
|
|
|
unsigned char ap_mac_addr_bytes[6];
|
2010-10-13 17:42:00 +02:00
|
|
|
char ap_ip_addr[16] ;
|
2010-10-11 09:54:35 +02:00
|
|
|
} autocalibration_hello ;
|
|
|
|
|
2010-10-12 10:13:59 +02:00
|
|
|
typedef struct _autocalibration_order
|
|
|
|
{
|
|
|
|
enum {AUTOCALIBRATION_ORDER_SEND = 1} order ;
|
|
|
|
} autocalibration_order ;
|
|
|
|
|
2008-11-06 08:41:32 +01:00
|
|
|
/* Types de demandes de localisation */
|
|
|
|
#define PACKET_TYPE_NORMAL 0
|
|
|
|
#define PACKET_TYPE_CALIBRATION 1
|
2010-10-12 10:13:59 +02:00
|
|
|
#define PACKET_TYPE_AUTOCALIBRATION 2
|
2008-11-06 08:41:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
|
|
|
|
/* Taille des en-têtes des paquets (en octets) */
|
|
|
|
#define IEEE80211_HEADER_SIZE 24
|
|
|
|
#define LLC_HEADER_SIZE 8
|
|
|
|
|
|
|
|
/* Types des paquets capturés (en-tête IEEE 802.11) */
|
2008-02-22 16:04:49 +01:00
|
|
|
#define RAW_PACKET_TYPE_BEACON 0x80
|
|
|
|
#define RAW_PACKET_TYPE_DATA 0x08
|
|
|
|
|
|
|
|
|
2008-11-06 08:41:32 +01:00
|
|
|
/* Position des champs fixes de l'en-tête radiotap (octets) */
|
2008-02-14 08:54:51 +01:00
|
|
|
#define RTAP_P_HREVISION 0 // Header revision
|
|
|
|
#define RTAP_P_HPAD 1 // Header pad
|
|
|
|
#define RTAP_P_HLENGTH 2 // Header length
|
|
|
|
#define RTAP_P_PRESENTFLAGS 4 // Present flags
|
|
|
|
|
|
|
|
|
2008-11-06 08:41:32 +01:00
|
|
|
/* Longueur des champs de l'en-tête radiotap (octets) */
|
2008-02-14 08:54:51 +01:00
|
|
|
#define RTAP_L_HREVISION 1 // Header revision
|
|
|
|
#define RTAP_L_HPAD 1 // Header pad
|
|
|
|
#define RTAP_L_HLENGTH 2 // Header length
|
|
|
|
#define RTAP_L_PRESENTFLAGS 4 // Present flags
|
2008-11-06 08:41:32 +01:00
|
|
|
#define RTAP_L_MACTS 8 // MAC timestamp (Time Synchronization Function Timer)
|
2008-02-14 08:54:51 +01:00
|
|
|
#define RTAP_L_FLAGS 1 // autre champ de flags
|
|
|
|
#define RTAP_L_RATE 1 // Data rate
|
2008-11-06 08:41:32 +01:00
|
|
|
#define RTAP_L_CHANNEL 2 // Channel frequency
|
2008-02-14 08:54:51 +01:00
|
|
|
#define RTAP_L_CHANNELTYPE 2 // Channel type
|
2008-11-06 08:41:32 +01:00
|
|
|
#define RTAP_L_ANTENNASIGNALDBM 1 // SSI signal (dBm)
|
|
|
|
#define RTAP_L_ANTENNANOISEDBM 1 // SSI noise (dBm)
|
|
|
|
#define RTAP_L_ANTENNA 1 // Antenna number
|
|
|
|
#define RTAP_L_FHSS 2 // Hop set and pattern for Frequency-Hopping Spread Spectrum
|
|
|
|
#define RTAP_L_LOCKQUALITY 2 // Signal quality
|
|
|
|
#define RTAP_L_TXATTENUATION 2 // Transmit power from max power
|
|
|
|
#define RTAP_L_TXATTENUATIONDB 2 // Idem (dB)
|
|
|
|
#define RTAP_L_TXATTENUATIONDBM 1 // Idem (dBm)
|
|
|
|
#define RTAP_L_ANTENNASIGNALDB 1 // SSI signal (dB)
|
|
|
|
#define RTAP_L_ANTENNANOISEDB 1 // SSI noise (dB)
|
|
|
|
#define RTAP_L_FCS 4 // Frame Check Sequence
|
|
|
|
//#define RTAP_L_CHANNELP // Extended channel info (non implémenté)
|
|
|
|
//#define RTAP_L_EXT // Extension aux Present flags (non implémenté)
|
|
|
|
|
|
|
|
|
|
|
|
/* Positions dans Present flags (et tableau 'check' des champs présents) */
|
2008-02-14 08:54:51 +01:00
|
|
|
#define RTAP_MACTS 0
|
|
|
|
#define RTAP_FLAGS 1
|
|
|
|
#define RTAP_RATE 2
|
|
|
|
#define RTAP_CHANNEL 3 // ainsi que RTAP_CHANNELTYPE
|
|
|
|
#define RTAP_FHSS 4
|
|
|
|
#define RTAP_ANTENNASIGNALDBM 5
|
|
|
|
#define RTAP_ANTENNANOISEDBM 6
|
|
|
|
#define RTAP_LOCKQUALITY 7
|
|
|
|
#define RTAP_TXATTENUATION 8
|
|
|
|
#define RTAP_TXATTENUATIONDB 9
|
|
|
|
#define RTAP_TXATTENUATIONDBM 10
|
|
|
|
#define RTAP_ANTENNA 11
|
|
|
|
#define RTAP_ANTENNASIGNALDB 12
|
|
|
|
#define RTAP_ANTENNANOISEDB 13
|
|
|
|
#define RTAP_FCS 14
|
2008-11-06 08:41:32 +01:00
|
|
|
//#define RTAP_CHANNELP 18
|
|
|
|
//#define RTAP_EXT 31
|
2008-02-26 16:51:49 +01:00
|
|
|
|
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
/* Variables globales */
|
|
|
|
BOOL run ;
|
|
|
|
|
|
|
|
|
2008-02-26 16:51:49 +01:00
|
|
|
/* Codes d'erreur des fonctions */
|
2010-08-05 17:03:21 +02:00
|
|
|
#define ERR_SETTING_MODE 101
|
2008-02-26 16:51:49 +01:00
|
|
|
#define ERR_SETTING_CHANNEL 102
|
|
|
|
#define ERR_READING_CHANNEL 103
|
2008-02-27 17:37:08 +01:00
|
|
|
#define ERR_READING_MODE 104
|
|
|
|
#define ERR_BAD_SIGNAL 111
|
2008-02-26 16:51:49 +01:00
|
|
|
|
2008-03-14 11:31:04 +01:00
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
/* En-têtes de fonctions */
|
|
|
|
// Fonctions utilitaires
|
|
|
|
char* mac_bytes_to_string(unsigned char *mac_binary) ;
|
|
|
|
char frequency_to_channel(unsigned short channel) ;
|
2008-03-14 11:31:04 +01:00
|
|
|
unsigned long long timeval_to_ms(struct timeval date) ;
|
2008-02-14 08:54:51 +01:00
|
|
|
unsigned long sub_date(struct timeval sup, struct timeval inf) ;
|
|
|
|
BOOL mac_cmp(unsigned char *mac1, unsigned char *mac2) ;
|
|
|
|
|
|
|
|
// Réseau
|
|
|
|
int create_udp_sending_socket(char *server_address, int server_port, struct sockaddr_in *server_description, struct sockaddr_in * client_description) ;
|
2008-11-06 08:41:32 +01:00
|
|
|
int create_udp_listening_socket(int port) ;
|
2008-02-26 16:51:49 +01:00
|
|
|
int iface_mode_monitor(char *iface) ;
|
|
|
|
int iface_set_channel(char *iface, int channel) ;
|
|
|
|
int iface_channel_hop(char *iface) ;
|
2008-02-22 16:04:49 +01:00
|
|
|
|
2008-11-06 08:41:32 +01:00
|
|
|
// Signaux
|
|
|
|
void sigint_handler(int num) ;
|
|
|
|
void sigterm_handler(int num) ;
|
|
|
|
|
2008-02-22 16:04:49 +01:00
|
|
|
|
2008-03-14 11:31:04 +01:00
|
|
|
/* Macros */
|
|
|
|
|
|
|
|
/* Prend les flags de l'en-tête IEEE 802.11 en paramètre,
|
|
|
|
* retourne 0 si le bit Retry est absent, ou une valeur positive s'il est présent.
|
|
|
|
*/
|
|
|
|
#define IS_RETRY(IEEE80211_FLAGS) ((IEEE80211_FLAGS) & 0x08)
|
|
|
|
|
|
|
|
|
2010-08-05 17:03:21 +02:00
|
|
|
#endif // _LIBOWLPS_H_
|