/src/ndpi/src/lib/protocols/ubntac2.c
Line | Count | Source |
1 | | /* |
2 | | * ubntac2.c |
3 | | * |
4 | | * Copyright (C) 2015 Thomas Fjellstrom |
5 | | * |
6 | | * nDPI is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * nDPI 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 Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
18 | | * |
19 | | */ |
20 | | |
21 | | |
22 | | #include "ndpi_protocol_ids.h" |
23 | | |
24 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UBNTAC2 |
25 | | |
26 | | #include "ndpi_api.h" |
27 | | #include "ndpi_private.h" |
28 | | |
29 | | static void ndpi_int_ubntac2_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) |
30 | 0 | { |
31 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_UBNTAC2, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
32 | 0 | } |
33 | | |
34 | | |
35 | | static void ndpi_search_ubntac2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) |
36 | 0 | { |
37 | 0 | struct ndpi_packet_struct *packet = &ndpi_struct->packet; |
38 | 0 | u_int8_t tlv_type; |
39 | 0 | u_int16_t tlv_length, version_len; |
40 | 0 | int off; |
41 | |
|
42 | 0 | NDPI_LOG_DBG(ndpi_struct, "search ubntac2\n"); |
43 | |
|
44 | 0 | if(packet->payload_packet_len >= 4 && |
45 | 0 | (packet->udp->source == htons(10001) || packet->udp->dest == htons(10001)) && |
46 | 0 | (ntohs(get_u_int16_t(packet->payload, 0)) == 0x0206 || |
47 | 0 | ntohs(get_u_int16_t(packet->payload, 0)) == 0x0100 /* discovery request/reply */) && |
48 | 0 | (4 + ntohs(*(u_int16_t *)&packet->payload[2]) == packet->payload_packet_len)) { |
49 | 0 | NDPI_LOG_INFO(ndpi_struct, "UBNT AirControl 2 request\n"); |
50 | 0 | ndpi_int_ubntac2_add_connection(ndpi_struct, flow); |
51 | | |
52 | | /* Parse TLV list: 1 byte type + 2 byte length + (optional) data */ |
53 | 0 | off = 4; |
54 | 0 | while (off + 3 < packet->payload_packet_len) { |
55 | 0 | tlv_type = packet->payload[off]; |
56 | 0 | tlv_length = ntohs(*(u_int16_t *)&packet->payload[off + 1]); |
57 | |
|
58 | 0 | NDPI_LOG_DBG2(ndpi_struct, "0x%x Len %d\n", tlv_type, tlv_length); |
59 | |
|
60 | 0 | if(tlv_type == 0x03 && off + 3 + tlv_length < packet->payload_packet_len) { |
61 | 0 | version_len = ndpi_min(sizeof(flow->protos.ubntac2.version) - 1, tlv_length); |
62 | 0 | memcpy(flow->protos.ubntac2.version, (const char *)&packet->payload[off + 3], version_len); |
63 | 0 | flow->protos.ubntac2.version[version_len] = '\0'; |
64 | 0 | } |
65 | |
|
66 | 0 | off += 3 + tlv_length; |
67 | 0 | } |
68 | 0 | return; |
69 | 0 | } |
70 | | |
71 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
72 | 0 | } |
73 | | |
74 | | |
75 | | void init_ubntac2_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
76 | 0 | { |
77 | 0 | register_dissector("UBNTAC2", ndpi_struct, |
78 | 0 | ndpi_search_ubntac2, |
79 | 0 | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD, |
80 | 0 | 1, NDPI_PROTOCOL_UBNTAC2); |
81 | 0 | } |