00001 /* 00002 * wlanmodel/PMTypes.h 00003 * 00004 * Copyright (C) 2009 Reto Gantenbein 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License version 2 as 00008 * published by the Free Software Foundation. 00009 */ 00010 00011 #ifndef __PMTYPES_H 00012 #define __PMTYPES_H 00013 00019 #include <limits.h> // for HOST_NAME_MAX 00020 #include <netinet/in.h> 00021 #include <net/ethernet.h> 00022 #include <linux/if_ether.h> 00023 #include <linux/types.h> 00024 #include <linux/wireless.h> 00025 00026 00028 #ifndef IWLIB_H 00029 00035 #define KILO 1e3 00036 #define MEGA 1e6 00037 #define GIGA 1e9 00038 00040 typedef struct iw_statistics iwstats; 00041 typedef struct iw_range iwrange; 00042 typedef struct iw_param iwparam; 00043 typedef struct iw_freq iwfreq; 00044 typedef struct iw_quality iwqual; 00045 typedef struct iw_priv_args iwprivargs; 00046 typedef struct sockaddr sockaddr; 00047 00049 typedef struct wireless_config 00050 { 00051 char name[IFNAMSIZ + 1]; // Wireless/protocol name 00052 int has_nwid; 00053 iwparam nwid; // Network ID 00054 int has_freq; 00055 double freq; // Frequency/channel 00056 int freq_flags; 00057 int has_key; 00058 unsigned char key[IW_ENCODING_TOKEN_MAX]; // Encoding key used 00059 int key_size; // Number of bytes 00060 int key_flags; // Various flags 00061 int has_essid; 00062 int essid_on; 00063 char essid[IW_ESSID_MAX_SIZE + 1]; // ESSID (extended network) 00064 int has_mode; 00065 int mode; // Operation mode 00066 } wireless_config; 00067 00069 typedef struct wireless_info 00070 { 00071 struct wireless_config b; // Basic information 00072 00073 int has_sens; 00074 iwparam sens; // Sensitivity 00075 int has_nickname; 00076 char nickname[IW_ESSID_MAX_SIZE + 1]; // NickName 00077 int has_ap_addr; 00078 sockaddr ap_addr; // Access point address 00079 int has_bitrate; 00080 iwparam bitrate; // Bit rate in bps 00081 int has_rts; 00082 iwparam rts; // RTS threshold in bytes 00083 int has_frag; 00084 iwparam frag; // Fragmentation threshold in bytes 00085 int has_power; 00086 iwparam power; // Power management parameters 00087 int has_txpower; 00088 iwparam txpower; // Transmit Power in dBm 00089 int has_retry; 00090 iwparam retry; // Retry limit or lifetime 00091 00093 iwstats stats; 00094 int has_stats; 00095 iwrange range; 00096 int has_range; 00097 00099 int auth_key_mgmt; 00100 int has_auth_key_mgmt; 00101 int auth_cipher_pairwise; 00102 int has_auth_cipher_pairwise; 00103 int auth_cipher_group; 00104 int has_auth_cipher_group; 00105 } wireless_info; 00106 00107 #endif 00108 00112 #define MAX_NUM_VIF 2 00113 00115 #define MAX_FRAME_SIZE (1500 + sizeof(struct ether_header)) 00116 00117 typedef unsigned char mac_addr [ETH_ALEN]; 00118 typedef char host_id [2 * ETH_ALEN + 1]; 00119 00120 #define max(a, b) ((a) > (b) ? (a) : (b)) 00121 00122 00130 typedef struct { 00131 uint8_t type; 00132 host_id id; 00133 } msgHeader; 00134 00138 typedef char rawFrame [MAX_FRAME_SIZE]; 00139 00145 struct s_dataMsg { 00146 msgHeader header; 00147 uint16_t vifIndex; 00148 uint16_t pktLength; 00149 rawFrame wlanPkt; 00150 } __attribute__((__packed__)); // pack structs to provide padding problems 00151 typedef struct s_dataMsg dataMsg; 00152 00157 typedef union { 00158 int16_t txpower; 00159 int16_t retry; 00160 int16_t rts; 00161 int16_t frag; 00162 int16_t sensitivity; 00163 uint16_t channel; 00164 } vifParameter; 00165 00170 struct s_configNotification { 00171 vifParameter value; 00172 uint16_t vifIndex; 00173 uint16_t type; 00174 } __attribute__((__packed__)); // pack structs to provide padding problems 00175 typedef struct s_configNotification configNotification; 00176 00180 typedef struct { 00181 msgHeader header; 00182 configNotification vifData; 00183 } configMsg; 00184 00188 struct s_vifRegistrationData { 00189 char vifName[IFNAMSIZ + 1]; 00190 unsigned char vifMac[ETH_ALEN]; 00191 int16_t vifIndex; 00192 int16_t txpower; // [mW] 00193 int16_t retry; 00194 int16_t rts; // [Bytes] 00195 int16_t frag; // [Bytes] 00196 int16_t sensitivity; // [dB] (negative) 00197 uint16_t channel; 00198 } __attribute__((__packed__)); // pack structs to provide padding problems 00199 typedef struct s_vifRegistrationData vifRegistrationData; 00200 00204 struct s_registrationInfo { 00205 char name[HOST_NAME_MAX]; 00206 struct sockaddr_storage addr; 00207 uint16_t msgId; 00208 uint16_t numVif; 00209 vifRegistrationData vifData[MAX_NUM_VIF]; 00210 } __attribute__((__packed__)); // pack structs to provide padding problems 00211 typedef struct s_registrationInfo registrationInfo; 00212 00216 typedef struct { 00217 msgHeader header; 00218 registrationInfo info; 00219 } registrationMsg; 00220 00225 typedef struct { 00226 msgHeader header; 00227 uint8_t msgId; 00228 } plainMsg; 00229 00230 00233 #define DATA_MSG 0 00234 #define DATA_PREAMBLE_SIZE (sizeof(msgHeader) + 2 * sizeof(uint16_t)) 00235 #define DATA_MSG_SIZE sizeof(dataMsg) 00236 00237 #define CONFIG_MSG 1 00238 #define CONFIG_MSG_SIZE sizeof(configMsg) 00239 00240 #define REGISTRATION_MSG 2 00241 #define REGISTRATION_MSG_SIZE sizeof(registrationMsg) 00242 00243 #define PLAIN_MSG_SIZE sizeof(plainMsg) 00244 00245 #define ACK_MSG 3 00246 #define ACK_MSG_SIZE PLAIN_MSG_SIZE 00247 00248 #define DEREGISTRATION_MSG 4 00249 #define DEREGISTRATION_MSG_SIZE PLAIN_MSG_SIZE 00250 00251 // maximal size of a node <-> model message 00252 #define MAX_MSG_SIZE max(DATA_MSG_SIZE, REGISTRATION_MSG_SIZE) 00253 00254 #endif // __PMTYPES_H