1 /* Metageek WiSPY network protocol interface 2 * Mike Kershaw/Dragorn <dragorn@kismetwireless.net> 3 * 4 * Generic WiSPY userspace container for the Metageek WiSPY 5 * 6 * This code is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This code is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * Extra thanks to Ryan Woodings @ Metageek for interface documentation 17 */ 18 19 /* 20 * Implementation of the spectool network protocol 21 * {published url goes here} 22 * 23 * All multibyte values are expected to be big-endian 24 * 25 * Frames may contain multiple blocks. These blocks must be of the same 26 * type. Stacking is at the discretion of the sender, and is intended for 27 * optimization to the TCP window size 28 * 29 * All sub-frame types contain a total frame length for future expandability. 30 * 31 * !!! NOTE !!! 32 * THIS IS NOT THE FINAL SPECTOOL PROTOCOL, DON'T USE THIS EXPECTING IT TO STAY 33 * THE SAME, THIS IS KLUGED TOGETHER AS A PROTOTYPE BEFORE THE FINAL PROTOCOL 34 * IS DEFINED BY METAGEEK. 35 * 36 */ 37 38 #ifndef __SPECTOOL_NET_H__ 39 #define __SPECTOOL_NET_H__ 40 41 #include "config.h" 42 43 #ifdef HAVE_STDINT 44 #include <stdint.h> 45 #endif 46 47 #ifdef HAVE_INTTYPES_H 48 #include <inttypes.h> 49 #endif 50 51 /* WiSPY Network Protocol 52 * 53 * Multiple (homogenous) subframes may be aggregated into a single frame 54 * header at the discretion of the server in order to optimize packing into 55 * frames. 56 * 57 * Subframes of different types cannot be mixed in a single header. 58 */ 59 60 #define SPECTOOL_NET_FRAME_DEVICE 0x00 61 #define SPECTOOL_NET_FRAME_SWEEP 0x01 62 #define SPECTOOL_NET_FRAME_COMMAND 0x02 63 #define SPECTOOL_NET_FRAME_MESSAGE 0x03 64 65 #define SPECTOOL_NET_SENTINEL 0xDECAFBAD 66 67 #define SPECTOOL_NET_PROTO_VERSION 0x01 68 69 #define SPECTOOL_NET_DEFAULT_PORT 30569 70 71 typedef struct _spectool_fr_header { 72 uint32_t sentinel; 73 uint16_t frame_len; 74 uint8_t proto_version; 75 uint8_t block_type; 76 uint8_t num_blocks; 77 uint8_t data[0]; 78 } __attribute__ ((packed)) spectool_fr_header; 79 /* Size of a container header */ 80 #define spectool_fr_header_size() (sizeof(spectool_fr_header)) 81 82 #define SPECTOOL_NET_SWEEPTYPE_CUR 0x01 83 #define SPECTOOL_NET_SWEEPTYPE_AVG 0x02 84 #define SPECTOOL_NET_SWEEPTYPE_PEAK 0x03 85 86 typedef struct _spectool_fr_sweep { 87 uint16_t frame_len; 88 uint32_t device_id; 89 uint8_t sweep_type; 90 uint32_t start_sec; 91 uint32_t start_usec; 92 uint8_t sample_data[0]; 93 } __attribute__ ((packed)) spectool_fr_sweep; 94 /* Size of a sweep of N samples */ 95 #define spectool_fr_sweep_size(x) (sizeof(spectool_fr_sweep) + (x)) 96 97 #define SPECTOOL_NET_DEVTYPE_USB1 0x01 98 #define SPECTOOL_NET_DEVTYPE_USB2 0x02 99 #define SPECTOOL_NET_DEVTYPE_LASTDEV 0xFF 100 101 #define SPECTOOL_NET_DEVFLAG_NONE 0x00 102 #define SPECTOOL_NET_DEVFLAG_VARSWEEP 0x01 103 #define SPECTOOL_NET_DEVFLAG_LOCKED 0x02 104 105 typedef struct _spectool_fr_device { 106 uint16_t frame_len; 107 uint8_t device_version; 108 uint16_t device_flags; 109 uint32_t device_id; 110 uint8_t device_name_len; 111 uint8_t device_name[256]; 112 113 uint32_t amp_offset_mdbm; 114 uint32_t amp_res_mdbm; 115 uint16_t rssi_max; 116 117 uint32_t def_start_khz; 118 uint32_t def_res_hz; 119 uint16_t def_num_samples; 120 121 uint32_t start_khz; 122 uint32_t res_hz; 123 uint16_t num_samples; 124 } __attribute__ ((packed)) spectool_fr_device; 125 /* Size of a device frame of N sample definitions */ 126 #define spectool_fr_device_size() (sizeof(spectool_fr_device)) 127 128 #define SPECTOOL_NET_TXTTYPE_INFO 0x00 129 #define SPECTOOL_NET_TXTTYPE_ERROR 0x01 130 #define SPECTOOL_NET_TXTTYPE_FATAL 0x02 131 typedef struct _spectool_fr_txtmessage { 132 uint16_t frame_len; 133 uint8_t message_type; 134 uint16_t message_len; 135 uint8_t message[0]; 136 } __attribute__ ((packed)) spectool_fr_txtmessage; 137 /* Size of a text message of N characters */ 138 #define spectool_fr_txtmessage_size(x) (sizeof(spectool_fr_txtmessage) + (x)) 139 140 #define SPECTOOL_NET_COMMAND_NULL 0x00 141 #define SPECTOOL_NET_COMMAND_ENABLEDEV 0x01 142 #define SPECTOOL_NET_COMMAND_DISABLEDEV 0x02 143 #define SPECTOOL_NET_COMMAND_SETSCAN 0x03 144 #define SPECTOOL_NET_COMMAND_LOCK 0x04 145 #define SPECTOOL_NET_COMMAND_UNLOCK 0x05 146 typedef struct _spectool_fr_command { 147 uint16_t frame_len; 148 uint8_t command_id; 149 uint16_t command_len; 150 uint8_t command_data[0]; 151 } __attribute__ ((packed)) spectool_fr_command; 152 #define spectool_fr_command_size(x) (sizeof(spectool_fr_command) + (x)) 153 154 typedef struct _spectool_fr_command_enabledev { 155 uint32_t device_id; 156 } __attribute__ ((packed)) spectool_fr_command_enabledev; 157 #define spectool_fr_command_enabledev_size(x) (sizeof(spectool_fr_command_enabledev)) 158 159 typedef struct _spectool_fr_command_disabledev { 160 uint32_t device_id; 161 } __attribute__ ((packed)) spectool_fr_command_disabledev; 162 #define spectool_fr_command_disabledev_size(x) (sizeof(spectool_fr_command_disabledev)) 163 164 typedef struct _spectool_fr_command_setscan { 165 uint32_t device_id; 166 uint32_t start_khz; 167 uint32_t res_hz; 168 uint32_t filter_bw_hz; 169 uint16_t sweep_points; 170 uint8_t lock_dev; 171 } __attribute__ ((packed)) spectool_fr_command_setscan; 172 #define spectool_fr_command_setscan_size(x) (sizeof(spectool_fr_command_setscan)) 173 174 typedef struct _spectool_fr_command_lockdev { 175 uint32_t device_id; 176 } __attribute__ ((packed)) spectool_fr_command_lockdev; 177 #define spectool_fr_command_lockdev_size(x) (sizeof(spectool_fr_command_lockdev)) 178 179 typedef struct _spectool_fr_command_unlockdev { 180 uint32_t device_id; 181 } __attribute__ ((packed)) spectool_fr_command_unlockdev; 182 #define spectool_fr_command_unlockdev_size(x) (sizeof(spectool_fr_command_unlockdev)) 183 184 typedef struct _spectool_fr_broadcast { 185 uint32_t sentinel; 186 uint8_t version; 187 uint16_t server_port; 188 } __attribute__ ((packed)) spectool_fr_broadcast; 189 190 #endif 191 192