00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00017
00018
00019 #include <arpa/inet.h>
00020 #include <netinet/in.h>
00021
00022
00023 #include <linux/wireless.h>
00024 #include "message.h"
00025 #include "iwc_print.h"
00026
00027
00028
00029
00031 int
00032 is_data_msg(struct msg_header *header)
00033 {
00034 return header->type == DATA_MSG;
00035 }
00036
00038 int
00039 is_registration_msg(struct msg_header *header)
00040 {
00041 return header->type == REGISTRATION_MSG;
00042 }
00043
00045 int
00046 is_deregistration_msg(struct msg_header *header)
00047 {
00048 return header->type == DEREGISTRATION_MSG;
00049 }
00050
00052 int
00053 is_ack_msg(struct msg_header *header)
00054 {
00055 return header->type == ACK_MSG;
00056 }
00057
00059 int
00060 is_config_msg(struct msg_header *header)
00061 {
00062 return header->type == CONFIG_MSG;
00063 }
00064
00066 void
00067 print_data_msg(const char *message)
00068 {
00069 struct msg_header *header = (struct msg_header *) message;
00070 struct data_msg *msg = (struct data_msg *) message;
00071 int frame_size = msg->pkt_length;
00072 if (frame_size < DATA_PREAMBLE_SIZE)
00073 {
00074 iwc_debug("Invalid message size!\n");
00075 return;
00076 }
00077 iwc_debug("[%4i bytes] =========== DATA MESSAGE ================\n",
00078 frame_size + DATA_PREAMBLE_SIZE);
00079 iwc_debug("[%4i bytes] ,---------- msg_header ------------------\n",
00080 sizeof(struct msg_header));
00081 iwc_debug("(%4i bytes) | type:\t\t%i\n", sizeof(header->type), header->type);
00082 iwc_debug("(%4i bytes) | id:\t\t%s\n", sizeof(header->id), header->id);
00083 iwc_debug("(%4i bytes) vif_index:\t\t%i\n", sizeof(uint16_t), msg->vif_index);
00084 iwc_debug("(%4i bytes) pkg_length:\t\t%i\n", sizeof(uint16_t), frame_size);
00085 struct ether_header *ether_hdr = (struct ether_header *) msg->wlan_pkt;
00086 iwc_debug("[%4i bytes] ,---------- raw_packet ------------------\n",
00087 frame_size);
00088 iwc_debug("(%4i bytes) | ether_header --------------------------\n",
00089 sizeof(struct ether_header));
00090 iwc_debug("(%4i bytes) | | ether_dhost\t%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
00091 ETH_ALEN, ether_hdr->ether_dhost[0], ether_hdr->ether_dhost[1],
00092 ether_hdr->ether_dhost[2], ether_hdr->ether_dhost[3],
00093 ether_hdr->ether_dhost[4], ether_hdr->ether_dhost[5]);
00094 iwc_debug("(%4i bytes) | | ether_shost\t%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
00095 ETH_ALEN, ether_hdr->ether_shost[0], ether_hdr->ether_shost[1],
00096 ether_hdr->ether_shost[2], ether_hdr->ether_shost[3],
00097 ether_hdr->ether_shost[4], ether_hdr->ether_shost[5]);
00098 u_int16_t ether_type = ntohs(ether_hdr->ether_type);
00099 switch (ether_type)
00100 {
00101 case ETHERTYPE_IP:
00102 iwc_debug("(%4i bytes) | | type\t\t%i (ETHERTYPE_IP)\n",
00103 sizeof(u_int16_t), ETHERTYPE_IP);
00104 break;
00105 case ETHERTYPE_ARP:
00106 iwc_debug("(%4i bytes) | | type\t\t%i (ETHERTYPE_ARP)\n",
00107 sizeof(u_int16_t), ETHERTYPE_ARP);
00108 break;
00109 default:
00110 iwc_debug("(%4i bytes) | | type\t\t%i (unknown)\n",
00111 sizeof(u_int16_t), ether_type);
00112 break;
00113 }
00114 if (frame_size > MAX_FRAME_SIZE)
00115 iwc_debug("====> FRAME SIZE INVALID (too big!) <====\n");
00116 iwc_debug("------------------------------------------------------\n");
00117 }
00118
00120 void
00121 print_config_msg(const char *message)
00122 {
00123 struct msg_header *header = (struct msg_header *) message;
00124 iwc_debug("[%4i bytes] =========== CONFIGURE MESSAGE ===========\n",
00125 sizeof(struct config_msg));
00126 iwc_debug("[%4i bytes] ,---------- msg_header ------------------\n",
00127 sizeof(struct msg_header));
00128 iwc_debug("(%4i bytes) | type:\t%i\n", sizeof(header->type), header->type);
00129 iwc_debug("(%4i bytes) | id:\t%s\n", sizeof(header->id), header->id);
00130 struct config_msg *conf_msg = (struct config_msg *) message;
00131 iwc_debug("(%4i bytes) vif_index:\t%i\n",
00132 sizeof(conf_msg->vif_data.vif_index), conf_msg->vif_data.vif_index);
00133 uint16_t property = conf_msg->vif_data.type;
00134 union vif_param *value_p = &(conf_msg->vif_data.value);
00135 switch (property)
00136 {
00137 case SIOCSIWFREQ:
00138 iwc_debug("(%4i bytes) property:\t%4x (SIOCSIWFREQ)\n",
00139 sizeof(property), property);
00140 iwc_debug("(%4i bytes) value:\t%i\n",
00141 sizeof(*value_p), value_p->channel);
00142 break;
00143 case SIOCSIWTXPOW:
00144 iwc_debug("(%4i bytes) property:\t%4x (SICSIWTXPOW)\n",
00145 sizeof(property), property);
00146 iwc_debug("(%4i bytes) value:\t%imW\n",
00147 sizeof(*value_p), value_p->txpower);
00148 break;
00149 case SIOCSIWFRAG:
00150 iwc_debug("(%4i bytes) property:\t%4x (SICSIWFRAG)\n",
00151 sizeof(property), property);
00152 iwc_debug("(%4i bytes) value:\t%i\n",
00153 sizeof(*value_p), value_p->frag);
00154 break;
00155 case SIOCSIWRETRY:
00156 iwc_debug("(%4i bytes) property:\t%4x (SICSIWRETRY)\n",
00157 sizeof(property), property);
00158 iwc_debug("(%4i bytes) value:\t%i\n",
00159 sizeof(*value_p), value_p->retry);
00160 break;
00161 case SIOCSIWRTS:
00162 iwc_debug("(%4i bytes) property:\t%4x (SIOCSIWRTS)\n",
00163 sizeof(property), property);
00164 iwc_debug("(%4i bytes) value:\t%iB\n",
00165 sizeof(*value_p), value_p->rts);
00166 break;
00167 case SIOCSIWSENS:
00168 iwc_debug("(%4i bytes) property:\t%4x (SICSIWSENS)\n",
00169 sizeof(property), property);
00170 iwc_debug("(%4i bytes) value:\t%idB\n",
00171 sizeof(*value_p), value_p->sensitivity);
00172 break;
00173 default:
00174 iwc_debug("(%4i bytes) property:\t%4x (unknown)\n",
00175 sizeof(property), property);
00176 break;
00177 }
00178 iwc_debug("------------------------------------------------------\n");
00179 }
00180
00182 void
00183 print_reg_msg(const char *message)
00184 {
00185 int i = 0;
00186
00187 iwc_debug("[%4i bytes] =========== REGISTRATION MESSAGE ========\n",
00188 sizeof(struct registration_msg));
00189 struct msg_header *header = (struct msg_header *) message;
00190 iwc_debug("[%4i bytes] ,---------- msg_header ------------------\n",
00191 sizeof(struct msg_header));
00192 iwc_debug("(%4i bytes) | type:\t%i\n", sizeof(header->type), header->type);
00193 iwc_debug("(%4i bytes) | id:\t%s\n", sizeof(header->id), header->id);
00194
00195 struct registration_info *reg_info =
00196 &((struct registration_msg *) message)->info;
00197 iwc_debug("[%4i bytes] ,---------- reg_info --------------------\n",
00198 sizeof(struct registration_info));
00199 iwc_debug("(%4i bytes) | name:\t%s\n",
00200 sizeof(reg_info->name), reg_info->name);
00201
00202 struct sockaddr *addr = (struct sockaddr *) ®_info->addr;
00203 iwc_debug("[%4i bytes] | ,---------------- addr ----------------\n",
00204 sizeof(struct sockaddr_storage));
00205 iwc_debug("(%4i bytes) | | sin_family:\t%i\n", sizeof(short), addr->sa_family);
00206 if (addr->sa_family == AF_INET)
00207 {
00208 iwc_debug("(%4i bytes) | | sin_port:\t%i\n", sizeof(unsigned short),
00209 ntohs(((struct sockaddr_in *) addr)->sin_port));
00210 iwc_debug("(%4i bytes) | | sin_addr:\t%s\n", sizeof(unsigned long),
00211 inet_ntoa(((struct sockaddr_in *) addr)->sin_addr));
00212 }
00213 if (addr->sa_family == AF_INET6)
00214 {
00215 char addr_string[INET6_ADDRSTRLEN];
00216 iwc_debug("(%4i bytes) | | sin6_port:\t%i\n", sizeof(uint16_t),
00217 ntohs(((struct sockaddr_in6 *) addr)->sin6_port));
00218 iwc_debug("(%4i bytes) | | sin6_addr:\t%s\n", 16 * sizeof(unsigned char),
00219 inet_ntop(AF_INET6, &((struct sockaddr_in6 *) addr)->sin6_addr,
00220 addr_string, INET6_ADDRSTRLEN));
00221 }
00222 iwc_debug("(%4i bytes) | msg_id:\t%i\n",
00223 sizeof(reg_info->msg_id), reg_info->msg_id);
00224 iwc_debug("(%4i bytes) | num_vif:\t%i\n",
00225 sizeof(reg_info->num_vif), reg_info->num_vif);
00226
00227 for (i = 0; i < reg_info->num_vif; i++)
00228 {
00229 vif_registration *vif_reg = ®_info->vif_data[i];
00230 unsigned char *mac = vif_reg->vif_mac;
00231 iwc_debug("[%4i bytes] | ,---------------- vif_registration[%i] -\n",
00232 sizeof(vif_registration), i);
00233 iwc_debug("(%4i bytes) | | vif_name:\t%s\n",
00234 IFNAMSIZ + 1, vif_reg->vif_name);
00235 iwc_debug("(%4i bytes) | | vif_mac:\t%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
00236 ETH_ALEN, ((unsigned char *) mac)[0], ((unsigned char *) mac)[1],
00237 ((unsigned char *) mac)[2], ((unsigned char *) mac)[3],
00238 ((unsigned char *) mac)[4], ((unsigned char *) mac)[5]);
00239 iwc_debug("(%4i btyes) | | vif_index\t%i\n",
00240 sizeof(vif_reg->vif_index), vif_reg->vif_index);
00241 iwc_debug("(%4i bytes) | | txpower:\t%imW\n",
00242 sizeof(reg_info->vif_data->txpower), vif_reg->txpower);
00243 iwc_debug("(%4i bytes) | | retry:\t\t%i\n",
00244 sizeof(reg_info->vif_data->retry), vif_reg->retry);
00245 iwc_debug("(%4i bytes) | | rts:\t\t%iB\n",
00246 sizeof(reg_info->vif_data->rts), vif_reg->rts);
00247 iwc_debug("(%4i bytes) | | fragmentation:\t%iB\n",
00248 sizeof(reg_info->vif_data->frag), vif_reg->frag);
00249 iwc_debug("(%4i bytes) | | sensitivity:\t%idB\n",
00250 sizeof(reg_info->vif_data->sensitivity), vif_reg->sensitivity);
00251 iwc_debug("(%4i bytes) | | channel:\t%i\n",
00252 sizeof(reg_info->vif_data->channel), vif_reg->channel);
00253 }
00254 iwc_debug("------------------------------------------------------\n");
00255 }
00256
00258 void
00259 print_plain_msg(const char *message)
00260 {
00261 struct msg_header *header = (struct msg_header *) message;
00262 if (is_ack_msg(header))
00263 iwc_debug("[%4i bytes] =========== ACKNOWLEDGE MESSAGE =========\n",
00264 sizeof(struct plain_msg));
00265 if (is_deregistration_msg(header))
00266 iwc_debug("[%4i bytes] =========== DEREGISTRATION MESSAGE ======\n",
00267 sizeof(struct plain_msg));
00268 iwc_debug("[%4i bytes] ,---------- msg_header ------------------\n",
00269 sizeof(struct msg_header));
00270 iwc_debug("(%4i bytes) | type:\t%i\n", sizeof(header->type), header->type);
00271 iwc_debug("(%4i bytes) | id:\t%s\n", sizeof(header->id), header->id);
00272 struct plain_msg *msg = (struct plain_msg *) message;
00273 iwc_debug("(%4i bytes) msg_id:\t%i\n", sizeof(uint8_t), msg->msg_id);
00274 iwc_debug("------------------------------------------------------\n");
00275 }
00276
00278 void
00279 debug_msg(const char *message)
00280 {
00281 struct msg_header *header = (struct msg_header *) message;
00282 switch (header->type)
00283 {
00284 case DATA_MSG:
00285 print_data_msg(message);
00286 break;
00287 case CONFIG_MSG:
00288 print_config_msg(message);
00289 break;
00290 case REGISTRATION_MSG:
00291 print_reg_msg(message);
00292 break;
00293 case ACK_MSG:
00294 print_plain_msg(message);
00295 break;
00296 case DEREGISTRATION_MSG:
00297 print_plain_msg(message);
00298 break;
00299 default:
00300 iwc_debug("Warning: unknown message\n");
00301 return;
00302 }
00303 }