/home/tai/chorist/xian-1.2/src/include/xian_proto.h

Go to the documentation of this file.
00001 /*
00002  *  xian_proto.h
00003  *  Copyright (C) 2006 THALES Communications
00004  *
00005  *  This file is part of XIAN software.
00006  *
00007  *  XIAN is free software; you can redistribute it and/or modify it
00008  *  under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation.
00010  *
00011  *  XIAN software is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with XIAN software; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  *
00020  *  */
00021 
00022 #include <linux/init.h>
00023 #include <linux/module.h>
00024 #include <linux/time.h>
00025 
00026 #include <linux/netdevice.h>   /* struct device, and other headers */
00027 #include <linux/version.h>
00028 #include "itm.h"
00029 #include "errors.h"
00030 
00031 #define XIAN_NANO_PROTOCOL_VERSION 1
00032 #define XIAN_NANO_PROTOCOL 1
00033 #define XIAN_HEADER_SIZE 12
00034 #define METRIC_MSG_LEN sizeof(struct metric_msg)
00035 #define NB_METRICS 10 //itm.h
00036 
00037 #define NB_MAX_INDEX 5
00038 
00039 #define ETH_ALEN 6
00040 #define HEADER_SIZE 14
00041 
00042 #define HH_DATA_MOD     16
00043 #define LL_RESERVED_SPACE(dev) \
00044         (((dev)->hard_header_len&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
00045 
00046 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
00047 #define XIAN_EXPORT_SYMBOL(x) EXPORT_SYMBOL_NOVERS(x)
00048 #else
00049 #define XIAN_EXPORT_SYMBOL(x) EXPORT_SYMBOL(x)
00050 #endif
00051 
00052 struct metric_msg {
00053   unsigned int type; 
00054   unsigned int id;
00055   unsigned int encoding_type;//not used at this time
00056   unsigned char mac[ETH_ALEN];
00057   struct xian_float value;
00058 };
00059 
00060 struct xian_msg {
00061   unsigned short version;
00062   unsigned int id;
00063   unsigned int length;
00064   struct metric_msg msg[NB_METRICS];
00065 };
00066 
00067 struct metric_conf{
00068   unsigned int index;
00069   char dev_name[IFNAMESIZ+1];
00070   char macadd[IEEE80211_MAC_ADDR_LEN+1];
00071   unsigned int nb;
00072   unsigned int frequency;
00073   unsigned int id[NB_METRICS];
00074   unsigned int metrics[NB_METRICS];//warning : total < NB_METRICS
00075   struct xian_float value[NB_METRICS];
00076   void (*function[NB_METRICS])(unsigned char *saddr, struct metric_msg *metric);
00077 };
00078 
00079 
00080 struct xian_stat{
00081   struct xian_stat *next_stat;
00082   unsigned char saddr[ETH_ALEN];//@MAC source
00083   struct xian_float value;//value
00084 };
00085 
00086 struct xian_stats{
00087   unsigned int id_conf;//id_metrique
00088   struct xian_stats *next_stats;
00089   struct xian_stat *stat;
00090 };
00091 
00092 struct neighbour_table  // structure constituée en local grâce aux infos du driver mad wifi.
00093 {
00094   char macaddr[IEEE80211_MAC_ADDR_LEN+1];
00095   long  timestamp;
00096   struct neighbour_table * next;
00097 };
00098 
00099 extern void xian_if_send(char *dev_name, void *daddr, void *saddr, struct qos_metric_proto_msg message);
00100 extern void xian_netif_rx(struct sk_buff *skb);
00101 
00102 extern void kinsert_metric(struct qos_metric_proto_msg *msg, unsigned int type, unsigned int id, unsigned int encoding_type, unsigned char mac[ETH_ALEN], struct xian_float value);
00103 extern void ksend_metric(char *dev_name, char *macadd, struct qos_metric_proto_msg msg, unsigned int *code_err);
00104 
00105 extern void insert_mac_to_broadcast(unsigned char *saddr);
00106 extern void delete_mac_to_broadcast(unsigned char *saddr);
00107 extern void free_mac_to_broadcast(void);
00108 extern void register_id(unsigned int id, unsigned int metric, char dev[IFNAMESIZ+1], char mac[IEEE80211_MAC_ADDR_LEN+1], unsigned int freq, void *pf);
00109 extern void register_id_no_report(unsigned int id, unsigned int metric, char dev[IFNAMESIZ+1], char mac[IEEE80211_MAC_ADDR_LEN+1], void *pf);
00110 extern void unregister_id(unsigned int id, unsigned int metric);
00111 
00112 void config_relay(void *pf);
00113 int XIAN_Manager_receive(unsigned char *saddr, struct xian_msg *stat);
00114 
00115 struct xian_float get_xian_stat(unsigned char macadd[IEEE80211_MAC_ADDR_LEN+1], unsigned char dev_name[IFNAMESIZ+1], unsigned int id_conf, unsigned int *code_err);
00116 void update_xian_stat(unsigned char saddr[IEEE80211_MAC_ADDR_LEN+1], unsigned char dev_name[IFNAMESIZ+1], unsigned int id_conf, struct xian_float value);
00117 void del_xian_stat(unsigned char dev_name[IFNAMESIZ+1], unsigned int id_conf);
00118 
00119 struct xian_float xian_float_add(struct xian_float a, struct xian_float b);
00120 struct xian_float xian_float_mult(struct xian_float a, struct xian_float b);
00121 struct xian_float xian_float_div(struct xian_float a, struct xian_float b);
00122 int xian_float_cmp(struct xian_float a, struct xian_float b);
00123 struct xian_float int2xian_float(unsigned int x);
00124 
00125 struct xian_neighbour* xian_get_neighbour(char *a );
00126 void xian_print_neighbour(char *a);
00127 
00128 
00129 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
00130 static inline unsigned int jiffies_to_msecs(const unsigned long j)
00131 {
00132 #if HZ <= 1000 && !(1000%HZ)
00133 return(1000/HZ)*j;
00134 #elif HZ > 1000 && !(HZ%1000)
00135 return (j + (HZ/1000)-1)/(HZ/1000);
00136 #else
00137 return (j*1000)/HZ;
00138 #endif
00139 }
00140 #endif
00141 
00142 /**************************************************************************************************************************************/
00147 int
00148 is_hexa (char c)
00149 {
00150   return ((c == '0') || 
00151           (c == '1') || 
00152           (c == '2') || 
00153           (c == '3') || 
00154           (c == '4') || 
00155           (c == '5') || 
00156           (c == '6') || 
00157           (c == '7') || 
00158           (c == '8') || 
00159           (c == '9') || 
00160           (c == 'A') || 
00161           (c == 'a') ||
00162           (c == 'B') ||
00163           (c == 'b') ||
00164           (c == 'C') ||
00165           (c == 'c') ||
00166           (c == 'D') ||
00167           (c == 'd') ||
00168           (c == 'E') ||
00169           (c == 'e') ||
00170           (c == 'F') ||
00171           (c == 'f'));
00172 }
00173 
00174 
00175 /**************************************************************************************************************************************/
00181 int
00182 is_mac_addr_valid (char * mac_addr)
00183 {
00184   if (mac_addr) {
00185     if (strlen (mac_addr) == ((IEEE80211_MAC_ADDR_LEN)))
00186       return (is_hexa(mac_addr[0]) && 
00187               is_hexa(mac_addr[1]) && 
00188               (mac_addr[2] == ':') && 
00189               is_hexa(mac_addr[3]) &&
00190               is_hexa(mac_addr[4]) &&
00191               (mac_addr[5] == ':') &&
00192               is_hexa(mac_addr[6]) &&
00193               is_hexa(mac_addr[7]) &&
00194               (mac_addr[8] == ':') &&
00195               is_hexa(mac_addr[9]) &&
00196               is_hexa(mac_addr[10]) &&
00197               (mac_addr[11] == ':') &&
00198               is_hexa(mac_addr[12]) &&
00199               is_hexa(mac_addr[13]) &&
00200               (mac_addr[14] == ':') &&
00201               is_hexa(mac_addr[15]) &&
00202               is_hexa(mac_addr[16])
00203               );  
00204   }
00205   return 0;
00206 }
00207 
00208 
00209 /**************************************************************************************************************************************/
00218 void
00219 convert_mac_addr (char * mac_addr, unsigned char * res, unsigned int * code_err)
00220 {
00221   char s[2];
00222   if (is_mac_addr_valid(mac_addr))
00223   {
00224     int i, y;
00225     y = 0;
00226     for (i=0;i<IEEE80211_MAC_ADDR_LEN;i = i+3)
00227     {
00228       s[0] = mac_addr[i];
00229       s[1] = mac_addr[i+1];
00230       res[y] = simple_strtoul (s, NULL, 16);
00231       //printk("address mac fields %d ====> %x\n", y, res[y]);
00232       y++;
00233     }
00234     return;
00235   }  
00236   (*code_err) = INVALID_MAC_ADDR;
00237   return;
00238 }
00239 
00240 /**************************************************************************************************************************************/
00245 unsigned char hex2char(unsigned char input){
00246   char c;
00247   if(input==0x0){c='0';}
00248   if(input==0x1){c='1';}
00249   if(input==0x2){c='2';}
00250   if(input==0x3){c='3';}
00251   if(input==0x4){c='4';}
00252   if(input==0x5){c='5';}
00253   if(input==0x6){c='6';}
00254   if(input==0x7){c='7';}
00255   if(input==0x8){c='8';}
00256   if(input==0x9){c='9';}
00257   if(input==0xa){c='a';}
00258   if(input==0xb){c='b';}
00259   if(input==0xc){c='c';}
00260   if(input==0xd){c='d';}
00261   if(input==0xe){c='e';}
00262   if(input==0xf){c='f';}
00263   return c;
00264 }
00265 
00266 /**************************************************************************************************************************************/
00272 void convert_hexamac(unsigned char * saddr, unsigned char * res){
00273   int i,j;
00274   for (i=0 ; i<ETH_ALEN-1; i++){
00275     j=3*i;
00276     res[j]=hex2char((saddr[i]&0xf0)>>4);
00277     res[j+1]=hex2char((saddr[i]&0xf));
00278     res[j+2]=':';
00279   }
00280   j=ETH_ALEN-1;
00281   res[j*3]=hex2char((saddr[j]&0xf0)>>4);
00282   res[j*3+1]=hex2char((saddr[j]&0xf));
00283   res[j*3+2]='\0';
00284  return;
00285 }
00286 
00287 /**************************************************************************************************************************************/
00293 int strcmp_mac(unsigned char mac[6], unsigned char mac_addr_converted[6]){
00294   int i;
00295   for(i=0; i<6; i++){
00296     if(mac[i]!=mac_addr_converted[i]){
00297       return 1;
00298     }
00299   }
00300   return 0;
00301 }

Generated on Mon Jan 21 12:31:46 2008 for XIAN by  doxygen 1.5.3