summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/net
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/net')
-rw-r--r--fw/fe310/eos/net/Makefile19
-rw-r--r--fw/fe310/eos/net/cell.c4
-rw-r--r--fw/fe310/eos/net/cell.h20
-rw-r--r--fw/fe310/eos/net/pwr.c69
-rw-r--r--fw/fe310/eos/net/pwr.h10
-rw-r--r--fw/fe310/eos/net/rng.c2
-rw-r--r--fw/fe310/eos/net/sock.c29
-rw-r--r--fw/fe310/eos/net/sock.h4
-rw-r--r--fw/fe310/eos/net/wifi.c113
-rw-r--r--fw/fe310/eos/net/wifi.h29
10 files changed, 249 insertions, 50 deletions
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<EOS_CELL_MAX_MTYPE; i++) {
diff --git a/fw/fe310/eos/net/cell.h b/fw/fe310/eos/net/cell.h
index b01d4cf..f04eef2 100644
--- a/fw/fe310/eos/net/cell.h
+++ b/fw/fe310/eos/net/cell.h
@@ -1,5 +1,5 @@
#include <stdint.h>
-#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 <stdlib.h>
+#include <stdint.h>
+
+#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<EOS_PWR_MAX_MTYPE; i++) {
+ evt_handler[i] = NULL;
+ }
+ eos_net_set_handler(EOS_NET_MTYPE_POWER, pwr_handle_msg);
+ eos_pwr_set_handler(EOS_PWR_MTYPE_BUTTON, pwr_handle_btn);
+}
+
+void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
+ if (mtype < EOS_PWR_MAX_MTYPE) evt_handler[mtype] = handler;
+}
+
+eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype) {
+ if (mtype < EOS_PWR_MAX_MTYPE) return evt_handler[mtype];
+ return NULL;
+}
diff --git a/fw/fe310/eos/net/pwr.h b/fw/fe310/eos/net/pwr.h
new file mode 100644
index 0000000..b82a96b
--- /dev/null
+++ b/fw/fe310/eos/net/pwr.h
@@ -0,0 +1,10 @@
+#include <stdint.h>
+#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 <stdint.h>
#include <string.h>
-#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<EOS_SOCK_MAX_SOCK; i++) {
@@ -69,20 +69,29 @@ int eos_sock_open_udp(eos_evt_handler_t handler, unsigned char *buffer) {
buffer[0] = EOS_SOCK_MTYPE_OPEN_DGRAM;
rv = eos_net_xchg(&type, buffer, &len);
- if (rv) return rv;
+ if (rv) goto sock_open_udp_fin;
- if (type != EOS_NET_MTYPE_SOCK) return EOS_ERR_NET;
- if (len < 2) return EOS_ERR_SIZE;
+ if (type != EOS_NET_MTYPE_SOCK) {
+ rv = EOS_ERR_NET;
+ goto sock_open_udp_fin;
+ }
+ if (len < 2) {
+ rv = EOS_ERR_SIZE;
+ goto sock_open_udp_fin;
+ }
sock = buffer[1];
- if (sock == 0) return EOS_ERR_NET;
-
- if (do_release) {
- eos_net_free(buffer, 1);
+ if (sock == 0) {
+ rv = EOS_ERR_NET;
+ goto sock_open_udp_fin;
}
+
+ rv = sock;
eos_sock_set_handler(sock, handler);
- return sock;
+sock_open_udp_fin:
+ if (do_release) eos_net_free(buffer, 1);
+ return rv;
}
void eos_sock_close(unsigned char sock, unsigned char *buffer) {
diff --git a/fw/fe310/eos/net/sock.h b/fw/fe310/eos/net/sock.h
index 5ef42e3..e2f8637 100644
--- a/fw/fe310/eos/net/sock.h
+++ b/fw/fe310/eos/net/sock.h
@@ -1,5 +1,5 @@
#include <stdint.h>
-#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<EOS_WIFI_MAX_MTYPE; i++) {
@@ -44,7 +47,64 @@ eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype) {
return NULL;
}
-int eos_wifi_scan(unsigned char *buffer) {
+int eos_wifi_status(unsigned char *buffer, uint8_t *status, uint8_t ip_addr[], char *ssid) {
+ unsigned char *buf;
+ unsigned char type;
+ uint16_t len;
+ int do_release;
+ int rv;
+
+ do_release = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ do_release = 1;
+ }
+
+ type = EOS_NET_MTYPE_WIFI;
+ len = 1;
+ buffer[0] = EOS_WIFI_MTYPE_STATUS;
+
+ rv = eos_net_xchg(&type, buffer, &len);
+ if (rv) goto wifi_status_fin;
+
+ if (type != EOS_NET_MTYPE_WIFI) {
+ rv = EOS_ERR_NET;
+ goto wifi_status_fin;
+ }
+ if (len < 2) {
+ rv = EOS_ERR_SIZE;
+ goto wifi_status_fin;
+ }
+
+ *status = buffer[1];
+ buf = buffer + 2;
+ len -= 2;
+
+ switch (*status) {
+ case EOS_WIFI_STATUS_GOT_IP:
+ if (len < sizeof(uint32_t)) {
+ rv = EOS_ERR_SIZE;
+ goto wifi_status_fin;
+ }
+ if (ip_addr) memcpy(ip_addr, buf, sizeof(uint32_t));
+ buf += sizeof(uint32_t);
+ len -= sizeof(uint32_t);
+ case EOS_WIFI_STATUS_CONNECTED:
+ if ((len == 0) || (len > 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 <stdint.h>
-#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