forked from rsta2/circle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbcm4343.cpp
More file actions
238 lines (182 loc) · 5.06 KB
/
bcm4343.cpp
File metadata and controls
238 lines (182 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// bcm4343.cpp
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2020 R. Stange <rsta2@o2online.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include <wlan/bcm4343.h>
#include <wlan/p9compat.h>
#include <circle/sysconfig.h>
#include <assert.h>
#if RASPPI <= 3 && !defined (USE_SDHOST)
#warning WLAN cannot be used parallel with SD card access in this configuration!
#endif
extern "C" void ether4330link (void);
static ether_pnp_t *s_pEtherPnpHandler = 0;
static Ether s_EtherDevice;
CBcm4343Device *CBcm4343Device::s_pThis = 0;
CBcm4343Device::CBcm4343Device (const char *pFirmwarePath)
: m_FirmwarePath (pFirmwarePath)
{
s_pThis = this;
}
CBcm4343Device::~CBcm4343Device (void)
{
assert (s_EtherDevice.shutdown != 0);
(*s_EtherDevice.shutdown) (&s_EtherDevice);
delete s_EtherDevice.oq;
s_pThis = 0;
}
boolean CBcm4343Device::Initialize (void)
{
p9arch_init ();
p9chan_init (m_FirmwarePath);
p9proc_init ();
ether4330link ();
assert (s_pEtherPnpHandler != 0);
(*s_pEtherPnpHandler) (&s_EtherDevice);
s_EtherDevice.oq = new Queue;
memset (s_EtherDevice.oq, 0, sizeof *s_EtherDevice.oq);
if (waserror ())
{
return FALSE;
}
assert (s_EtherDevice.attach != 0);
(*s_EtherDevice.attach) (&s_EtherDevice);
m_MACAddress.Set (s_EtherDevice.ea);
AddNetDevice ();
poperror ();
return TRUE;
}
const CMACAddress *CBcm4343Device::GetMACAddress (void) const
{
return &m_MACAddress;
}
boolean CBcm4343Device::SendFrame (const void *pBuffer, unsigned nLength)
{
//hexdump (pBuffer, nLength, "wlantx");
Block *pBlock = allocb (nLength);
assert (pBlock != 0);
assert (pBlock->wp != 0);
assert (pBuffer != 0);
memcpy (pBlock->wp, pBuffer, nLength);
pBlock->wp += nLength;
assert (s_EtherDevice.oq != 0);
qpass (s_EtherDevice.oq, pBlock);
if (waserror ())
{
return FALSE;
}
assert (s_EtherDevice.transmit != 0);
(*s_EtherDevice.transmit) (&s_EtherDevice);
poperror ();
return TRUE;
}
boolean CBcm4343Device::ReceiveFrame (void *pBuffer, unsigned *pResultLength)
{
assert (pBuffer != 0);
unsigned nLength = m_RxQueue.Dequeue (pBuffer);
if (nLength == 0)
{
return FALSE;
}
assert (pResultLength != 0);
*pResultLength = nLength;
//hexdump (pBuffer, nLength, "wlanrx");
return TRUE;
}
void CBcm4343Device::RegisterEventHandler (TBcm4343EventHandler *pHandler, void *pContext)
{
assert (s_EtherDevice.setevhndlr != 0);
(*s_EtherDevice.setevhndlr) (&s_EtherDevice, pHandler, pContext);
}
boolean CBcm4343Device::Control (const char *pFormat, ...)
{
assert (pFormat != 0);
va_list var;
va_start (var, pFormat);
CString Command;
Command.FormatV (pFormat, var);
va_end (var);
if (waserror ())
{
return FALSE;
}
assert (s_EtherDevice.ctl != 0);
(*s_EtherDevice.ctl) (&s_EtherDevice, (const char *) Command, 0);
poperror ();
return TRUE;
}
boolean CBcm4343Device::ReceiveScanResult (void *pBuffer, unsigned *pResultLength)
{
assert (pBuffer != 0);
unsigned nLength = m_ScanResultQueue.Dequeue (pBuffer);
if (nLength == 0)
{
return FALSE;
}
assert (pResultLength != 0);
*pResultLength = nLength;
//hexdump (pBuffer, nLength, "wlanscan");
return TRUE;
}
const CMACAddress *CBcm4343Device::GetBSSID (void)
{
u8 BSSID[MAC_ADDRESS_SIZE];
assert (s_EtherDevice.getbssid != 0);
(*s_EtherDevice.getbssid) (&s_EtherDevice, BSSID);
m_BSSID.Set (BSSID);
return &m_BSSID;
}
boolean CBcm4343Device::JoinOpenNet (const char *pSSID)
{
assert (pSSID != 0);
return Control ("join %s %s 0 off", pSSID, "FFFFFFFFFFFF");
}
void CBcm4343Device::DumpStatus (void)
{
char Buffer[200];
assert (s_EtherDevice.ifstat != 0);
long nLength = (*s_EtherDevice.ifstat) (&s_EtherDevice, Buffer, sizeof Buffer, 0);
Buffer[nLength] = '\0';
print (Buffer);
}
void CBcm4343Device::FrameReceived (const void *pBuffer, unsigned nLength)
{
assert (s_pThis != 0);
s_pThis->m_RxQueue.Enqueue (pBuffer, nLength);
}
void CBcm4343Device::ScanResultReceived (const void *pBuffer, unsigned nLength)
{
assert (s_pThis != 0);
s_pThis->m_ScanResultQueue.Enqueue (pBuffer, nLength);
}
void etheriq (Ether *pEther, Block *pBlock, unsigned nFlag)
{
assert (pBlock != 0);
CBcm4343Device::FrameReceived (pBlock->rp, BLEN (pBlock));
freeb (pBlock);
}
void etherscanresult (Ether *pEther, const void *pBuffer, long nLength)
{
assert (pBuffer != 0);
CBcm4343Device::ScanResultReceived (pBuffer, (unsigned) nLength);
}
void addethercard (const char *pName, ether_pnp_t *pEtherPnpHandler)
{
assert (pEtherPnpHandler != 0);
s_pEtherPnpHandler = pEtherPnpHandler;
}