00001 /* 00002 * iwconnect/message.h 00003 * $Rev: 1222 $ 00004 * 00005 * Copyright (C) 2008-2010 Reto Gantenbein 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License version 2 as 00009 * published by the Free Software Foundation. 00010 */ 00011 00012 #ifndef __MESSAGE_H 00013 #define __MESSAGE_H 00014 00020 /* INCLUDES *******************************************************************/ 00021 00022 #include <netinet/in.h> // struct sockaddr_in 00023 #include <linux/if.h> // IFNAMSIZ 00024 #include <net/ethernet.h> // struct ether_header, ETH_ALEN 00025 #include <limits.h> // for HOST_NAME_MAX 00026 #include <stdint.h> // uint8_t, uint16_t, int16_t, ... 00027 00028 00029 /* MESSAGE TYPES DEFINITIONS **************************************************/ 00030 00032 #define MAX_FRAME_SIZE (1500 + sizeof(struct ether_header)) 00033 // maximal size of an Ethernet frame (MTU 1500); 00034 00036 typedef char raw_packet [MAX_FRAME_SIZE]; 00037 00041 struct msg_header { 00042 uint8_t type; 00043 char id[2 * ETH_ALEN + 1]; 00044 }; 00045 00049 struct data_msg { 00050 struct msg_header header; 00051 uint16_t vif_index; 00052 uint16_t pkt_length; 00053 raw_packet wlan_pkt; 00054 } __attribute__((__packed__)); // pack structs to provide padding problems 00055 00059 typedef union vif_param { 00060 int16_t txpower; 00061 int16_t retry; 00062 int16_t rts; 00063 int16_t frag; 00064 int16_t sensitivity; //(negative) 00065 uint16_t channel; 00066 } 00067 vif_param; 00068 00072 struct s_vif_config { 00073 vif_param value; 00074 uint16_t vif_index; 00075 uint16_t type; 00076 } __attribute__((__packed__)); // pack structs to provide padding problems 00077 typedef struct s_vif_config vif_config; 00078 00082 struct config_msg { 00083 struct msg_header header; 00084 vif_config vif_data; 00085 }; 00086 00090 struct s_vif_registration { 00091 char vif_name[IFNAMSIZ + 1]; 00092 unsigned char vif_mac[ETH_ALEN]; 00093 int16_t vif_index; 00094 int16_t txpower; 00095 int16_t retry; 00096 int16_t rts; 00097 int16_t frag; 00098 int16_t sensitivity; //(negative) 00099 uint16_t channel; 00100 } __attribute__((__packed__)); // pack structs to provide padding problems 00101 typedef struct s_vif_registration vif_registration; 00102 00106 struct registration_info { 00107 char name[HOST_NAME_MAX]; 00108 struct sockaddr_storage addr; 00109 uint16_t msg_id; 00110 uint16_t num_vif; 00111 vif_registration vif_data[2]; 00112 } __attribute__((__packed__)); // pack structs to provide padding problems 00113 00117 struct registration_msg { 00118 struct msg_header header; 00119 struct registration_info info; 00120 }; 00121 00125 struct plain_msg { 00126 struct msg_header header; 00127 uint8_t msg_id; 00128 }; 00129 00130 00131 /* MESSAGE PARAMETER DEFINITIONS **********************************************/ 00132 00133 #define DATA_MSG 0 00134 #define DATA_PREAMBLE_SIZE (sizeof(struct msg_header) + 2 * sizeof(uint16_t)) 00135 #define DATA_MSG_SIZE sizeof(struct data_msg) 00136 00137 #define CONFIG_MSG 1 00138 #define CONFIG_MSG_SIZE sizeof(struct config_msg) 00139 00140 #define REGISTRATION_MSG 2 00141 #define REGISTRATION_MSG_SIZE sizeof(struct registration_msg) 00142 00143 #define PLAIN_MSG_SIZE sizeof(struct plain_msg) 00144 00145 #define ACK_MSG 3 00146 #define ACK_MSG_SIZE PLAIN_MSG_SIZE 00147 00148 #define DEREGISTRATION_MSG 4 00149 #define DEREGISTRATION_MSG_SIZE PLAIN_MSG_SIZE 00150 00151 00153 #define MAX_MSG_SIZE max(WLAN_MSG_SIZE, REGISTRATION_MSG_SIZE) 00154 00155 00156 /* PUBLIC MESSAGE FUNCTIONS ***************************************************/ 00157 00158 int 00159 is_data_msg(struct msg_header *); 00160 00161 int 00162 is_registration_msg(struct msg_header *); 00163 00164 int 00165 is_deregistration_msg(struct msg_header *); 00166 00167 int 00168 is_ack_msg(struct msg_header *); 00169 00170 int 00171 is_config_msg(struct msg_header *); 00172 00173 void 00174 debug_msg(const char *); 00175 00176 #endif