nexmon – Blame information for rev 1
?pathlinks?
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 <wrapper.h> // wrapper definitions for functions that already exist in the firmware |
||
39 | #include <structs.h> // structures that are used by the code in the firmware |
||
40 | #include <helper.h> // useful helper functions |
||
41 | #include <patcher.h> // macros used to craete patches such as BLPatch, BPatch, ... |
||
42 | #include <nexioctls.h> // ioctls added in the nexmon patch |
||
43 | #include <capabilities.h> // capabilities included in a nexmon patch |
||
44 | #include <sendframe.h> // sendframe functionality |
||
45 | #include <objmem.h> // Functions to access object memory |
||
46 | #include <ieee80211_radiotap.h> // Radiotap header related |
||
47 | #include <securitycookie.h> // Security cookie related |
||
48 | #include <version.h> // version information |
||
49 | #include <argprintf.h> // allows to execute argprintf to print into the arg buffer |
||
50 | |||
51 | int |
||
52 | wlc_ioctl_4xx(struct wlc_info *wlc, int cmd, char *arg, int len, void *wlc_if) |
||
53 | { |
||
54 | int ret = IOCTL_ERROR; |
||
55 | |||
56 | switch (cmd) { |
||
57 | |||
58 | case NEX_GET_CAPABILITIES: |
||
59 | // sends back the chips capabilities |
||
60 | if (len == 4) { |
||
61 | memcpy(arg, &capabilities, 4); |
||
62 | ret = IOCTL_SUCCESS; |
||
63 | } |
||
64 | break; |
||
65 | |||
66 | case NEX_WRITE_TO_CONSOLE: |
||
67 | // writes the string from arg to the console |
||
68 | if (len > 0) { |
||
69 | arg[len-1] = 0; |
||
70 | printf("ioctl: %s\n", arg); |
||
71 | ret = IOCTL_SUCCESS; |
||
72 | } |
||
73 | break; |
||
74 | /* |
||
75 | case NEX_GET_PHYREG: |
||
76 | // reads the value from arg[0] to arg[0] |
||
77 | if(wlc->hw->up && len >= 4) { |
||
78 | wlc_phyreg_enter(wlc->band->pi); |
||
79 | *(int *) arg = phy_reg_read(wlc->band->pi, ((int *) arg)[0]); |
||
80 | wlc_phyreg_exit(wlc->band->pi); |
||
81 | ret = IOCTL_SUCCESS; |
||
82 | } |
||
83 | break; |
||
84 | |||
85 | case NEX_SET_PHYREG: |
||
86 | // writes the value arg[1] to physical layer register arg[0] |
||
87 | if(wlc->hw->up && len >= 8) { |
||
88 | wlc_phyreg_enter(wlc->band->pi); |
||
89 | phy_reg_write(wlc->band->pi, ((int *) arg)[1], ((int *) arg)[0]); |
||
90 | wlc_phyreg_exit(wlc->band->pi); |
||
91 | ret = IOCTL_SUCCESS; |
||
92 | } |
||
93 | break; |
||
94 | |||
95 | case NEX_READ_OBJMEM: |
||
96 | if(wlc->hw->up && len >= 4) |
||
97 | { |
||
98 | int addr = ((int *) arg)[0]; |
||
99 | int i = 0; |
||
100 | |||
101 | for (i = 0; i < len/4; i++) { |
||
102 | wlc_bmac_read_objmem32_objaddr(wlc->hw, addr + i, &((unsigned int *) arg)[i]); |
||
103 | } |
||
104 | |||
105 | ret = IOCTL_SUCCESS; |
||
106 | } |
||
107 | break; |
||
108 | |||
109 | case NEX_WRITE_OBJMEM: |
||
110 | if(wlc->hw->up && len >= 5) |
||
111 | { |
||
112 | int addr = ((int *) arg)[0]; |
||
113 | int i = 0; |
||
114 | |||
115 | for (i = 0; i < (len-4)/8; i+=2) { |
||
116 | wlc_bmac_write_objmem64_objaddr(wlc->hw, addr + i, ((unsigned int *) arg)[i + 1], ((unsigned int *) arg)[i + 2]); |
||
117 | } |
||
118 | |||
119 | switch((len-4) % 8) { |
||
120 | case 4: |
||
121 | wlc_bmac_write_objmem32_objaddr(wlc->hw, addr + i, ((unsigned int *) arg)[i + 1]); |
||
122 | break; |
||
123 | } |
||
124 | |||
125 | ret = IOCTL_SUCCESS; |
||
126 | } |
||
127 | break; |
||
128 | |||
129 | case NEX_INJECT_FRAME: |
||
130 | { |
||
131 | sk_buff *p; |
||
132 | int bytes_used = 0; |
||
133 | struct inject_frame *frm = (struct inject_frame *) arg; |
||
134 | |||
135 | while ((frm->len > 0) && (bytes_used + frm->len <= len)) { |
||
136 | // add a dummy radiotap header if frame does not contain one |
||
137 | if (frm->type == 0) { |
||
138 | p = pkt_buf_get_skb(wlc->osh, frm->len + 202 + 8 - 4); |
||
139 | skb_pull(p, 202); |
||
140 | struct ieee80211_radiotap_header *radiotap = |
||
141 | (struct ieee80211_radiotap_header *) p->data; |
||
142 | |||
143 | memset(radiotap, 0, sizeof(struct ieee80211_radiotap_header)); |
||
144 | |||
145 | radiotap->it_len = 8; |
||
146 | |||
147 | skb_pull(p, 8); |
||
148 | memcpy(p->data, frm->data, frm->len - 4); |
||
149 | skb_push(p, 8); |
||
150 | } else { |
||
151 | p = pkt_buf_get_skb(wlc->osh, frm->len + 202 - 4); |
||
152 | skb_pull(p, 202); |
||
153 | |||
154 | memcpy(p->data, frm->data, frm->len - 4); |
||
155 | } |
||
156 | |||
157 | inject_frame(wlc, p); |
||
158 | |||
159 | bytes_used += frm->len; |
||
160 | |||
161 | frm = (struct inject_frame *) (arg + bytes_used); |
||
162 | } |
||
163 | |||
164 | ret = IOCTL_SUCCESS; |
||
165 | } |
||
166 | break; |
||
167 | |||
168 | case NEX_PRINT_TIMERS: |
||
169 | { |
||
170 | struct _ctimeout *timers = (struct _ctimeout *) 0x180E6C; |
||
171 | struct _ctimeout *this; |
||
172 | int bytes_written = 0; |
||
173 | |||
174 | if ((this = timers->next) == 0) { |
||
175 | printf("No timers\n"); |
||
176 | ret = IOCTL_ERROR; |
||
177 | } else { |
||
178 | while (this != 0 && len >= bytes_written + 64) { |
||
179 | bytes_written += sprintf(arg + bytes_written, |
||
180 | "timer %p, fun %p, arg %p, %d ms\n", |
||
181 | this, this->fun, this->arg, this->ms); |
||
182 | this = this->next; |
||
183 | } |
||
184 | |||
185 | ret = IOCTL_SUCCESS; |
||
186 | } |
||
187 | } |
||
188 | break; |
||
189 | |||
190 | case NEX_GET_SECURITYCOOKIE: |
||
191 | if (len == 4) { |
||
192 | *(int *) arg = get_securitycookie(); |
||
193 | ret = IOCTL_SUCCESS; |
||
194 | } |
||
195 | break; |
||
196 | |||
197 | case NEX_SET_SECURITYCOOKIE: |
||
198 | if (len == 4) { |
||
199 | set_securitycookie(*(int *) arg); |
||
200 | ret = IOCTL_SUCCESS; |
||
201 | } |
||
202 | break; |
||
203 | |||
204 | case NEX_GET_WL_CNT: |
||
205 | if (len >= sizeof(wl_cnt_t)) { |
||
206 | wlc_statsupd(wlc); |
||
207 | memcpy(arg, wlc->pub->_cnt, sizeof(wl_cnt_t)); |
||
208 | ret = IOCTL_SUCCESS; |
||
209 | } |
||
210 | break; |
||
211 | */ |
||
212 | case NEX_GET_VERSION_STRING: |
||
213 | { |
||
214 | int strlen = 0; |
||
215 | for ( strlen = 0; version[strlen]; ++strlen ); |
||
216 | if (len >= strlen) { |
||
217 | memcpy(arg, version, strlen); |
||
218 | ret = IOCTL_SUCCESS; |
||
219 | } |
||
220 | } |
||
221 | break; |
||
222 | |||
223 | } |
||
224 | |||
225 | return ret; |
||
226 | } |