5
5
*/
6
6
#include "usbd_core.h"
7
7
#include "usbd_rndis.h"
8
+ #include "dhserver.h"
9
+ #include "dnserver.h"
8
10
9
11
#ifndef CONFIG_USBDEV_RNDIS_USING_LWIP
10
12
#error "Please enable CONFIG_USBDEV_RNDIS_USING_LWIP for this demo"
@@ -175,10 +177,11 @@ static const uint8_t cdc_rndis_descriptor[] = {
175
177
#endif
176
178
177
179
const uint8_t mac [6 ] = { 0xaa , 0xbb , 0xcc , 0xdd , 0xee , 0xff };
180
+
178
181
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
179
182
#define IP_ADDR0 (uint8_t)192
180
183
#define IP_ADDR1 (uint8_t)168
181
- #define IP_ADDR2 (uint8_t)123
184
+ #define IP_ADDR2 (uint8_t)7
182
185
#define IP_ADDR3 (uint8_t)100
183
186
184
187
/*NETMASK*/
@@ -190,18 +193,45 @@ const uint8_t mac[6] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
190
193
/*Gateway Address*/
191
194
#define GW_ADDR0 (uint8_t)192
192
195
#define GW_ADDR1 (uint8_t)168
193
- #define GW_ADDR2 (uint8_t)123
196
+ #define GW_ADDR2 (uint8_t)7
194
197
#define GW_ADDR3 (uint8_t)1
195
198
199
+ const ip_addr_t ipaddr = IPADDR4_INIT_BYTES (IP_ADDR0 , IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
200
+ const ip_addr_t netmask = IPADDR4_INIT_BYTES (NETMASK_ADDR0 , NETMASK_ADDR1 , NETMASK_ADDR2 , NETMASK_ADDR3 );
201
+ const ip_addr_t gateway = IPADDR4_INIT_BYTES (GW_ADDR0 , GW_ADDR1 , GW_ADDR2 , GW_ADDR3 );
202
+
203
+ #define NUM_DHCP_ENTRY 3
204
+
205
+ static dhcp_entry_t entries [NUM_DHCP_ENTRY ] = {
206
+ /* mac ip address subnet mask lease time */
207
+ { { 0 }, { 192 , 168 , 7 , 2 }, { 255 , 255 , 255 , 0 }, 24 * 60 * 60 },
208
+ { { 0 }, { 192 , 168 , 7 , 3 }, { 255 , 255 , 255 , 0 }, 24 * 60 * 60 },
209
+ { { 0 }, { 192 , 168 , 7 , 4 }, { 255 , 255 , 255 , 0 }, 24 * 60 * 60 }
210
+ };
211
+
212
+ static dhcp_config_t dhcp_config = {
213
+ { 192 , 168 , 7 , 1 }, /* server address */
214
+ 67 , /* port */
215
+ { 192 , 168 , 7 , 1 }, /* dns server */
216
+ "cherry" , /* dns suffix */
217
+ NUM_DHCP_ENTRY , /* num entry */
218
+ entries /* entries */
219
+ };
220
+
221
+ static bool dns_query_proc (const char * name , ip_addr_t * addr )
222
+ {
223
+ if (strcmp (name , "rndis.cherry" ) == 0 || strcmp (name , "www.rndis.cherry" ) == 0 ) {
224
+ addr -> addr = * (uint32_t * )ipaddr ;
225
+ return true;
226
+ }
227
+ return false;
228
+ }
229
+
196
230
#ifdef RT_USING_LWIP
197
231
#include <rtthread.h>
198
232
#include <rtdevice.h>
199
233
#include <netif/ethernetif.h>
200
234
201
- const ip_addr_t ipaddr = IPADDR4_INIT_BYTES (IP_ADDR0 , IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
202
- const ip_addr_t netmask = IPADDR4_INIT_BYTES (NETMASK_ADDR0 , NETMASK_ADDR1 , NETMASK_ADDR2 , NETMASK_ADDR3 );
203
- const ip_addr_t gateway = IPADDR4_INIT_BYTES (GW_ADDR0 , GW_ADDR1 , GW_ADDR2 , GW_ADDR3 );
204
-
205
235
struct eth_device rndis_dev ;
206
236
207
237
static rt_err_t rt_usbd_rndis_control (rt_device_t dev , int cmd , void * args )
@@ -243,7 +273,7 @@ void usbd_rndis_data_recv_done(uint32_t len)
243
273
eth_device_ready (& rndis_dev );
244
274
}
245
275
246
- void rt_usbd_rndis_init (void )
276
+ void rndis_lwip_init (void )
247
277
{
248
278
rndis_dev .parent .control = rt_usbd_rndis_control ;
249
279
rndis_dev .eth_rx = rt_usbd_rndis_eth_rx ;
@@ -259,10 +289,6 @@ void rt_usbd_rndis_init(void)
259
289
#include "lwip/netif.h"
260
290
#include "lwip/pbuf.h"
261
291
262
- const ip_addr_t ipaddr = IPADDR4_INIT_BYTES (IP_ADDR0 , IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
263
- const ip_addr_t netmask = IPADDR4_INIT_BYTES (NETMASK_ADDR0 , NETMASK_ADDR1 , NETMASK_ADDR2 , NETMASK_ADDR3 );
264
- const ip_addr_t gateway = IPADDR4_INIT_BYTES (GW_ADDR0 , GW_ADDR1 , GW_ADDR2 , GW_ADDR3 );
265
-
266
292
static struct netif rndis_netif ; //network interface
267
293
268
294
/* Network interface name */
@@ -328,7 +354,7 @@ void rndis_lwip_init(void)
328
354
329
355
while (dhserv_init (& dhcp_config )) {}
330
356
331
- while (dnserv_init (& ipaddr , PORT_DNS , dns_query_proc )) {}
357
+ while (dnserv_init (IP_ADDR_ANY , 53 , dns_query_proc )) {}
332
358
}
333
359
334
360
void usbd_rndis_data_recv_done (uint32_t len )
@@ -374,11 +400,8 @@ struct usbd_interface intf1;
374
400
375
401
void cdc_rndis_init (uint8_t busid , uintptr_t reg_base )
376
402
{
377
- #ifdef RT_USING_LWIP
378
- rt_usbd_rndis_init ();
379
- #else
380
403
rndis_lwip_init ();
381
- #endif
404
+
382
405
#ifdef CONFIG_USBDEV_ADVANCE_DESC
383
406
usbd_desc_register (busid , & cdc_rndis_descriptor );
384
407
#else
0 commit comments