summaryrefslogtreecommitdiff
path: root/lib/networking
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2024-04-01 12:35:57 +0200
committerHiFiPhile <[email protected]>2024-04-01 12:35:57 +0200
commita1f01fcbe0fecb8d1783a105d7f22cba032dfced (patch)
treec8174923ef0bdd1016f55ed731df4c2df3257940 /lib/networking
parentdd0350f5499de586a3405fdcec632f059fd7534e (diff)
parent82dfe95655c7b7564363a2d5cb2f5e32d431b223 (diff)
Merge remote-tracking branch 'upstream/master' into pr/1702
Diffstat (limited to 'lib/networking')
-rw-r--r--lib/networking/dhserver.c22
-rw-r--r--lib/networking/dhserver.h12
-rw-r--r--lib/networking/dnserver.c16
-rw-r--r--lib/networking/dnserver.h12
-rw-r--r--lib/networking/ndis.h12
-rw-r--r--lib/networking/rndis_protocol.h28
-rw-r--r--lib/networking/rndis_reports.c18
7 files changed, 70 insertions, 50 deletions
diff --git a/lib/networking/dhserver.c b/lib/networking/dhserver.c
index 590739236..2f14f7a09 100644
--- a/lib/networking/dhserver.c
+++ b/lib/networking/dhserver.c
@@ -2,17 +2,17 @@
* The MIT License (MIT)
*
* Copyright (c) 2015 by Sergey Fetisov <[email protected]>
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -86,7 +86,7 @@ typedef struct
uint8_t dp_giaddr[4]; /* gateway IP address */
uint8_t dp_chaddr[16]; /* client hardware address */
uint8_t dp_legacy[192];
- uint8_t dp_magic[4];
+ uint8_t dp_magic[4];
uint8_t dp_options[275]; /* options area */
} DHCP_TYPE;
@@ -240,7 +240,15 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
unsigned n = p->len;
if (n > sizeof(dhcp_data)) n = sizeof(dhcp_data);
memcpy(&dhcp_data, p->payload, n);
- switch (dhcp_data.dp_options[2])
+
+ ptr = find_dhcp_option(dhcp_data.dp_options, sizeof(dhcp_data.dp_options), DHCP_MESSAGETYPE);
+ if (ptr == NULL)
+ {
+ pbuf_free(p);
+ return;
+ }
+
+ switch (ptr[2])
{
case DHCP_DISCOVER:
entry = entry_by_mac(dhcp_data.dp_chaddr);
@@ -259,7 +267,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
DHCP_OFFER,
config->domain,
config->dns,
- entry->lease,
+ entry->lease,
*netif_ip4_addr(netif),
config->router,
*netif_ip4_netmask(netif));
@@ -301,7 +309,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
DHCP_ACK,
config->domain,
config->dns,
- entry->lease,
+ entry->lease,
*netif_ip4_addr(netif),
config->router,
*netif_ip4_netmask(netif));
diff --git a/lib/networking/dhserver.h b/lib/networking/dhserver.h
index 2a0b15854..b0d57ac4e 100644
--- a/lib/networking/dhserver.h
+++ b/lib/networking/dhserver.h
@@ -2,17 +2,17 @@
* The MIT License (MIT)
*
* Copyright (c) 2015 by Sergey Fetisov <[email protected]>
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -56,7 +56,13 @@ typedef struct dhcp_config
dhcp_entry_t *entries;
} dhcp_config_t;
+#ifdef __cplusplus
+extern "C" {
+#endif
err_t dhserv_init(const dhcp_config_t *config);
void dhserv_free(void);
+#ifdef __cplusplus
+}
+#endif
#endif /* DHSERVER_H */
diff --git a/lib/networking/dnserver.c b/lib/networking/dnserver.c
index e4e7c3492..6d15fee02 100644
--- a/lib/networking/dnserver.c
+++ b/lib/networking/dnserver.c
@@ -2,17 +2,17 @@
* The MIT License (MIT)
*
* Copyright (c) 2015 by Sergey Fetisov <[email protected]>
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -93,11 +93,11 @@ static uint16_t get_uint16(const uint8_t *pnt)
static int parse_next_query(void *data, int size, dns_query_t *query)
{
int len;
- int lables;
+ int labels;
uint8_t *ptr;
len = 0;
- lables = 0;
+ labels = 0;
ptr = (uint8_t *)data;
while (true)
@@ -107,7 +107,7 @@ static int parse_next_query(void *data, int size, dns_query_t *query)
lable_len = *ptr++;
size--;
if (lable_len == 0) break;
- if (lables > 0)
+ if (labels > 0)
{
if (len == DNS_MAX_HOST_NAME_LEN) return -2;
query->name[len++] = '.';
@@ -118,7 +118,7 @@ static int parse_next_query(void *data, int size, dns_query_t *query)
len += lable_len;
ptr += lable_len;
size -= lable_len;
- lables++;
+ labels++;
}
if (size < 4) return -1;
@@ -165,7 +165,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
answer->ttl = htonl(32);
answer->len = htons(4);
answer->addr = host_addr.addr;
-
+
udp_sendto(upcb, out, addr, port);
pbuf_free(out);
diff --git a/lib/networking/dnserver.h b/lib/networking/dnserver.h
index a062e3aa7..a7a7f9acb 100644
--- a/lib/networking/dnserver.h
+++ b/lib/networking/dnserver.h
@@ -2,17 +2,17 @@
* The MIT License (MIT)
*
* Copyright (c) 2015 by Sergey Fetisov <[email protected]>
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -41,7 +41,13 @@
typedef bool (*dns_query_proc_t)(const char *name, ip4_addr_t *addr);
+#ifdef __cplusplus
+extern "C" {
+#endif
err_t dnserv_init(const ip_addr_t *bind, uint16_t port, dns_query_proc_t query_proc);
void dnserv_free(void);
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/lib/networking/ndis.h b/lib/networking/ndis.h
index 1c737574c..29b07749c 100644
--- a/lib/networking/ndis.h
+++ b/lib/networking/ndis.h
@@ -16,14 +16,14 @@
*/
/*
- * ndis.h
- *
+ * ndis.h
+ *
* Modified by Colin O'Flynn <[email protected]>
* ntddndis.h modified by Benedikt Spranger <[email protected]>
- *
- * Thanks to the cygwin development team,
- * espacially to Casper S. Hornstrup <[email protected]>
- *
+ *
+ * Thanks to the cygwin development team,
+ * especially to Casper S. Hornstrup <[email protected]>
+ *
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* This source code is offered for use in the public domain. You may
diff --git a/lib/networking/rndis_protocol.h b/lib/networking/rndis_protocol.h
index b45860eeb..3d07d6fa3 100644
--- a/lib/networking/rndis_protocol.h
+++ b/lib/networking/rndis_protocol.h
@@ -39,7 +39,7 @@
#ifndef _RNDIS_H
#define _RNDIS_H
-/**
+/**
\addtogroup RNDIS
@{
*/
@@ -112,7 +112,7 @@ typedef struct{
rndis_MinorVersion_t MinorVersion;
rndis_MaxTransferSize_t MaxTransferSize;
} rndis_initialize_msg_t;
-
+
/* Response: */
typedef struct{
rndis_MessageType_t MessageType;
@@ -129,7 +129,7 @@ typedef struct{
rndis_AfListOffset_t AfListOffset;
rndis_AfListSize_t AfListSize;
} rndis_initialize_cmplt_t;
-
+
/*** Remote NDIS Halt Message ***/
typedef struct{
@@ -137,7 +137,7 @@ typedef struct{
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
} rndis_halt_msg_t;
-
+
typedef uint32_t rndis_Oid_t;
typedef uint32_t rndis_InformationBufferLength_t;
typedef uint32_t rndis_InformationBufferOffset_t;
@@ -153,7 +153,7 @@ typedef struct{
rndis_InformationBufferOffset_t InformationBufferOffset;
rndis_DeviceVcHandle_t DeviceVcHandle;
} rndis_query_msg_t;
-
+
/* Response: */
typedef struct{
@@ -164,7 +164,7 @@ typedef struct{
rndis_InformationBufferLength_t InformationBufferLength;
rndis_InformationBufferOffset_t InformationBufferOffset;
} rndis_query_cmplt_t;
-
+
/*** Remote NDIS Set Message ***/
typedef struct{
rndis_MessageType_t MessageType;
@@ -175,7 +175,7 @@ typedef struct{
rndis_InformationBufferOffset_t InformationBufferOffset;
rndis_DeviceVcHandle_t DeviceVcHandle;
} rndis_set_msg_t;
-
+
/* Response */
typedef struct{
rndis_MessageType_t MessageType;
@@ -199,9 +199,9 @@ typedef struct{
rndis_ParameterNameLength_t ParameterNameLength;
rndis_ParameterType_t ParameterType;
rndis_ParameterValueOffset_t ParameterValueOffset;
- rndis_ParameterValueLength_t ParameterValueLength;
+ rndis_ParameterValueLength_t ParameterValueLength;
}rndis_config_parameter_t;
-
+
typedef uint32_t rndis_Reserved_t;
/*** Remote NDIS Soft Reset Message ***/
@@ -210,7 +210,7 @@ typedef struct{
rndis_MessageLength_t MessageLength;
rndis_Reserved_t Reserved;
} rndis_reset_msg_t;
-
+
typedef uint32_t rndis_AddressingReset_t;
/* Response: */
@@ -220,7 +220,7 @@ typedef struct{
rndis_Status_t Status;
rndis_AddressingReset_t AddressingReset;
} rndis_reset_cmplt_t;
-
+
/*** Remote NDIS Indicate Status Message ***/
typedef struct{
rndis_MessageType_t MessageType;
@@ -229,7 +229,7 @@ typedef struct{
rndis_Status_t StatusBufferLength;
rndis_Status_t StatusBufferOffset;
} rndis_indicate_status_t;
-
+
typedef uint32_t rndis_DiagStatus_t;
typedef uint32_t rndis_ErrorOffset_t;
@@ -237,14 +237,14 @@ typedef struct {
rndis_DiagStatus_t DiagStatus;
rndis_ErrorOffset_t ErrorOffset;
}rndis_diagnostic_info_t;
-
+
/*** Remote NDIS Keepalive Message */
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
}rndis_keepalive_msg_t;
-
+
/* Response: */
typedef struct{
rndis_MessageType_t MessageType;
diff --git a/lib/networking/rndis_reports.c b/lib/networking/rndis_reports.c
index ee611c883..60afb8615 100644
--- a/lib/networking/rndis_reports.c
+++ b/lib/networking/rndis_reports.c
@@ -7,17 +7,17 @@
* The MIT License (MIT)
*
* Copyright (c) 2015 by Sergey Fetisov <[email protected]>
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -43,9 +43,9 @@ static usb_eth_stat_t usb_eth_stat = { 0, 0, 0, 0 };
static uint32_t oid_packet_filter = 0x0000000;
static rndis_state_t rndis_state;
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t ndis_report[8] = { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
+CFG_TUD_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t ndis_report[8] = { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
-static const uint32_t OIDSupportedList[] =
+static const uint32_t OIDSupportedList[] =
{
OID_GEN_SUPPORTED_LIST,
OID_GEN_HARDWARE_STATUS,
@@ -203,8 +203,8 @@ static void rndis_handle_set_msg(void)
{
rndis_packetFilter(oid_packet_filter);
rndis_state = rndis_data_initialized;
- }
- else
+ }
+ else
{
rndis_state = rndis_initialized;
}
@@ -220,7 +220,7 @@ static void rndis_handle_set_msg(void)
case OID_802_3_MULTICAST_LIST:
break;
- /* Power Managment: fails for now */
+ /* Power Management: fails for now */
case OID_PNP_ADD_WAKE_UP_PATTERN:
case OID_PNP_REMOVE_WAKE_UP_PATTERN:
case OID_PNP_ENABLE_WAKE_UP:
@@ -266,7 +266,7 @@ void rndis_class_set_handler(uint8_t *data, int size)
case REMOTE_NDIS_QUERY_MSG:
rndis_query();
break;
-
+
case REMOTE_NDIS_SET_MSG:
rndis_handle_set_msg();
break;