Device descriptor | ||||
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | one | 12h | |
one | bDescriptorType | one | 01h | Device |
2 | bcdUSB | 2 | 0200h | USB Spec 2.0 |
four | bDeviceClass | one | 02h | CDC Control |
five | bDeviceSubClass | one | 00h | |
6 | bDeviceProtocol | one | 00h | |
7 | bMaxPacketSize0 | one | 40h | 64 bytes |
eight | idVendor | 2 | 0483h | SGS Thomson Microelectronics |
ten | idProduct | 2 | 0123h | |
12 | bcdDevice | 2 | 0001h | 0.01 |
14 | iManufacturer | one | 01h | "Fetisov Sergey" |
15 | iProduct | one | 02h | "STM32F4 RNDIS" |
sixteen | iSerialNumber | one | 03h | "00000000123C" |
17 | bNumConfigurations | one | 01h | |
Configuration Descriptor 1 | ||||
Offset | Field | Size | Value | Description |
0 | bLength | one | 09h | |
one | bDescriptorType | one | 02h | Configuration |
2 | wTotalLength | 2 | 0043h | |
four | bNumInterfaces | one | 02h | |
five | bConfigurationValue | one | 01h | |
6 | iConfiguration | one | 00h | |
7 | bmAttributes | one | 40h | Self powered |
eight | bMaxPower | one | 01h | 2 mA |
Interface Descriptor 0/0 CDC Control, 1 Endpoint | ||||
Offset | Field | Size | Value | Description |
0 | bLength | one | 09h | |
one | bDescriptorType | one | 04h | Interface |
2 | bInterfaceNumber | one | 00h | |
3 | bAlternateSetting | one | 00h | |
four | bNumEndpoints | one | 01h | |
five | bInterfaceClass | one | 02h | CDC Control |
6 | bInterfaceSubClass | one | 02h | Abstract Control Model |
7 | bInterfaceProtocol | one | FFh | Vendor-specific |
eight | iInterface | one | 00h | |
Header Functional Descriptor | ||||
Offset | Field | Size | Value | Description |
0 | bFunctionLength | one | 05h | |
one | bDescriptorType | one | 24h | CS Interface |
2 | bDescriptorSubtype | one | 00h | Header |
3 | bcdCDC | 2 | 0110h | 1.10 |
Call Management Functional Descriptor | ||||
Offset | Field | Size | Value | Description |
0 | bFunctionLength | one | 05h | |
one | bDescriptorType | one | 24h | CS Interface |
2 | bDescriptorSubtype | one | 01h | Call management |
3 | bmCapabilities | one | 00h | |
four | bDataInterface | one | 01h | |
Abstract Control Management Functional Descriptor | ||||
Offset | Field | Size | Value | Description |
0 | bFunctionLength | one | 04h | |
one | bDescriptorType | one | 24h | CS Interface |
2 | bDescriptorSubtype | one | 02h | Abstract Control Management |
3 | bmCapabilities | one | 00h | Requests / notifications not supported |
Union Functional Descriptor | ||||
Offset | Field | Size | Value | Description |
0 | bFunctionLength | one | 05h | |
one | bDescriptorType | one | 24h | CS Interface |
2 | bDescriptorSubtype | one | 06h | Union |
3 | bControlInterface | one | 00h | |
four | bSubordinateInterface0 | one | 01h | CDC Data |
Endpoint Descriptor 81 1 In, Interrupt, 80 ms | ||||
Offset | Field | Size | Value | Description |
0 | bLength | one | 07h | |
one | bDescriptorType | one | 05h | Endpoint |
2 | bEndpointAddress | one | 81h | 1 In |
3 | bmAttributes | one | 03h | Interrupt |
four | wMaxPacketSize | 2 | 0008h | 8 bytes |
6 | bInterval | one | 50h | 80 ms |
Interface Descriptor 1/0 CDC Data, 2 Endpoints | ||||
Offset | Field | Size | Value | Description |
0 | bLength | one | 09h | |
one | bDescriptorType | one | 04h | Interface |
2 | bInterfaceNumber | one | 01h | |
3 | bAlternateSetting | one | 00h | |
four | bNumEndpoints | one | 02h | |
five | bInterfaceClass | one | 0Ah | CDC Data |
6 | bInterfaceSubClass | one | 00h | |
7 | bInterfaceProtocol | one | 00h | |
eight | iInterface | one | 00h | |
Endpoint Descriptor 82 2 In, Bulk, 64 bytes | ||||
Offset | Field | Size | Value | Description |
0 | bLength | one | 07h | |
one | bDescriptorType | one | 05h | Endpoint |
2 | bEndpointAddress | one | 82h | 2 In |
3 | bmAttributes | one | 02h | Bulk |
four | wMaxPacketSize | 2 | 0040h | 64 bytes |
6 | bInterval | one | 00h | |
Endpoint Descriptor 03 3 Out, Bulk, 64 bytes | ||||
Offset | Field | Size | Value | Description |
0 | bLength | one | 07h | |
one | bDescriptorType | one | 05h | Endpoint |
2 | bEndpointAddress | one | 03h | 3 out |
3 | bmAttributes | one | 02h | Bulk |
four | wMaxPacketSize | 2 | 0040h | 64 bytes |
6 | bInterval | one | 00h |
#define ETH_MTU 1500 // MTU value #define ETH_LINK_SPEED 250000 // bits per sec #define RNDIS_VENDOR "fetisov" // NIC vendor name #define STATION_HWADDR 0x20,0x89,0x84,0x6A,0x96,0xAA // station MAC #define PERMANENT_HWADDR 0x20,0x89,0x84,0x6A,0x96,0xAA // permanent MAC
The TCP / IP protocol suite has been continued developed.
While IP TCP TCP TCP TCP / IP It also makes it possible to use it.
Main features include:
- Protocols: IP, ICMP, UDP, TCP, IGMP, ARP, PPPoS, PPPoE
- DHCP client, DNS client, AutoIP / APIPA (Zeroconf), SNMP agent (private MIB support)
- APIs: specialized APIs for enhanced performance, optional Berkeley-alike socket API
- Extended features: IP forwarding and recovery / retransmit
- Addon applications: HTTP server, SNTP client, SMTP client, ping, NetBIOS nameserver
#define NO_SYS 1 #define LWIP_RAW 1 #define LWIP_NETCONN 0 #define LWIP_SOCKET 0 #define LWIP_DHCP 0 #define LWIP_ICMP 1 #define LWIP_UDP 1 #define LWIP_TCP 1 #define ETH_PAD_SIZE 0 #define LWIP_IP_ACCEPT_UDP_PORT(p) ((p) == PP_NTOHS(67)) #define MEM_SIZE 10000 #define TCP_MSS (1500 /*mtu*/ - 14 /*ethhdr*/ - 20 /*iphdr*/ - 20 /*tcphhr*/) #define ETHARP_SUPPORT_STATIC_ENTRIES 1
#define NUM_DHCP_ENTRY 3 static dhcp_entry_t entries[NUM_DHCP_ENTRY] = { // mac ip address subnet mask lease time { {0}, {192, 168, 7, 2}, {255, 255, 255, 0}, 24 * 60 * 60 }, { {0}, {192, 168, 7, 3}, {255, 255, 255, 0}, 24 * 60 * 60 }, { {0}, {192, 168, 7, 4}, {255, 255, 255, 0}, 24 * 60 * 60 } }; static dhcp_config_t dhcp_config = { {192, 168, 7, 1}, 67, // server address, port {192, 168, 7, 1}, // dns server "stm", // dns suffix NUM_DHCP_ENTRY, // num entry entries // entries }; int main(void) { ... while (dhserv_init(&dhcp_config) != ERR_OK) ; ... }
bool dns_query_proc(const char *name, ip_addr_t *addr) { if (strcmp(name, "run.stm") == 0 || strcmp(name, "www.run.stm") == 0) { addr->addr = *(uint32_t *)ipaddr; return true; } return false; } int main(void) { ... while (dnserv_init(PADDR(ipaddr), 53, dns_query_proc) != ERR_OK) ; ... }
static const my_page_t my_pages[] = { { "/", 200, MIME_TEXT_HTML, page1_html, page1_html_size }, { "/page2.htm", 200, MIME_TEXT_HTML, page2_html, page2_html_size }, { "/page3.htm", 200, MIME_TEXT_HTML, page3_html, page3_html_size }, { "/check.gif", 200, MIME_IMAGE_GIF, check_png, check_png_size }, { NULL, 404, MIME_TEXT_HTML, page_not_found, page_not_found_size } }; bool on_http_req(const http_req_t *req, http_resp_t *resp, void **arg) { const my_page_t *page; for (page = my_pages; page->uri != NULL; page++) if (strcmp(page->uri, req->uri) == 0) break; resp->code = page->code; resp->cont_len = page->size; resp->mime = page->mime; resp->conn_type = CT_CLOSE; *arg = (void *)page; return true; } void http_write_data() { for (int i = 0; i < HTTP_SERVER_MAX_CON; i++) { int n; const htcon_t *con; my_page_t *page; con = htcon(i); if (con == NULL) continue; page = (my_page_t *)con->arg; if (con->state == CON_CLOSED) { htcon_free(i); continue; } if (con->state != CON_ACTIVE) continue; n = page->size - con->writed; htcon_write(i, (char *)page->data + con->writed, n); } } int main(void) { ... htserv_on_req = on_http_req; while (htserv_init(80) != ERR_OK) ; while (1) { stmr(); // call software timers usb_polling(); // usb device polling http_write_data(); // writes http response } }
Source: https://habr.com/ru/post/248097/
All Articles