nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /***************************************************************************
2 * *
3 * ########### ########### ########## ########## *
4 * ############ ############ ############ ############ *
5 * ## ## ## ## ## ## ## *
6 * ## ## ## ## ## ## ## *
7 * ########### #### ###### ## ## ## ## ###### *
8 * ########### #### # ## ## ## ## # # *
9 * ## ## ###### ## ## ## ## # # *
10 * ## ## # ## ## ## ## # # *
11 * ############ ##### ###### ## ## ## ##### ###### *
12 * ########### ########### ## ## ## ########## *
13 * *
14 * S E C U R E M O B I L E N E T W O R K I N G *
15 * *
16 * This file is part of NexMon. *
17 * *
18 * Copyright (c) 2016 NexMon Team *
19 * *
20 * NexMon is free software: you can redistribute it and/or modify *
21 * it under the terms of the GNU General Public License as published by *
22 * the Free Software Foundation, either version 3 of the License, or *
23 * (at your option) any later version. *
24 * *
25 * NexMon is distributed in the hope that it will be useful, *
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
28 * GNU General Public License for more details. *
29 * *
30 * You should have received a copy of the GNU General Public License *
31 * along with NexMon. If not, see <http://www.gnu.org/licenses/>. *
32 * *
33 **************************************************************************/
34  
35 #pragma NEXMON targetregion "patch"
36  
37 #include <firmware_version.h> // definition of firmware version macros
38 //#include <debug.h> // contains macros to access the debug hardware
39 #include <wrapper.h> // wrapper definitions for functions that already exist in the firmware
40 #include <structs.h> // structures that are used by the code in the firmware
41 #include <helper.h> // useful helper functions
42 #include <patcher.h> // macros used to craete patches such as BLPatch, BPatch, ...
43 //#include <rates.h> // rates used to build the ratespec for frame injection
44 //#include <bcmwifi_channels.h>
45 //#include <ieee80211_radiotap.h> // radiotap header related
46 //#include <vendor_radiotap.h> // vendor specific radiotap extensions
47 //#include <sendframe.h> // sendframe functionality
48 //#include <securitycookie.h> // related to securtiy cookie
49  
50 struct ethernet_ip_udp_header ethernet_ipv4_udp_header = {
51 .ethernet = {
52 .dst = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
53 .src = { 'N', 'E', 'X', 'M', 'O', 'N' },
54 .type = 0x0008
55 },
56 .ip = {
57 .version_ihl = 0x45,
58 .dscp_ecn = 0x00,
59 .total_length = 0x0000,
60 .identification = 0x0100,
61 .flags_fragment_offset = 0x0000,
62 .ttl = 0x01,
63 .protocol = 0x11,
64 .header_checksum = 0x0000,
65 .src_ip.array = { 10, 10, 10, 10 },
66 .dst_ip.array = { 255, 255, 255, 255 }
67 },
68 .udp = {
69 .src_port = HTONS(5500),
70 .dst_port = HTONS(5500),
71 .len_chk_cov.length = 0x0000,
72 .checksum = 0x0000
73 }
74 };
75  
76 /**
77 * Calculates the IPv4 header checksum given the total IPv4 packet length.
78 *
79 * This checksum is specific to the packet format above. This is not a full
80 * implementation of the checksum algorithm. Instead, as much as possible is
81 * precalculated to reduce the amount of computation needed. This calculation
82 * is accurate for total lengths up to 42457.
83 */
84 static inline uint16_t
85 calc_checksum(uint16_t total_len)
86 {
87 return ~(23078 + total_len);
88 }
89  
90 void
91 prepend_ethernet_ipv4_udp_header(struct sk_buff *p)
92 {
93 ethernet_ipv4_udp_header.ip.total_length = htons(p->len + sizeof(struct ip_header) + sizeof(struct udp_header));
94 ethernet_ipv4_udp_header.ip.header_checksum = htons(calc_checksum(p->len + sizeof(struct ip_header) + sizeof(struct udp_header)));
95 ethernet_ipv4_udp_header.udp.len_chk_cov.length = htons(p->len + sizeof(struct udp_header));
96  
97 skb_push(p, sizeof(ethernet_ipv4_udp_header));
98 memcpy(p->data, &ethernet_ipv4_udp_header, sizeof(ethernet_ipv4_udp_header));
99 }
100  
101 void
102 udpnprintf(struct wl_info *wl, unsigned int n, const char *format, ...)
103 {
104 va_list args;
105 int len = 0;
106 struct sk_buff *p = pkt_buf_get_skb(wl->wlc->osh, sizeof(struct ethernet_ip_udp_header) + n);
107  
108 if (p != 0) {
109 skb_pull(p, sizeof(struct ethernet_ip_udp_header));
110  
111 va_start(args, format);
112 len = vsnprintf(p->data, n, format, args);
113 va_end(args);
114  
115 p->len = len;
116  
117 prepend_ethernet_ipv4_udp_header(p);
118  
119 wl->dev->chained->funcs->xmit(wl->dev, wl->dev->chained, p);
120 }
121 }
122  
123 void
124 udpprintf(struct wl_info *wl, const char *format, ...)
125 {
126 va_list args;
127 int len = 0;
128 struct sk_buff *p = pkt_buf_get_skb(wl->wlc->osh, sizeof(struct ethernet_ip_udp_header) + 1000);
129  
130 if (p != 0) {
131 skb_pull(p, sizeof(struct ethernet_ip_udp_header));
132  
133 va_start(args, format);
134 len = vsnprintf(p->data, 1000, format, args);
135 va_end(args);
136  
137 p->len = len;
138  
139 prepend_ethernet_ipv4_udp_header(p);
140  
141 wl->dev->chained->funcs->xmit(wl->dev, wl->dev->chained, p);
142 }
143 }