A refactor.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-04-20 17:34:42 +02:00
parent fa07b59cc7
commit 26de18608f
64 changed files with 1067 additions and 917 deletions

View File

@@ -43,31 +43,31 @@ The smartphone may be artificially picky about which Ethernet MAC address to rec
try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00 (clearing bit 1).
*/
#if !defined(ESP_PLATFORM)
#include "bsp/board_api.h"
#include "tusb.h"
#include "dhserver.h"
#include "dnserver.h"
#include "lwip/ethip6.h"
#include "lwip/init.h"
#include "lwip/timeouts.h"
#endif
#include "rest_server.h"
#include "rest_server_tls.h"
#include "tusb.h"
/* shared between tud_network_recv_cb() and service_traffic() */
static struct pbuf *received_frame;
#if !defined(ESP_PLATFORM)
/* this is used by this code, ./class/net/net_driver.c, and usb_descriptors.c */
/* ideally speaking, this should be generated from the hardware's unique ID (if available) */
/* it is suggested that the first byte is 0x02 to indicate a link-local address */
uint8_t tud_network_mac_address[6] = {0x02, 0x02, 0x84, 0x6A, 0x96, 0x00};
#define INIT_IP4(a, b, c, d) \
{ PP_HTONL(LWIP_MAKEU32(a, b, c, d)) }
/* lwip context */
static struct netif netif_data;
/* shared between tud_network_recv_cb() and service_traffic() */
static struct pbuf *received_frame;
/* this is used by this code, ./class/net/net_driver.c, and usb_descriptors.c */
/* ideally speaking, this should be generated from the hardware's unique ID (if available) */
/* it is suggested that the first byte is 0x02 to indicate a link-local address */
uint8_t tud_network_mac_address[6] = {0x02, 0x02, 0x84, 0x6A, 0x96, 0x00};
/* network parameters of this MCU */
static const ip4_addr_t ipaddr = INIT_IP4(192, 168, 7, 1);
static const ip4_addr_t netmask = INIT_IP4(255, 255, 255, 0);
@@ -201,8 +201,9 @@ void service_traffic(void) {
received_frame = NULL;
tud_network_recv_renew();
}
#if !defined(ESP_PLATFORM)
sys_check_timeouts();
#endif
}
void tud_network_init_cb(void) {
@@ -213,11 +214,14 @@ void tud_network_init_cb(void) {
}
}
#endif
int lwip_itf_init(void) {
#if !defined(ESP_PLATFORM)
init_lwip();
while (!netif_is_up(&netif_data));
while (dhserv_init(&dhcp_config) != ERR_OK);
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc) != ERR_OK);
#endif
while (rest_server_init(REST_CONN_ALL) != ERR_OK);
return 0;

View File

@@ -15,6 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "picokeys.h"
#include "pico_time.h"
#include "rest.h"
#include <strings.h>
#include "random.h"

View File

@@ -15,8 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef REST_SERVER_H
#define REST_SERVER_H
#ifndef REST_H
#define REST_H
#include <string.h>
#include <stdio.h>
@@ -25,7 +25,6 @@
#include <stdint.h>
#include <time.h>
#include "cJSON.h"
#include "pico_keys.h"
#define REST_MAX_REQUEST_SIZE 1024
#define REST_MAX_METHOD_SIZE 8

View File

@@ -15,18 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#include "picokeys.h"
#include "rest_server.h"
#include "rest_server_tls.h"
#include "pico_keys.h"
#include "usb.h"
#include <stdbool.h>
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#ifdef ENABLE_EMULATION
@@ -127,7 +121,7 @@ void rest_task(void) {
return;
}
status = card_status(ITF_LWIP);
if (status != PICOKEY_OK) {
if (status != PICOKEYS_OK) {
return;
}

View File

@@ -16,8 +16,8 @@
*/
#ifndef PICO_KEYS_REST_SERVER_H
#define PICO_KEYS_REST_SERVER_H
#ifndef REST_SERVER_H
#define REST_SERVER_H
#ifdef ENABLE_EMULATION
typedef int err_t;

View File

@@ -15,13 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#include "picokeys.h"
#include "rest_server_tls.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
extern void rest_close_conn(rest_conn_t *conn);

View File

@@ -15,8 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PICO_KEYS_REST_SERVER_TLS_H
#define PICO_KEYS_REST_SERVER_TLS_H
#ifndef REST_SERVER_TLS_H
#define REST_SERVER_TLS_H
#ifdef ENABLE_EMULATION
typedef int err_t;
@@ -58,4 +58,4 @@ extern void tls_handle_client(int client_fd);
extern struct tcp_pcb *tls_listener_pcb;
#endif
#endif
#endif // REST_SERVER_TLS_H