cc3000 hostdriver with the mbed socket interface
Dependents: cc3000_hello_world_demo cc3000_simple_socket_demo cc3000_ntp_demo cc3000_ping_demo ... more
Revision 40:acb9324640c4, committed 2013-10-12
- Comitter:
- SolderSplashLabs
- Date:
- Sat Oct 12 20:51:05 2013 +0000
- Parent:
- 37:3332f57b7f1e
- Parent:
- 39:03ac37ab34eb
- Child:
- 41:eb1999bd50fb
- Commit message:
- Merged with Martin's
Changed in this revision
| cc3000.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/cc3000.cpp Sat Oct 12 14:27:46 2013 +0200
+++ b/cc3000.cpp Sat Oct 12 20:51:05 2013 +0000
@@ -60,6 +60,7 @@
_status.smart_config_complete = 0;
_status.stop_smart_config = 0;
_status.ok_to_shut_down = 0;
+ _status.enabled = 0;
_inst = this;
}
@@ -68,6 +69,67 @@
}
+#ifdef CC3000_ETH_COMPAT
+// Ethernet library compatible, functions return strings
+// Caches the ipconfig from the usync callback
+static char mac_addr[19];
+static char ip_addr[17] = "\0";
+static char gateway[17] = "\0";
+static char networkmask[17] = "\0";
+
+char* cc3000::getMACAddress() {
+ return mac_addr;
+}
+
+char* cc3000::getIPAddress() {
+ return ip_addr;
+}
+
+char* cc3000::getGateway() {
+ return gateway;
+}
+
+char* cc3000::getNetworkMask() {
+ return networkmask;
+}
+
+/* Copied from lwip , modified to accept an uint32*/
+static char *inet_ntoa_r(uint32_t s_addr, char *buf, int buflen)
+{
+ char inv[3];
+ char *rp;
+ uint8_t *ap;
+ uint8_t rem;
+ uint8_t n;
+ uint8_t i;
+ int len = 0;
+
+ rp = buf;
+ ap = (uint8_t *)&s_addr;
+ for(n = 0; n < 4; n++) {
+ i = 0;
+ do {
+ rem = *ap % (uint8_t)10;
+ *ap /= (uint8_t)10;
+ inv[i++] = '0' + rem;
+ } while(*ap);
+ while(i--) {
+ if (len++ >= buflen) {
+ return NULL;
+ }
+ *rp++ = inv[i];
+ }
+ if (len++ >= buflen) {
+ return NULL;
+ }
+ *rp++ = '.';
+ ap++;
+ }
+ *--rp = 0;
+ return buf;
+}
+#endif
+
void cc3000::usync_callback(int32_t event_type, uint8_t * data, uint8_t length) {
if (event_type == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE)
{
@@ -78,6 +140,8 @@
if (event_type == HCI_EVNT_WLAN_UNSOL_CONNECT)
{
_status.connected = 1;
+ // Connect message is always followed by a DHCP message, connection is not useable until then
+ _status.dhcp = 0;
}
if (event_type == HCI_EVNT_WLAN_UNSOL_DISCONNECT)
@@ -89,6 +153,15 @@
if (event_type == HCI_EVNT_WLAN_UNSOL_DHCP)
{
+ #ifdef CC3000_ETH_COMPAT
+
+ inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_IP_OFFSET]))), ip_addr, 17);
+ inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_GW_OFFSET]))), gateway, 17);
+ inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_SUBNET_OFFSET]))), networkmask, 17);
+ inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_MAC_OFFSET]))), mac_addr, 19);
+
+ #endif
+
if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0) {
_status.dhcp = 1;
} else {
@@ -116,6 +189,8 @@
}
void cc3000::start_smart_config(const uint8_t *smart_config_key) {
+
+ _status.smart_config_complete = 0;
_wlan.ioctl_set_connection_policy(0, 0, 0);
//Wait until CC3000 is disconected
@@ -151,13 +226,14 @@
// Configure to connect automatically to the AP retrieved in the
// Smart config process
- _wlan.ioctl_set_connection_policy(0, 1, 1);
+ _wlan.ioctl_set_connection_policy(0, 0, 1);
// reset the CC3000
_wlan.stop();
- wait(2);
+ _status.enabled = 0;
+ wait(5);
_wlan.start(0);
- wait(2);
+ _status.enabled = 1;
// Mask out all non-required events
_wlan.set_event_mask(HCI_EVNT_WLAN_KEEPALIVE | HCI_EVNT_WLAN_UNSOL_INIT | HCI_EVNT_WLAN_ASYNC_PING_REPORT);
@@ -177,6 +253,32 @@
return ret;
}
+bool cc3000::connect_non_blocking(const uint8_t *ssid, const uint8_t *key, int32_t security_mode)
+{
+bool ret = false;
+
+ if (key == 0)
+ {
+ if (connect_open(ssid))
+ {
+ ret = true;
+ }
+ }
+ else
+ {
+ #ifndef CC3000_TINY_DRIVER
+ if (connect_secure(ssid,key,security_mode))
+ {
+ ret = true;
+ }
+ #else
+ /* secure connection not supported with TINY_DRIVER */
+ #endif
+ }
+
+ return ret;
+}
+
bool cc3000::connect_to_AP(const uint8_t *ssid, const uint8_t *key, int32_t security_mode) {
Timer t; /* TODO static? */
bool ret = true;
@@ -212,17 +314,21 @@
void cc3000::start(uint8_t patch) {
_wlan.start(patch);
+ _status.enabled = 1;
_wlan.set_event_mask(HCI_EVNT_WLAN_UNSOL_INIT | HCI_EVNT_WLAN_KEEPALIVE);
}
void cc3000::stop(void) {
_wlan.stop();
+ _status.enabled = 0;
}
void cc3000::restart(uint8_t patch) {
_wlan.stop();
+ _status.enabled = 0;
wait_ms(500);
_wlan.start(patch);
+ _status.enabled = 1;
}
bool cc3000::connect_open(const uint8_t *ssid) {
@@ -243,6 +349,11 @@
return ret;
}
+bool cc3000::is_enabled()
+{
+ return _status.enabled;
+}
+
bool cc3000::is_connected() {
return _status.connected;
}
--- a/cc3000.h Sat Oct 12 14:27:46 2013 +0200
+++ b/cc3000.h Sat Oct 12 20:51:05 2013 +0000
@@ -50,24 +50,25 @@
#include "cc3000_socket.h"
#define MAX_SOCKETS 4
+#define CC3000_ETH_COMPAT
/** Enable debug messages, remove comment from the ones you want or all.
*/
// Debug - Socket interface messages
-//#define CC3000_DEBUG_SOCKET
+#define CC3000_DEBUG_SOCKET
// Debug - HCI TX messages
-//#define CC3000_DEBUG_HCI_TX
+#define CC3000_DEBUG_HCI_TX
// Debug - HCI Rx messages
-//#define CC3000_DEBUG_HCI_RX
+#define CC3000_DEBUG_HCI_RX
// Debug - General Debug
-//#define CC3000_DEBUG
+#define CC3000_DEBUG
// Add colour to the debug messages, requires a VT100 terminal like putty, comment out to remove
-//#define VT100_COLOUR
+#define VT100_COLOUR
#ifdef CC3000_DEBUG_SOCKET
@@ -1543,6 +1544,7 @@
bool stop_smart_config;
bool dhcp_configured;
bool ok_to_shut_down;
+ bool enabled;
} tStatus;
/**
* \brief Ctor.
@@ -1584,7 +1586,15 @@
*/
void usync_callback(int32_t event_type, uint8_t *data, uint8_t length);
/**
- * \brief Connect to SSID (open/secured) with timeout (10ms).
+ * \brief Start connection to SSID (open/secured) non-blocking
+ * \param ssid SSID name
+ * \param key Security key (if key = 0, open connection)
+ * \param security_mode Security mode
+ * \return true if connection was established, false otherwise.
+ */
+ bool connect_non_blocking(const uint8_t *ssid, const uint8_t *key, int32_t security_mode);
+ /**
+ * \brief Connect to SSID (open/secured) with timeout (10s).
* \param ssid SSID name
* \param key Security key (if key = 0, open connection)
* \param security_mode Security mode
@@ -1606,6 +1616,11 @@
*/
bool connect_open(const uint8_t *ssid);
/**
+ * \brief Status of the cc3000 module.
+ * \return true if it's enabled, false otherwise.
+ */
+ bool is_enabled();
+ /**
* \brief Status of the cc3000 connection.
* \return true if it's connected, false otherwise.
*/
@@ -1683,6 +1698,35 @@
static cc3000 *get_instance() {
return _inst;
}
+#ifdef CC3000_ETH_COMPAT
+ /**
+ * \brief
+ * \param
+ * \return
+ */
+ char* getMACAddress();
+
+ /**
+ * \brief
+ * \param
+ * \return
+ */
+ char* getIPAddress();
+
+ /**
+ * \brief
+ * \param
+ * \return
+ */
+ char* getGateway();
+
+ /**
+ * \brief
+ * \param
+ * \return
+ */
+ char* getNetworkMask();
+#endif
public:
cc3000_simple_link _simple_link;
cc3000_event _event;
--- a/cc3000_event.cpp Sat Oct 12 14:27:46 2013 +0200
+++ b/cc3000_event.cpp Sat Oct 12 20:51:05 2013 +0000
@@ -198,6 +198,7 @@
#endif
}
+Timer timer;
uint8_t *cc3000_event::hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen) {
uint8_t *received_data, argument_size;
uint16_t length;
@@ -206,7 +207,11 @@
uint32_t return_value;
uint8_t * RecvParams;
uint8_t *RetParams;
-
+
+
+ timer.reset();
+ timer.start();
+
while (1)
{
if (_simple_link.get_data_received_flag() != 0)
@@ -396,8 +401,13 @@
//Read SSID
STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_SSID_LENGTH);
-
+ break;
+
+ default :
+ DBG_HCI("UNKNOWN Event Received : 0x%04X ", received_op_code);
+ break;
}
+
}
if (received_op_code == _simple_link.get_op_code())
{
@@ -440,6 +450,12 @@
return NULL;
}
}
+
+ if ( timer.read_ms() > 10000)
+ {
+ DBG_HCI("TIMEOUT Waiting for CC3000 Event - BAD");
+ break;
+ }
}
}
SimpleLink Wi-Fi CC3000
Avnet Wi-Go System