diff --git a/examples/wifi_rx.grc b/examples/wifi_rx.grc index 73fecbe..7af6c0a 100644 --- a/examples/wifi_rx.grc +++ b/examples/wifi_rx.grc @@ -24,6 +24,9 @@ options: title: '' window_size: 1280, 2048 states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [8, 12.0] rotation: 0 state: enabled @@ -52,6 +55,9 @@ blocks: value: '0' widget: radio_buttons states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [312, 12.0] rotation: 0 state: enabled @@ -106,9 +112,12 @@ blocks: 5910000000.0, 5920000000.0]' orient: Qt.QVBoxLayout type: real - value: '5890000000' + value: '5745000000' widget: combo_box states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [624, 12.0] rotation: 0 state: enabled @@ -127,6 +136,9 @@ blocks: value: '0.75' widget: counter_slider states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [488, 12.0] rotation: 0 state: enabled @@ -153,6 +165,9 @@ blocks: value: '0' widget: combo_box states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [176, 12.0] rotation: 0 state: enabled @@ -176,9 +191,12 @@ blocks: options: '[5e6, 10e6, 20e6]' orient: Qt.QVBoxLayout type: real - value: 10e6 + value: 5e6 widget: combo_box states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [800, 12.0] rotation: 0 state: enabled @@ -188,6 +206,9 @@ blocks: comment: '' value: '320' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [8, 133] rotation: 0 state: enabled @@ -197,6 +218,9 @@ blocks: comment: '' value: '48' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [8, 84.0] rotation: 0 state: enabled @@ -210,6 +234,9 @@ blocks: minoutbuf: '0' vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [1016, 312] rotation: 0 state: enabled @@ -223,6 +250,9 @@ blocks: minoutbuf: '0' vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [496, 208.0] rotation: 0 state: enabled @@ -235,6 +265,9 @@ blocks: maxoutbuf: '0' minoutbuf: '0' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [424, 328] rotation: 0 state: enabled @@ -251,6 +284,9 @@ blocks: type: complex vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [536, 540.0] rotation: 0 state: enabled @@ -267,6 +303,9 @@ blocks: type: complex vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [264, 324] rotation: 0 state: enabled @@ -282,6 +321,9 @@ blocks: type: float vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [1168, 400] rotation: 270 state: enabled @@ -297,9 +339,12 @@ blocks: unbuffered: 'True' vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [768, 908] rotation: 180 - state: disabled + state: enabled - name: blocks_moving_average_xx_0 id: blocks_moving_average_xx parameters: @@ -314,6 +359,9 @@ blocks: type: float vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [944, 180.0] rotation: 0 state: true @@ -331,6 +379,9 @@ blocks: type: complex vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [808, 284.0] rotation: 0 state: true @@ -346,6 +397,9 @@ blocks: type: complex vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [664, 296] rotation: 0 state: enabled @@ -360,6 +414,9 @@ blocks: tag: packet_len type: complex states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [584, 836] rotation: 180 state: enabled @@ -375,6 +432,9 @@ blocks: type: complex vlen: '1' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [944, 536.0] rotation: 0 state: enabled @@ -393,6 +453,9 @@ blocks: type: complex window: window.rectangular(64) states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [168, 672] rotation: 0 state: enabled @@ -407,9 +470,12 @@ blocks: minoutbuf: '0' tech: '127' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [952, 916] rotation: 180 - state: disabled + state: enabled - name: ieee802_11_decode_mac_0 id: ieee802_11_decode_mac parameters: @@ -421,6 +487,9 @@ blocks: maxoutbuf: '0' minoutbuf: '0' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [864, 676] rotation: 0 state: enabled @@ -438,6 +507,9 @@ blocks: maxoutbuf: '0' minoutbuf: '0' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [432, 672] rotation: 0 state: enabled @@ -452,6 +524,9 @@ blocks: maxoutbuf: '0' minoutbuf: '0' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [984, 804] rotation: 180 state: enabled @@ -467,6 +542,9 @@ blocks: minoutbuf: '0' sync_length: sync_length states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [744, 508.0] rotation: 0 state: enabled @@ -483,6 +561,9 @@ blocks: minoutbuf: '0' threshold: '0.56' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [304, 488.0] rotation: 0 state: enabled @@ -572,6 +653,9 @@ blocks: ymax: '2' ymin: '-2' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [344, 828] rotation: 180 state: enabled @@ -592,16 +676,16 @@ blocks: alpha9: '1.0' autoscale: 'False' axislabels: 'True' - color1: '"blue"' - color10: '"blue"' - color2: '"red"' - color3: '"green"' - color4: '"black"' - color5: '"cyan"' - color6: '"magenta"' - color7: '"yellow"' - color8: '"dark red"' - color9: '"dark green"' + color1: blue + color10: dark blue + color2: red + color3: green + color4: black + color5: cyan + color6: magenta + color7: yellow + color8: dark red + color9: dark green comment: '' ctrlpanel: 'False' entags: 'True' @@ -666,6 +750,9 @@ blocks: ymin: '-1' yunit: '""' states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [1164, 520] rotation: 270 state: enabled @@ -1023,7 +1110,7 @@ blocks: show_lo_controls: 'False' stream_args: '' stream_chans: '[]' - sync: sync + sync: pc_clock time_source0: '' time_source1: '' time_source2: '' @@ -1034,6 +1121,9 @@ blocks: time_source7: '' type: fc32 states: + bus_sink: false + bus_source: false + bus_structure: null coordinate: [32, 216] rotation: 0 state: enabled diff --git a/lib/parse_mac.cc b/lib/parse_mac.cc index f50a7fc..c75347c 100644 --- a/lib/parse_mac.cc +++ b/lib/parse_mac.cc @@ -62,45 +62,32 @@ public: int frame_len = pmt::blob_length(d_msg); mac_header* h = (mac_header*)pmt::blob_data(d_msg); - mylog(boost::format("length: %1%") % frame_len); - - dout << std::endl << "new mac frame (length " << frame_len << ")" << std::endl; - dout << "=========================================" << std::endl; if (frame_len < 20) { - dout << "frame too short to parse (<20)" << std::endl; return; } d_meta = pmt::dict_add(d_meta, pmt::mp("Duration"), pmt::mp(h->duration)); #define HEX(a) std::hex << std::setfill('0') << std::setw(2) << int(a) << std::dec - dout << "duration: " << HEX(h->duration >> 8) << " " << HEX(h->duration & 0xff) - << std::endl; - dout << "frame control: " << HEX(h->frame_control >> 8) << " " - << HEX(h->frame_control & 0xff); switch ((h->frame_control >> 2) & 3) { case 0: d_meta = pmt::dict_add(d_meta, pmt::mp("Type"), pmt::mp("Management")); - dout << " (MANAGEMENT)" << std::endl; parse_management((char*)h, frame_len); break; case 1: d_meta = pmt::dict_add(d_meta, pmt::mp("Type"), pmt::mp("Control")); - dout << " (CONTROL)" << std::endl; parse_control((char*)h, frame_len); break; case 2: d_meta = pmt::dict_add(d_meta, pmt::mp("Type"), pmt::mp("Data")); - dout << " (DATA)" << std::endl; parse_data((char*)h, frame_len); break; default: d_meta = pmt::dict_add(d_meta, pmt::mp("Type"), pmt::mp("Unknown")); - dout << " (unknown)" << std::endl; break; } @@ -108,10 +95,8 @@ public: // DATA if ((((h->frame_control) >> 2) & 63) == 2) { - print_ascii(frame + 24, frame_len - 24); // QoS Data } else if ((((h->frame_control) >> 2) & 63) == 34) { - print_ascii(frame + 26, frame_len - 26); } message_port_pub(pmt::mp("out"), pmt::cons(d_meta, d_msg)); @@ -122,219 +107,247 @@ public: mac_header* h = (mac_header*)buf; if (length < 24) { - dout << "too short for a management frame" << std::endl; return; } - dout << "Subtype: "; switch (((h->frame_control) >> 4) & 0xf) { case 0: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Association Request")); - dout << "Association Request"; break; case 1: d_meta = pmt::dict_add( d_meta, pmt::mp("Subtype"), pmt::mp("Association Response")); - dout << "Association Response"; break; case 2: d_meta = pmt::dict_add( d_meta, pmt::mp("Subtype"), pmt::mp("Reassociation Request")); - dout << "Reassociation Request"; break; case 3: d_meta = pmt::dict_add( d_meta, pmt::mp("Subtype"), pmt::mp("Reassociation Response")); - dout << "Reassociation Response"; break; case 4: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Probe Request")); - dout << "Probe Request"; break; case 5: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Probe Response")); - dout << "Probe Response"; break; case 6: d_meta = pmt::dict_add( d_meta, pmt::mp("Subtype"), pmt::mp("Timing Advertisement")); - dout << "Timing Advertisement"; break; case 7: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Reserved")); - dout << "Reserved"; break; case 8: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Beacon")); - dout << "Beacon" << std::endl; + // Start parsing for DroneID data below here. if (length < 38) { return; } { + // MAC header == 36 bytes uint8_t* len = (uint8_t*)(buf + 24 + 13); if (length < 38 + *len) { return; } + std::string s(buf + 24 + 14, *len); d_meta = pmt::dict_add(d_meta, pmt::mp("SSID"), pmt::mp(s)); - dout << "SSID: " << s; + + #define DEBUG 0 + if (buf[length-5] == 'a' && buf[length-4] == 'd' && buf[length-3] == 'h' && buf[length-2] == 'o' && buf[length-1] == 'c') + { + #if DEBUG > 0 + printf("DJI Enhanced Wifi packet seen, Len: %i \n", length); + print_ascii(buf, length); + #endif + + if (length == 218) { + printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", buf[71], buf[72], buf[73], buf[74], buf[75], buf[76], buf[77], buf[78], buf[79], buf[80], buf[81], buf[82], buf[83], buf[84], buf[85], buf[86]); + } + else if (length == 220) { + printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", buf[73], buf[74], buf[75], buf[76], buf[77], buf[78], buf[79], buf[80], buf[81], buf[82], buf[83], buf[84], buf[85], buf[86], buf[87], buf[88]); + } + else if (length == 165) { + printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", buf[76], buf[77], buf[78], buf[79], buf[80], buf[81], buf[82], buf[83], buf[84], buf[85], buf[86], buf[87], buf[88], buf[89], buf[90], buf[91]); + } + else if (length == 167) { + printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", buf[78], buf[79], buf[80], buf[81], buf[82], buf[83], buf[84], buf[85], buf[86], buf[87], buf[88], buf[89], buf[90], buf[91], buf[92], buf[93]); + } + else if (length == 69 || length == 71 || length == 73) { + // idle drone, no props armed, or RC has lost connectivity & beaconing for reconnection + } + else { + printf("Len: %i \n", length); + print_ascii(buf, length); + } + } + else + { + printf("Unknown packet, Len: %i \n", length); + } } break; case 9: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("ATIM")); - dout << "ATIM"; break; case 10: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Disassociation")); - dout << "Disassociation"; break; case 11: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Authentication")); - dout << "Authentication"; break; case 12: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Deauthentication")); - dout << "Deauthentication"; break; case 13: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Action")); - dout << "Action"; break; case 14: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Action No Ack")); - dout << "Action No Ack"; break; case 15: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Reserved")); - dout << "Reserved"; break; default: break; } - dout << std::endl; int seq_no = int(h->seq_nr >> 4); d_meta = pmt::dict_add(d_meta, pmt::mp("Sequence number"), pmt::mp(seq_no)); - dout << "seq nr: " << seq_no << std::endl; + //dout << "seq nr: " << seq_no << std::endl; auto address = format_mac_address(h->addr1); d_meta = pmt::dict_add(d_meta, pmt::mp("Address 1"), pmt::mp(address)); - dout << "address 1: " << address << std::endl; + //dout << "address 1: " << address << std::endl; + parse_dji(address.c_str()); address = format_mac_address(h->addr2); d_meta = pmt::dict_add(d_meta, pmt::mp("Address 2"), pmt::mp(address)); - dout << "address 2: " << address << std::endl; + //dout << "address 2: " << address << std::endl; + parse_dji(address.c_str()); address = format_mac_address(h->addr3); d_meta = pmt::dict_add(d_meta, pmt::mp("Address 3"), pmt::mp(address)); - dout << "address 3: " << address << std::endl; + //dout << "address 3: " << address << std::endl; + parse_dji(address.c_str()); + } + #define DEBUG 0 + void parse_dji(const char* address) + { + // Check for known DJI MAC addresses here. + // Example: 34:D2:62:* - DJI EnhancedWifi + // 38:D2:62:* + // 60:60:1F:* + #if DEBUG > 0 + if (strstr(address,"34:d2:62:") ==address) { + printf("Dji: %s\n", address); + } + else if (strstr(address,"38:d2:62:") ==address) { + printf("Dji: %s\n", address); + } + else if (strstr(address,"60:60:1f:") ==address) { + printf("Dji: %s\n", address); + } + else if (strstr(address,"ff:ff:ff:") ==address) { + printf("Broadcast: %s\n", address); + } + else { + printf("Non-Dji: %s\n", address); + } + #endif + } void parse_data(char* buf, int length) { mac_header* h = (mac_header*)buf; if (length < 24) { - dout << "too short for a data frame" << std::endl; return; } - dout << "Subtype: "; switch (((h->frame_control) >> 4) & 0xf) { case 0: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Data")); - dout << "Data"; break; case 1: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Data + CF-ACK")); - dout << "Data + CF-ACK"; break; case 2: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Data + CR-Poll")); - dout << "Data + CR-Poll"; break; case 3: d_meta = pmt::dict_add( d_meta, pmt::mp("Subtype"), pmt::mp("Data + CF-ACK + CF-Poll")); - dout << "Data + CF-ACK + CF-Poll"; break; case 4: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Null")); - dout << "Null"; break; case 5: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-ACK")); - dout << "CF-ACK"; break; case 6: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-Poll")); - dout << "CF-Poll"; break; case 7: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-ACK + CF-Poll")); - dout << "CF-ACK + CF-Poll"; break; case 8: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data")); - dout << "QoS Data"; break; case 9: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-ACK")); - dout << "QoS Data + CF-ACK"; break; case 10: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-Poll")); - dout << "QoS Data + CF-Poll"; break; case 11: d_meta = pmt::dict_add( d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-ACK + CF-Poll")); - dout << "QoS Data + CF-ACK + CF-Poll"; break; case 12: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Null")); - dout << "QoS Null"; break; case 13: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Reserved")); - dout << "Reserved"; break; case 14: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS CF-Poll")); - dout << "QoS CF-Poll"; break; case 15: d_meta = pmt::dict_add( d_meta, pmt::mp("Subtype"), pmt::mp("QoS CF-ACK + CF-Poll")); - dout << "QoS CF-ACK + CF-Poll"; break; default: break; } - dout << std::endl; int seq_no = int(h->seq_nr >> 4); d_meta = pmt::dict_add(d_meta, pmt::mp("Sequence number"), pmt::mp(seq_no)); - dout << "seq nr: " << seq_no << std::endl; + //dout << "seq nr: " << seq_no << std::endl; auto address = format_mac_address(h->addr1); d_meta = pmt::dict_add(d_meta, pmt::mp("Address 1"), pmt::mp(address)); - dout << "address 1: " << address << std::endl; + //dout << "address 1: " << address << std::endl; + parse_dji(address.c_str()); address = format_mac_address(h->addr2); d_meta = pmt::dict_add(d_meta, pmt::mp("Address 2"), pmt::mp(address)); - dout << "address 2: " << address << std::endl; + //dout << "address 2: " << address << std::endl; + parse_dji(address.c_str()); address = format_mac_address(h->addr3); d_meta = pmt::dict_add(d_meta, pmt::mp("Address 3"), pmt::mp(address)); - dout << "address 3: " << address << std::endl; - + //dout << "address 3: " << address << std::endl; + parse_dji(address.c_str()); float lost_frames = seq_no - d_last_seq_no - 1; if (lost_frames < 0) @@ -343,7 +356,6 @@ public: // calculate frame error rate float fer = lost_frames / (lost_frames + 1); - dout << "instantaneous fer: " << fer << std::endl; d_meta = pmt::dict_add(d_meta, pmt::mp("Instantaneous FER"), pmt::mp(fer)); // keep track of sequence numbers @@ -359,48 +371,37 @@ public: case 7: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Control Wrapper")); - dout << "Control Wrapper"; break; case 8: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Block ACK Request")); - dout << "Block ACK Request"; break; case 9: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Block ACK")); - dout << "Block ACK"; break; case 10: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("PS Poll")); - dout << "PS Poll"; break; case 11: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("RTS")); - dout << "RTS"; break; case 12: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CTS")); - dout << "CTS"; break; case 13: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("ACK")); - dout << "ACK"; break; case 14: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-End")); - dout << "CF-End"; break; case 15: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-End + CF-ACK")); - dout << "CF-End + CF-ACK"; break; default: d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Reserved")); - dout << "Reserved"; break; } - dout << std::endl; auto address = format_mac_address(h->addr1); diff --git a/lib/sync_long.cc b/lib/sync_long.cc index 962928c..0ae02fa 100644 --- a/lib/sync_long.cc +++ b/lib/sync_long.cc @@ -109,7 +109,6 @@ public: if (d_offset == SYNC_LENGTH) { search_frame_start(); - mylog(boost::format("LONG: frame start at %1%") % d_frame_start); d_offset = 0; d_count = 0; d_state = COPY;