From 3f913efda03fd840cd526ef72e6f397c7da61bd7 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Tue, 9 Aug 2022 22:23:08 +0200 Subject: code layout --- fw/fe310/eos/net/Makefile | 19 ++++++++ fw/fe310/eos/net/cell.c | 4 +- fw/fe310/eos/net/cell.h | 20 ++++++-- fw/fe310/eos/net/pwr.c | 69 ++++++++++++++++++++++++++++ fw/fe310/eos/net/pwr.h | 10 ++++ fw/fe310/eos/net/rng.c | 2 +- fw/fe310/eos/net/sock.c | 29 ++++++++---- fw/fe310/eos/net/sock.h | 4 +- fw/fe310/eos/net/wifi.c | 113 ++++++++++++++++++++++++++++++++++++++-------- fw/fe310/eos/net/wifi.h | 29 ++++++++---- 10 files changed, 249 insertions(+), 50 deletions(-) create mode 100644 fw/fe310/eos/net/Makefile create mode 100644 fw/fe310/eos/net/pwr.c create mode 100644 fw/fe310/eos/net/pwr.h (limited to 'fw/fe310/eos/net') diff --git a/fw/fe310/eos/net/Makefile b/fw/fe310/eos/net/Makefile new file mode 100644 index 0000000..fc65454 --- /dev/null +++ b/fw/fe310/eos/net/Makefile @@ -0,0 +1,19 @@ +include ../../common.mk + +obj = rng.o pwr.o wifi.o sock.o cell.o +lib = ../../libeos-net.a + + +%.o: %.c %.h + $(CC) $(CFLAGS) -c $< + +%.o: %.S + $(CC) $(CFLAGS) -c $< + +all: $(lib) + +$(lib): $(obj) + $(AR) rcs $@ $(obj) + +clean: + rm -f *.o $(lib) diff --git a/fw/fe310/eos/net/cell.c b/fw/fe310/eos/net/cell.c index 20a9f42..4bfbb35 100644 --- a/fw/fe310/eos/net/cell.c +++ b/fw/fe310/eos/net/cell.c @@ -4,7 +4,7 @@ #include "eos.h" #include "event.h" -#include "net.h" +#include "dev/net.h" #include "cell.h" @@ -28,7 +28,7 @@ static void cell_handle_msg(unsigned char type, unsigned char *buffer, uint16_t } } -void eos_cell_netinit(void) { +void eos_cell_init(void) { int i; for (i=0; i -#include "event.h" +#include "../event.h" #define EOS_CELL_MTYPE_DEV 0x10 #define EOS_CELL_MTYPE_VOICE 0x20 @@ -38,14 +38,24 @@ #define EOS_CELL_MTYPE_USSD_REPLY 2 #define EOS_CELL_MTYPE_USSD_CANCEL 3 -#define EOS_CELL_MTYPE_PDP_CONFIG 1 -#define EOS_CELL_MTYPE_PDP_CONNECT 2 -#define EOS_CELL_MTYPE_PDP_DISCONNECT 3 +#define EOS_CELL_MTYPE_PDP_GET_APN 1 +#define EOS_CELL_MTYPE_PDP_GET_USR 2 +#define EOS_CELL_MTYPE_PDP_GET_PWD 3 +#define EOS_CELL_MTYPE_PDP_SET_APN 4 +#define EOS_CELL_MTYPE_PDP_SET_USR 5 +#define EOS_CELL_MTYPE_PDP_SET_PWD 6 +#define EOS_CELL_MTYPE_PDP_CONNECT 7 +#define EOS_CELL_MTYPE_PDP_DISCONNECT 8 #define EOS_CELL_SMS_ADDRTYPE_INTL 1 #define EOS_CELL_SMS_ADDRTYPE_ALPHA 2 #define EOS_CELL_SMS_ADDRTYPE_OTHER 3 -void eos_cell_netinit(void); +#define EOS_CELL_PDP_SIZE_APN 64 +#define EOS_CELL_PDP_SIZE_USR 64 +#define EOS_CELL_PDP_SIZE_PWD 64 +#define EOS_CELL_PDP_SIZE_ARG 64 + +void eos_cell_init(void); void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler); eos_evt_handler_t eos_cell_get_handler(unsigned char mtype); \ No newline at end of file diff --git a/fw/fe310/eos/net/pwr.c b/fw/fe310/eos/net/pwr.c new file mode 100644 index 0000000..734e3cd --- /dev/null +++ b/fw/fe310/eos/net/pwr.c @@ -0,0 +1,69 @@ +#include +#include + +#include "eos.h" +#include "event.h" +#include "dev/net.h" + +#include "soc/pwr.h" +#include "soc/spi.h" +#include "dev/spi.h" +#include "eve/eve.h" + +#include "pwr.h" + +static eos_evt_handler_t evt_handler[EOS_PWR_MAX_MTYPE]; +static unsigned char power_btn_down; + +static void pwr_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) { + unsigned char mtype; + + if ((buffer == NULL) || (len < 1)) { + eos_net_bad_handler(type, buffer, len); + return; + } + + mtype = buffer[0]; + if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) { + evt_handler[mtype](mtype, buffer, len); + } else { + eos_net_bad_handler(type, buffer, len); + } +} + +static void pwr_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) { + int rv; + unsigned char level = buffer[1]; + + eos_net_free(buffer, 0); + if (!level) { + power_btn_down = 1; + return; + } + if (!power_btn_down) return; + + eos_spi_select(EOS_SPI_DEV_EVE); + eve_pwr_sleep(); + eos_spi_deselect(); + + rv = eos_pwr_sleep(); +} + +void eos_pwr_net_init(void) { + int i; + + for (i=0; i +#include "../event.h" + +#define EOS_PWR_MTYPE_BUTTON 1 + +#define EOS_PWR_MAX_MTYPE 2 + +void eos_pwr_net_init(void); +void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler); +eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype); diff --git a/fw/fe310/eos/net/rng.c b/fw/fe310/eos/net/rng.c index 317941d..7d05a81 100644 --- a/fw/fe310/eos/net/rng.c +++ b/fw/fe310/eos/net/rng.c @@ -2,7 +2,7 @@ #include #include -#include "net.h" +#include "dev/net.h" int getentropy(unsigned char *b, size_t sz) { unsigned char type; diff --git a/fw/fe310/eos/net/sock.c b/fw/fe310/eos/net/sock.c index 7365c97..1db0cd9 100644 --- a/fw/fe310/eos/net/sock.c +++ b/fw/fe310/eos/net/sock.c @@ -4,7 +4,7 @@ #include "eos.h" #include "event.h" -#include "net.h" +#include "dev/net.h" #include "sock.h" @@ -34,7 +34,7 @@ static void sock_handle_msg(unsigned char type, unsigned char *buffer, uint16_t } } -void eos_sock_netinit(void) { +void eos_sock_init(void) { int i; for (i=0; i -#include "event.h" +#include "../event.h" #define EOS_SOCK_MTYPE_PKT 0 #define EOS_SOCK_MTYPE_OPEN_DGRAM 1 @@ -16,7 +16,7 @@ typedef struct EOSNetAddr { uint16_t port; } EOSNetAddr; -void eos_sock_netinit(void); +void eos_sock_init(void); void eos_sock_set_handler(unsigned char sock, eos_evt_handler_t handler); eos_evt_handler_t eos_sock_get_handler(unsigned char sock); diff --git a/fw/fe310/eos/net/wifi.c b/fw/fe310/eos/net/wifi.c index 0663582..4db49f8 100644 --- a/fw/fe310/eos/net/wifi.c +++ b/fw/fe310/eos/net/wifi.c @@ -4,10 +4,13 @@ #include "eos.h" #include "event.h" -#include "net.h" +#include "dev/net.h" #include "wifi.h" +#define WIFI_SIZE_SSID 33 +#define WIFI_SIZE_PWD 64 + static eos_evt_handler_t evt_handler[EOS_WIFI_MAX_MTYPE]; static void wifi_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) { @@ -26,7 +29,7 @@ static void wifi_handle_msg(unsigned char type, unsigned char *buffer, uint16_t } } -void eos_wifi_netinit(void) { +void eos_wifi_init(void) { int i; for (i=0; i WIFI_SIZE_SSID)) { + rv = EOS_ERR_SIZE; + goto wifi_status_fin; + } + buf[len - 1] = '\0'; + if (ssid) strcpy(ssid, buf); + break; + } + +wifi_status_fin: + if (do_release) eos_net_free(buffer, 1); + return rv; +} + +int eos_wifi_start(unsigned char *buffer) { int async; async = 0; @@ -52,13 +112,11 @@ int eos_wifi_scan(unsigned char *buffer) { buffer = eos_net_alloc(); async = 1; } - buffer[0] = EOS_WIFI_MTYPE_SCAN; + buffer[0] = EOS_WIFI_MTYPE_START; return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1); } -int eos_wifi_auth(const char *ssid, const char *pass, unsigned char *buffer) { - unsigned char *buf; - size_t ssid_len, pass_len; +int eos_wifi_stop(unsigned char *buffer) { int async; async = 0; @@ -66,30 +124,45 @@ int eos_wifi_auth(const char *ssid, const char *pass, unsigned char *buffer) { buffer = eos_net_alloc(); async = 1; } - ssid_len = strlen(ssid) + 1; - pass_len = strlen(pass) + 1; - if ((1 + ssid_len + pass_len) > EOS_NET_MTU) return EOS_ERR_SIZE; + buffer[0] = EOS_WIFI_MTYPE_STOP; + return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1); +} - buf = buffer; - buf[0] = EOS_WIFI_MTYPE_AUTH; - buf++; - strcpy(buf, ssid); - buf += ssid_len; - strcpy(buf, pass); - buf += pass_len; +int eos_wifi_scan(unsigned char *buffer) { + int async; - return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1 + ssid_len + pass_len, async, 1); + async = 0; + if (buffer == NULL) { + buffer = eos_net_alloc(); + async = 1; + } + buffer[0] = EOS_WIFI_MTYPE_SCAN; + return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1); } -int eos_wifi_connect(unsigned char *buffer) { +int eos_wifi_connect(const char *ssid, const char *pwd, unsigned char *buffer) { + unsigned char *buf; + size_t ssid_len, pwd_len; int async; + ssid_len = strlen(ssid); + pwd_len = strlen(pwd); + if (ssid_len > WIFI_SIZE_SSID - 1) return EOS_ERR_SIZE; + if (pwd_len > WIFI_SIZE_PWD - 1) return EOS_ERR_SIZE; + async = 0; if (buffer == NULL) { buffer = eos_net_alloc(); async = 1; } - buffer[0] = EOS_WIFI_MTYPE_CONNECT; + buf = buffer; + buf[0] = EOS_WIFI_MTYPE_CONNECT; + buf++; + strcpy(buf, ssid); + buf += ssid_len + 1; + strcpy(buf, pwd); + buf += pwd_len + 1; + return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1); } diff --git a/fw/fe310/eos/net/wifi.h b/fw/fe310/eos/net/wifi.h index 4a49518..2100144 100644 --- a/fw/fe310/eos/net/wifi.h +++ b/fw/fe310/eos/net/wifi.h @@ -1,18 +1,27 @@ #include -#include "event.h" +#include "../event.h" -#define EOS_WIFI_MTYPE_SCAN 1 -#define EOS_WIFI_MTYPE_AUTH 2 -#define EOS_WIFI_MTYPE_CONNECT 3 -#define EOS_WIFI_MTYPE_DISCONNECT 4 +#define EOS_WIFI_MTYPE_STATUS 0 +#define EOS_WIFI_MTYPE_SCAN 1 +#define EOS_WIFI_MTYPE_START 2 +#define EOS_WIFI_MTYPE_STOP 3 +#define EOS_WIFI_MTYPE_CONNECT 4 +#define EOS_WIFI_MTYPE_DISCONNECT 5 -#define EOS_WIFI_MAX_MTYPE 5 +#define EOS_WIFI_MAX_MTYPE 2 -void eos_wifi_netinit(void); +#define EOS_WIFI_STATUS_OFF 0 +#define EOS_WIFI_STATUS_DISCONNECTED 1 +#define EOS_WIFI_STATUS_CONNECTED 2 +#define EOS_WIFI_STATUS_GOT_IP 3 + +void eos_wifi_init(void); void eos_wifi_set_handler(unsigned char mtype, eos_evt_handler_t handler); eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype); +int eos_wifi_status(unsigned char *buffer, uint8_t *status, uint8_t ip_addr[], char *ssid); +int eos_wifi_start(unsigned char *buffer); +int eos_wifi_stop(unsigned char *buffer); int eos_wifi_scan(unsigned char *buffer); -int eos_wifi_auth(const char *ssid, const char *pass, unsigned char *buffer); -int eos_wifi_connect(unsigned char *buffer); -int eos_wifi_disconnect(unsigned char *buffer); +int eos_wifi_connect(const char *ssid, const char *pwd, unsigned char *buffer); +int eos_wifi_disconnect(unsigned char *buffer); \ No newline at end of file -- cgit v1.2.3