Skip to content

Commit 64b1c88

Browse files
committed
Portenta: port WHD drivers
Portenta: WHD: sync with Cypress driver WHD: fix Thread namespace WHD: allow disabling OOB interrupt
1 parent d967edb commit 64b1c88

File tree

138 files changed

+241644
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+241644
-13
lines changed

connectivity/drivers/emac/TARGET_STM/COMPONENT_WHD/interface/CyDhcpServer.cpp

Lines changed: 454 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (c) 2018-2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef WHD_DHCP_SERVER_H
19+
#define WHD_DHCP_SERVER_H
20+
21+
#include "cy_result.h"
22+
#include "cy_syslib.h"
23+
#include "cynetwork_utils.h"
24+
#include "UDPSocket.h"
25+
#include "netsocket/NetworkInterface.h"
26+
#include "netsocket/NetworkStack.h"
27+
#include "rtos.h"
28+
29+
/* DHCP data structure */
30+
typedef struct {
31+
uint8_t Opcode; /* packet opcode type */
32+
uint8_t HwType; /* hardware addr type */
33+
uint8_t HwLen; /* hardware addr length */
34+
uint8_t Hops; /* gateway hops */
35+
uint32_t TransactionId; /* transaction ID */
36+
uint16_t SecsElapsed; /* seconds since boot began */
37+
uint16_t Flags;
38+
uint32_t ClientIpAddr; /* client IP address */
39+
uint32_t YourIpAddr; /* 'your' IP address */
40+
uint32_t ServerIpAddr; /* server IP address */
41+
uint32_t GatewayIpAddr; /* gateway IP address */
42+
uint8_t ClientHwAddr[16]; /* client hardware address */
43+
uint8_t Legacy[192]; /* SName, File */
44+
uint32_t MagicCookie;
45+
uint8_t Options[3]; /* options area */
46+
/* as of RFC2131 it is variable length */
47+
} dhcp_packet_t;
48+
49+
#define DHCP_SUBNETMASK_OPTION_CODE (1)
50+
#define DHCP_ROUTER_OPTION_CODE (3)
51+
#define DHCP_DNS_SERVER_OPTION_CODE (6)
52+
#define DHCP_HOST_NAME_OPTION_CODE (12)
53+
#define DHCP_MTU_OPTION_CODE (26)
54+
#define DHCP_REQUESTED_IP_ADDRESS_OPTION_CODE (50)
55+
#define DHCP_LEASETIME_OPTION_CODE (51)
56+
#define DHCP_MESSAGETYPE_OPTION_CODE (53)
57+
#define DHCP_SERVER_IDENTIFIER_OPTION_CODE (54)
58+
#define DHCP_PARAM_REQUEST_LIST_OPTION_CODE (55)
59+
#define DHCP_WPAD_OPTION_CODE (252)
60+
#define DHCP_END_OPTION_CODE (255)
61+
62+
#define DHCP_IP_ADDRESS_CACHE_MAX (5)
63+
#define ADDITIONAL_OPTION_BYTES (272)
64+
#define DHCP_PACKET_SIZE (sizeof(dhcp_packet_t) + ADDITIONAL_OPTION_BYTES)
65+
66+
/** DHCP thread could not be started */
67+
#define CY_DHCP_THREAD_CREATION_FAILED CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_BASE, 0)
68+
69+
/** Error while trying to stop the DHCP server */
70+
#define CY_DHCP_STOP_FAILED CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_BASE, 1)
71+
72+
/**
73+
* Implementation of a DHCP sever
74+
*/
75+
class CyDhcpServer {
76+
public:
77+
/**
78+
* Create a DHCP server.
79+
*/
80+
CyDhcpServer(NetworkStack *nstack, NetworkInterface *niface);
81+
82+
/**
83+
* Delete the DHCP server.
84+
*/
85+
virtual ~CyDhcpServer();
86+
87+
/**
88+
* Start a DHCP server instance.
89+
* @return CY_RSLT_SUCCESS on success otherwise error.
90+
*/
91+
cy_rslt_t start(void);
92+
93+
/**
94+
* Stop a DHCP server instance.
95+
* @return CY_RSLT_SUCCESS on success otherwise error.
96+
*/
97+
cy_rslt_t stop(void);
98+
99+
private:
100+
NetworkStack *_nstack = NULL;
101+
NetworkInterface *_niface = NULL;
102+
UDPSocket _socket;
103+
rtos::Thread _thread;
104+
bool _running = false;
105+
106+
cy_ip_addr_t _available_addr;
107+
cy_ip_addr_t _server_addr;
108+
cy_ip_addr_t _netmask;
109+
110+
cy_mac_addr_t _mac_addr_cache[DHCP_IP_ADDRESS_CACHE_MAX];
111+
cy_ip_addr_t _ip_addr_cache[DHCP_IP_ADDRESS_CACHE_MAX];
112+
uint8_t _buff[DHCP_PACKET_SIZE];
113+
114+
static void threadWrapper(CyDhcpServer *obj);
115+
void runServer(void);
116+
117+
void setAddress(const cy_mac_addr_t &mac_id, const cy_ip_addr_t &addr);
118+
bool lookupAddress(const cy_mac_addr_t &mac_id, cy_ip_addr_t &addr);
119+
void freeAddress(const cy_mac_addr_t &mac_id);
120+
121+
void handleDiscover(dhcp_packet_t *dhcp);
122+
void handleRequest(dhcp_packet_t *dhcp);
123+
};
124+
125+
#endif /* WHD_DHCP_SERVER_H */
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* WHD Access Point Interface Implementation
2+
* Copyright (c) 2018-2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <cstdlib>
19+
#include <utility>
20+
#include "WhdAccessPoint.h"
21+
22+
WhdAccessPoint::WhdAccessPoint(nsapi_wifi_ap_t ap, whd_bss_type_t bss_type, uint8_t *ie_ptr, uint32_t ie_len) :
23+
WiFiAccessPoint(ap), _bss_type(bss_type)
24+
{
25+
_ie_ptr = (uint8_t *)malloc(ie_len * sizeof(uint8_t));
26+
if (_ie_ptr != NULL) {
27+
_ie_len = ie_len;
28+
memcpy(_ie_ptr, ie_ptr, ie_len * sizeof(uint8_t));
29+
}
30+
}
31+
32+
WhdAccessPoint &WhdAccessPoint::operator=(WhdAccessPoint &&rhs)
33+
{
34+
if (this != &rhs) {
35+
WiFiAccessPoint::operator=(rhs);
36+
_bss_type = rhs._bss_type;
37+
_ie_ptr = rhs._ie_ptr;
38+
_ie_len = rhs._ie_len;
39+
rhs._ie_ptr = NULL;
40+
rhs._ie_len = 0;
41+
}
42+
return *this;
43+
}
44+
45+
whd_bss_type_t WhdAccessPoint::get_bss_type() const
46+
{
47+
return _bss_type;
48+
}
49+
50+
uint8_t *WhdAccessPoint::get_ie_data() const
51+
{
52+
return _ie_ptr;
53+
}
54+
55+
uint32_t WhdAccessPoint::get_ie_len() const
56+
{
57+
return _ie_len;
58+
}
59+
60+
WhdAccessPoint::~WhdAccessPoint()
61+
{
62+
if (_ie_ptr != NULL) {
63+
free(_ie_ptr);
64+
}
65+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* WHD Access Point Interface
2+
* Copyright (c) 2017-2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef WHD_ACCESS_POINT_H
19+
#define WHD_ACCESS_POINT_H
20+
21+
#include "netsocket/WiFiAccessPoint.h"
22+
#include "whd_types.h"
23+
24+
/* Enum for scan result type */
25+
enum scan_result_type {
26+
SRES_TYPE_WIFI_ACCESS_POINT,
27+
SRES_TYPE_WHD_ACCESS_POINT
28+
};
29+
30+
/** WhdAccessPoint class
31+
*
32+
* Class that represents a Whd Access Point
33+
* which contains additional Whd specific information
34+
*/
35+
class WhdAccessPoint : public WiFiAccessPoint {
36+
public:
37+
WhdAccessPoint() : WiFiAccessPoint() {};
38+
WhdAccessPoint(nsapi_wifi_ap_t ap, whd_bss_type_t bss_type, uint8_t *ie_ptr, uint32_t ie_len);
39+
40+
/** Define move assignment and prevent copy-assignment
41+
*
42+
* Due to IE element data could have large memory footprint,
43+
* only move assignment is allowed.
44+
*/
45+
WhdAccessPoint &operator=(WhdAccessPoint &&rhs);
46+
WhdAccessPoint &operator=(const WhdAccessPoint &rhs) = delete;
47+
48+
/** Get WHD access point's bss type
49+
*
50+
* @return The whd_bss_type_t of the access point
51+
*/
52+
whd_bss_type_t get_bss_type() const;
53+
54+
/** Get WHD access point's IE data
55+
*
56+
* @return The pointer to ie data buffer
57+
*/
58+
uint8_t *get_ie_data() const;
59+
60+
/** Get WHD access point's IE length
61+
*
62+
* @return The ie data length
63+
*/
64+
uint32_t get_ie_len() const;
65+
66+
virtual ~WhdAccessPoint();
67+
68+
private:
69+
whd_bss_type_t _bss_type;
70+
uint8_t *_ie_ptr; /**< Pointer to received Beacon/Probe Response IE(Information Element) */
71+
uint32_t _ie_len; /**< Length of IE(Information Element) */
72+
};
73+
74+
#endif

0 commit comments

Comments
 (0)