Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Servo X_NUCLEO_IKS01A2 X_NUCLEO_IDW01M1v2 NetworkSocketAPI NDefLib MQTT
Revision 0:cbf8bc43bc9e, committed 2016-04-08
- Comitter:
- mridup
- Date:
- Fri Apr 08 12:07:17 2016 +0000
- Child:
- 1:041e9f05738c
- Commit message:
- changes for optimization in Keil compiler
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NetworkSocketAPI/.hgtags Fri Apr 08 12:07:17 2016 +0000 @@ -0,0 +1,1 @@ +3c873fab420725fdc18466a9884e5c9d29e4fd0b address_mutators
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/DnsQuery/DnsQuery.cpp Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,214 @@
+/* Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include "DnsQuery.h"
+#include <stdio.h>
+#include <string.h>
+
+
+#define DNS_COUNT (sizeof DNS_IPS / sizeof DNS_IPS[0])
+const char *DNS_IPS[] = {
+ "8.8.8.8",
+ "209.244.0.3",
+ "84.200.69.80",
+ "8.26.56.26",
+ "208.67.222.222"
+};
+
+static bool isIP(const char *host)
+{
+ int i;
+
+ for (i = 0; host[i]; i++) {
+ if (!(host[i] >= '0' && host[i] <= '9') && host[i] != '.') {
+ return false;
+ }
+ }
+
+ // Ending with '.' garuntees host
+ if (i > 0 && host[i-1] == '.') {
+ return false;
+ }
+
+ return true;
+}
+
+
+static bool parseRR(uint8_t *resp, int &c, char *adr)
+{
+ int n = 0;
+ while((n=resp[c++]) != 0) {
+ if ((n & 0xc0) != 0) {
+ // This is a link
+ c++;
+ break;
+ } else {
+ // skip this segment, not interested in string domain names
+ c+= n;
+ }
+ }
+
+ int TYPE = (((int)resp[c])<<8) + resp[c+1];
+ int CLASS = (((int)resp[c+2])<<8) + resp[c+3];
+ int RDLENGTH = (((int)resp[c+8])<<8) + resp[c+9];
+
+ c+= 10;
+ if ((CLASS == 1) && (TYPE == 1)) {
+ sprintf(adr,"%d.%d.%d.%d", resp[c], resp[c+1], resp[c+2], resp[c+3]);
+ c+= RDLENGTH;
+ return true;
+ }
+ c+= RDLENGTH;
+
+ return false;
+}
+
+
+static bool resolve(unsigned char *resp, char *ipaddress)
+{
+
+ int ID = (((int)resp[0]) <<8) + resp[1];
+ int QR = resp[2] >>7;
+ int Opcode = (resp[2]>>3) & 0x0F;
+ int RCODE = (resp[3] & 0x0F);
+ int ANCOUNT = (((int)resp[6])<<8)+ resp[7];
+
+ if ((ID != 1) || (QR != 1) || (Opcode != 0) || (RCODE != 0)) {
+ return false;
+ }
+
+ int c = 12;
+ int d;
+ // Skip domain question
+ while( (d=resp[c++]) != 0) {
+ c+=d;
+ }
+ c+= 4; // skip QTYPE and QCLASS
+
+ // Here comes the resource record
+ for (int ans = 0 ; ans < ANCOUNT; ans++) {
+ if (parseRR(resp, c, ipaddress)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+int32_t dnsQuery(NetworkInterface *iface, const char *host, char *ip)
+{
+ if (isIP(host)) {
+ strcpy(ip, host);
+ return 0;
+ }
+
+ UDPSocket sock(iface);
+ int32_t err;
+
+ for (unsigned i = 0; i < DNS_COUNT; i++) {
+ err = sock.open(DNS_IPS[0], 53);
+ if (err < 0) {
+ return err;
+ }
+
+ err = dnsQuery(&sock, host, ip);
+ sock.close();
+ return err;
+ }
+
+ sock.close();
+ return NS_ERROR_DNS_FAILURE;
+}
+
+int32_t dnsQuery(UDPSocket *socket, const char *hostname, char *ipaddress)
+{
+ int len = 0;
+ if (hostname == NULL) {
+ return false;
+ }
+ len = strlen(hostname);
+ if ((len > 128) || (len == 0)) {
+ return false;
+ }
+
+ int packetlen = /* size of HEADER structure */ 12 + /* size of QUESTION Structure */5 + len + 1;
+ uint8_t *packet = new uint8_t[packetlen]; /* this is the UDP packet to send to the DNS */
+ if (packet == NULL) {
+ return false;
+ }
+
+ // Fill the header
+ memset(packet, 0, packetlen);
+ packet[1] = 1; // ID = 1
+ packet[5] = 1; // QDCOUNT = 1 (contains one question)
+ packet[2] = 1; // recursion requested
+
+ int c = 13; // point to NAME element in question section or request
+ int cnt = 12; // points to the counter of
+ packet[cnt] = 0;
+ for (int i = 0 ; i < len ; i++) {
+ if (hostname[i] != '.') {
+ // Copy the character and increment the character counter
+ packet[cnt]++;
+ packet[c++] = hostname[i];
+ } else {
+ // Finished with this part, so go to the next
+ cnt = c++;
+ packet[cnt] = 0;
+ }
+ }
+
+ // Terminate this domain name with a zero entry
+ packet[c++] = 0;
+
+ // Set QTYPE
+ packet[c++] = 0;
+ packet[c++] = 1;
+ // Set QCLASS
+ packet[c++] = 0;
+ packet[c++] = 1;
+
+
+ if (socket->send(packet, packetlen) < 0) {
+ delete packet;
+ return false;
+ }
+ delete packet;
+
+ packet = new uint8_t [1024];
+
+ // Receive the answer from DNS
+ int response_length = 0;
+ response_length = socket->recv(packet, 1024);
+
+ if (response_length > 0 ) {
+ if (!resolve(packet, ipaddress)) {
+ delete packet;
+ return NS_ERROR_DNS_FAILURE;
+ }
+
+ // cleanup and return
+ delete packet;
+ return 0;
+ }
+
+ delete packet;
+ return NS_ERROR_DNS_FAILURE;
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NetworkSocketAPI/DnsQuery/DnsQuery.h Fri Apr 08 12:07:17 2016 +0000 @@ -0,0 +1,41 @@ +/* + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef __DNSQUERY_H__ +#define __DNSQUERY_H__ + +#include "NetworkInterface.h" +#include "UDPSocket.h" + + +/** Function dnsQuery implements the functionality to query a domain name + * server for an IP-Address of a given hostname. + * @param iface : Network interface to use for DNS resolution. + * @param sock : Previously opened socket to use for DNS resolution. + * @param hostname : The hostname of interest as a string. + * Format must be without http:// or www. IE google.com, mbed.org, etc. + * If a standard IP Address is passed, it will be copied into ip unmodified. + * @param ipaddress : A reference to a IPADDRESS_t object which will receive + * the resolved IP Address of the host in question. + * @returns 0 on succes, NS_DNS_FAILURE if host is not found, + * or a negative value for other errors. + */ +int32_t dnsQuery(NetworkInterface *iface, const char *host, char *ip); +int32_t dnsQuery(UDPSocket *sock, const char *host, char *ip); + + +#endif // __DNSQUERY_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/EthernetInterface.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,39 @@
+/* EthernetInterface Base Class
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ETHERNET_INTERFACE_H
+#define ETHERNET_INTERFACE_H
+
+#include "NetworkInterface.h"
+
+/** EthernetInterface class
+ * Common interface that is shared between ethernet hardware
+ */
+class EthernetInterface : public NetworkInterface
+{
+public:
+ /** Start the interface
+ * @return 0 on success
+ */
+ virtual int32_t connect() = 0;
+
+ /** Stop the interface
+ * @return 0 on success
+ */
+ virtual int32_t disconnect() = 0;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/NetworkInterface.cpp Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,29 @@
+/* NetworkInterface Base Class
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "NetworkInterface.h"
+#include "DnsQuery.h"
+
+
+bool NetworkInterface::isConnected()
+{
+ return getIPAddress() != 0;
+}
+
+int32_t NetworkInterface::getHostByName(const char *name, char *ip)
+{
+ return dnsQuery(this, name, ip);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/NetworkInterface.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,91 @@
+/* NetworkInterface Base Class
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NETWORK_INTERFACE_H
+#define NETWORK_INTERFACE_H
+
+#include "SocketInterface.h"
+#include "stdint.h"
+
+/** Maximum storage needed for IP address and MAC addresses
+ */
+#define NS_IP_SIZE 16
+#define NS_MAC_SIZE 18
+
+/**
+ * @enum ns_error_t
+ * @brief enum of standardized error codes
+ */
+enum ns_error_t {
+ NS_ERROR_TIMEOUT = -3001, /*!< operation took longer than allowed */
+ NS_ERROR_NO_CONNECTION = -3002, /*!< not connected to a network */
+ NS_ERROR_NO_SOCKET = -3003, /*!< socket not available for use */
+ NS_ERROR_NO_ADDRESS = -3004, /*!< IP address is not known */
+ NS_ERROR_NO_MEMORY = -3005, /*!< memory resource not available */
+ NS_ERROR_DNS_FAILURE = -3006, /*!< DNS failed to complete successfully */
+ NS_ERROR_DHCP_FAILURE = -3007, /*!< DHCP failed to complete successfully */
+ NS_ERROR_AUTH_FAILURE = -3008, /*!< connection to access point faield */
+ NS_ERROR_DEVICE_ERROR = -3009 /*!< failure interfacing with the network procesor */
+};
+
+/** NetworkInterface class
+ * Common interface that is shared between all hardware that
+ * can connect to a network over IP.
+ */
+class NetworkInterface
+{
+public:
+ virtual ~NetworkInterface() {};
+
+ /** Get the IP address
+ * @return IP address of the interface or 0 if not yet connected
+ */
+ virtual const char *getIPAddress() = 0;
+
+ /** Get the current MAC address
+ * @return String MAC address of the interface
+ */
+ virtual const char *getMACAddress() = 0;
+
+ /** Get the current status of the interface
+ * @return true if connected
+ */
+ virtual bool isConnected();
+
+ /** Looks up the specified host's IP address
+ * @param name URL of host
+ * @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE
+ * @return 0 on success
+ */
+ virtual int32_t getHostByName(const char *name, char *ip);
+
+protected:
+ friend class Socket;
+
+ /** Internally create a socket
+ * @param proto The type of socket to open, NS_TCP or NS_UDP
+ * @return The allocated socket
+ */
+ virtual SocketInterface *createSocket(ns_protocol_t proto) = 0;
+
+ /** Internally destroy a socket
+ * @param socket An allocated SocketInterface
+ * @returns 0 on success
+ */
+ virtual void destroySocket(SocketInterface *socket) = 0;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/Socket.cpp Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,129 @@
+/* Socket
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Socket.h"
+#include <string.h>
+
+Socket::Socket(NetworkInterface *iface, ns_protocol_t proto)
+ : _iface(iface)
+ , _proto(proto)
+ , _socket(0)
+{
+ memset(_ip_address, 0, NS_IP_SIZE);
+ _port = 0;
+}
+
+Socket::~Socket()
+{
+ if (_socket) {
+ close();
+ }
+}
+
+
+int32_t Socket::open(const char *address, uint16_t port)
+{
+ int32_t err;
+
+ err = close();
+ if (err) {
+ return err;
+ }
+
+ err = _iface->getHostByName(address, _ip_address);
+ _port = port;
+ if (err) {
+ return err;
+ }
+
+ _socket = _iface->createSocket(_proto);
+ if (!_socket) {
+ return NS_ERROR_NO_SOCKET;
+ }
+
+ err = _socket->open(_ip_address, _port);
+
+ if (err) {
+ _iface->destroySocket(_socket);
+ _socket = 0;
+ }
+
+ return err;
+}
+
+int32_t Socket::close()
+{
+ if (!_socket) {
+ return 0;
+ }
+
+ int32_t err = _socket->close();
+
+ if (!err) {
+ _iface->destroySocket(_socket);
+ _socket = 0;
+ }
+
+ return err;
+}
+
+int32_t Socket::send(const void *data, uint32_t size)
+{
+ if (!_socket) {
+ return NS_ERROR_NO_CONNECTION;
+ }
+ return _socket->send(data, size);
+}
+
+int32_t Socket::recv(void *data, uint32_t size, bool blocking)
+{
+ if (!_socket) {
+ return NS_ERROR_NO_CONNECTION;
+ }
+
+ while (true) {
+ int32_t recv = _socket->recv(data, size);
+
+ if (recv != 0 || !blocking) {
+ return recv;
+ }
+ }
+}
+
+
+const char *Socket::getIPAddress() const
+{
+ if (_ip_address[0]) {
+ return _ip_address;
+ } else {
+ return 0;
+ }
+}
+
+uint16_t Socket::getPort() const
+{
+ return _port;
+}
+
+bool Socket::isConnected()
+{
+ if (!_socket) {
+ return false;
+ }
+
+ return _socket->isConnected();
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/Socket.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,85 @@
+/* Socket
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SOCKET_H
+#define SOCKET_H
+
+#include "NetworkInterface.h"
+
+/** Abstract socket class
+ * API for handling general sockets. Supports IP address operations
+ * and sending/recieving data.
+ */
+class Socket
+{
+public:
+ ~Socket();
+
+ /** Open a connection to the underlying address
+ * @param address URL or IP address to connect to
+ * @param port Port to connect to
+ * @return 0 on success
+ */
+ int32_t open(const char *address, uint16_t port);
+
+ /** Close an open connection
+ * @return 0 on success
+ */
+ int32_t close();
+
+ /** Send data over the socket
+ * @param data Buffer of data to send
+ * @param size Size of data to send
+ * @return 0 on success
+ */
+ int32_t send(const void *data, uint32_t size);
+
+ /** Recieve data over the socket
+ * @param data Buffer to store recieved data
+ * @param size Size of provided buffer
+ * @param blocking If true wait for data, otherwise return 0 if no data is available
+ * @return Number of bytes recieved or a negative value on failure
+ */
+ int32_t recv(void *data, uint32_t size, bool blocking = true);
+
+ /** Gets the IP address
+ * @return IP address to connect to
+ */
+ const char *getIPAddress() const;
+
+ /** Gets the port
+ * @return Port to connect to
+ */
+ uint16_t getPort() const;
+
+ /** Returns status of socket
+ * @return true if connected
+ */
+ bool isConnected();
+
+protected:
+ Socket(NetworkInterface *iface, ns_protocol_t proto);
+
+private:
+ NetworkInterface *_iface;
+ ns_protocol_t _proto;
+ SocketInterface *_socket;
+
+ char _ip_address[NS_IP_SIZE];
+ uint16_t _port;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/SocketInterface.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,83 @@
+/* SocketInterface Base Class
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SOCKET_INTERFACE_H
+#define SOCKET_INTERFACE_H
+
+#include "stdint.h"
+
+
+/**
+ * @enum ns_protocol_t
+ * @brief enum of socket protocols
+ */
+enum ns_protocol_t {
+ NS_TCP, /*!< Socket is of TCP type */
+ NS_UDP, /*!< Socket is of UDP type */
+};
+
+
+/** SocketInterface class
+ * Common interface for implementation specific sockets created through
+ * network interfaces. This class is used internally by the
+ * TCPSocket and UDPSocket classes
+ */
+class SocketInterface
+{
+public:
+
+ virtual ~SocketInterface() {}
+
+ /** Open a connection to the underlying address
+ * @param ip IP address to connect to
+ * @param port Port to connect to
+ * @return 0 on success
+ */
+ virtual int32_t open(const char *ip, uint16_t port) = 0;
+
+ /** Close an open connection
+ * @return 0 on success
+ */
+ virtual int32_t close() = 0;
+
+ /** Send data
+ * @param data Buffer of data to send
+ * @param size Size of data to send
+ * @return 0 on success
+ */
+ virtual int32_t send(const void *data, uint32_t size) = 0;
+
+ /** Receive data
+ * @note
+ * This call should return immediately with a value of 0
+ * if no data is available.
+ *
+ * @param data A buffer to store the data in
+ * @param size Size of buffer
+ * @return Number of bytes received or a negative value on failure
+ */
+ virtual int32_t recv(void *data, uint32_t size) = 0;
+
+ /** Status of the socket
+ * @return True if connected
+ */
+ virtual bool isConnected() {
+ // By default return true if socket was created successfully
+ return true;
+ }
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/TCPSocket.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,39 @@
+/* TCPSocket
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TCP_SOCKET_H
+#define TCP_SOCKET_H
+
+#include "Socket.h"
+
+/** TCPSocket class
+ * API for handling TCP sockets. The implementation is determined
+ * by the interface passed during construction.
+ */
+class TCPSocket : public Socket
+{
+public:
+ /** Create a socket using the specified network interface
+ * No network operations are performed until the socket is actually used
+ * @param iface The network interface to use
+ * @param url Optional URL to connect to, copied internally
+ * @param port Optional port to connect to
+ */
+ TCPSocket(NetworkInterface *iface)
+ : Socket(iface, NS_TCP) {}
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/UDPSocket.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,39 @@
+/* UDPSocket
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UDP_SOCKET_H
+#define UDP_SOCKET_H
+
+#include "Socket.h"
+
+/** UDPSocket class
+ * API for handling UDP sockets. The implementation is determined
+ * by the interface passed during construction.
+ */
+class UDPSocket : public Socket
+{
+public:
+ /** Create a socket using the specified network interface
+ * No network operations are performed until the socket is actually used
+ * @param iface The network interface to use
+ * @param ip Optional URL to connect to, copied internally
+ * @param port Optional port to connect to
+ */
+ UDPSocket(NetworkInterface *iface)
+ : Socket(iface, NS_UDP) {}
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI/WiFiInterface.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,52 @@
+/* WiFiInterface Base Class
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFI_INTERFACE_H
+#define WIFI_INTERFACE_H
+
+#include "NetworkInterface.h"
+
+/** Enum for WiFi encryption types
+ */
+enum ns_security_t {
+ NS_SECURITY_NONE = 0, /*!< open access point */
+ NS_SECURITY_WEP, /*!< phrase conforms to WEP */
+ NS_SECURITY_WPA, /*!< phrase conforms to WPA */
+ NS_SECURITY_WPA2, /*!< phrase conforms to WPA2 */
+};
+
+
+/** WiFiInterface class
+ * Common interface that is shared between WiFi devices
+ */
+class WiFiInterface : public NetworkInterface
+{
+public:
+ /** Start the interface
+ * @param ssid Name of the network to connect to
+ * @param pass Security passphrase to connect to the network
+ * @param security Type of encryption to connect with
+ * @return 0 on success
+ */
+ virtual int32_t connect(const char *ssid, const char *pass, ns_security_t security = NS_SECURITY_NONE) = 0;
+
+ /** Stop the interface
+ * @return 0 on success
+ */
+ virtual int32_t disconnect() = 0;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/SPWFInterface.cpp Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,177 @@
+/* SpwfSAInterface implementation of NetworkInterfaceAPI
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SPWFInterface.h"
+
+// Various timeouts for different SPWF operations
+#define SPWF_CONNECT_TIMEOUT 20000
+#define SPWF_SEND_TIMEOUT 500
+#define SPWF_RECV_TIMEOUT 10000
+#define SPWF_MISC_TIMEOUT 15000
+
+/**
+ * The singleton which represents the SpwfSAInterface.
+ *
+ */
+static SpwfSAInterface spwf_device(PA_9, PA_10, PC_12, PC_8, PA_12, true);
+
+/**
+* Export the instance to the user.
+*/
+SpwfSAInterface *createSPWFInstance(void)
+{
+ return (&spwf_device);
+}
+
+// SpwfSAInterface implementation
+SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, PinName rst, PinName wkup, PinName rts, bool debug)
+ : _spwf(tx, rx, rst, wkup, rts)
+{
+ memset(_ids, 0, sizeof(_ids));
+}
+
+SpwfSAInterface::~SpwfSAInterface()
+{
+}
+
+int32_t SpwfSAInterface::init(void)
+{
+ _spwf.setTimeout(SPWF_MISC_TIMEOUT);
+ return (_spwf.init());
+}
+
+int32_t SpwfSAInterface::connect(
+ const char *ap,
+ const char *pass_phrase,
+ ns_security_t security)
+{
+ _spwf.setTimeout(SPWF_CONNECT_TIMEOUT);
+
+ if(security == NS_SECURITY_WPA2) return NS_ERROR_DEVICE_ERROR;
+
+ WiFi_Priv_Mode mode = (WiFi_Priv_Mode)security;
+
+ return (_spwf.connect((char*)ap, (char*)pass_phrase, mode));//0 on success
+}
+
+int32_t SpwfSAInterface::disconnect()
+{
+ //_spwf.setTimeout(SPWF_SEND_TIMEOUT);
+
+ return (_spwf.disconnect());
+}
+
+const char *SpwfSAInterface::getIPAddress()
+{
+ return _spwf.getIPAddress();
+}
+
+const char *SpwfSAInterface::getMACAddress()
+{
+ return _spwf.getMACAddress();
+}
+
+void SpwfSAInterface::setid(bool set, int id)
+{
+ if(set)
+ _ids[id] = true;
+ else
+ _ids[id] = false;
+}
+
+SocketInterface *SpwfSAInterface::createSocket(ns_protocol_t proto)
+{
+ return new SpwfSASocket(this, &_spwf, proto);
+}
+
+void SpwfSAInterface::destroySocket(SocketInterface *iface)
+{
+ SpwfSASocket *socket = (SpwfSASocket *)iface;
+ _ids[socket->_id] = false;
+ delete socket;
+}
+
+
+// SpwfSASocket implementation
+int32_t SpwfSAInterface::SpwfSASocket::open(const char *ip, uint16_t port)
+{
+ uint8_t sock_id = -1;
+
+ //__spwf->setTimeout(SPWF_SEND_TIMEOUT);
+
+ const char *proto = (_proto == NS_UDP) ? "u" : "t";//"s" for secure socket?
+
+ __spwf->socket_client_open((uint8_t*)ip, (uint32_t)port, (uint8_t *)proto, &sock_id);
+
+ //TODO: Maintain a socket table to map socket ID to host & port
+ //TODO: lookup on client table to see if already socket is allocated to same host/port
+ //multimap <char *, vector <uint16_t> > ::iterator i = c_table.find((char*)ip);
+
+ if(sock_id <= SPWFSA_SOCKET_COUNT)
+ {
+ _id = sock_id;//the socket ID of this Socket instance
+ _itf->setid(true, _id);
+ //_itf->c_table.insert(pair <char *, vector <uint16_t> > ((char*)ip, port));
+ }
+ else
+ return NS_ERROR_NO_SOCKET;
+
+ return 0;//0 means SUCCESS
+}
+
+int32_t SpwfSAInterface::SpwfSASocket::close()
+{
+ int32_t err;
+
+ //__spwf->setTimeout(SPWF_SEND_TIMEOUT);
+
+ _itf->setid(false, _id);
+ //_itf->c_table.empty();
+
+ err = __spwf->socket_client_close((uint8_t)_id);
+
+ return err;
+}
+
+int32_t SpwfSAInterface::SpwfSASocket::send(const void *data, uint32_t size)
+{
+ int32_t err;
+
+ //__spwf->setTimeout(SPWF_SEND_TIMEOUT);
+
+ err = __spwf->socket_client_write((uint8_t)_id, (uint16_t)size, (char*)data);
+
+ return err;
+}
+
+//return no of bytes read
+int32_t SpwfSAInterface::SpwfSASocket::recv(void *data, uint32_t size)
+{
+ int32_t recv;
+
+ __spwf->setTimeout(SPWF_RECV_TIMEOUT);
+
+ recv = __spwf->socket_client_recv((uint8_t)_id, (uint16_t)size, (char*)data);
+
+
+ return recv;
+
+}
+
+void SpwfSAInterface::debug(const char * string)
+{
+ _spwf.debug_print(string);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/SPWFInterface.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,94 @@
+/* SpwfSAInterface implementation of NetworkInterfaceAPI
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SPWFSA_INTERFACE_H
+#define SPWFSA_INTERFACE_H
+
+#include <vector>
+#include <map>
+#include "WiFiInterface.h"
+#include "x-nucleo-idw01m1.h"
+
+#define SPWFSA_SOCKET_COUNT 8
+
+/** SpwfSAInterface class
+ * Implementation of the NetworkInterface for the SPWF Device
+ */
+class SpwfSAInterface : public WiFiInterface
+{
+public:
+
+ SpwfSAInterface(PinName tx, PinName rx, PinName rst, PinName wkup, PinName rts, bool debug = false);
+ virtual ~SpwfSAInterface();
+
+ // Implementation of WiFiInterface
+ virtual int32_t connect(
+ const char *ssid,
+ const char *pass,
+ ns_security_t security = NS_SECURITY_NONE);
+
+ virtual int32_t disconnect();
+
+ // Implementation of NetworkInterface
+ virtual const char *getIPAddress();
+ virtual const char *getMACAddress();
+
+ virtual SocketInterface *createSocket(ns_protocol_t proto);
+ virtual void destroySocket(SocketInterface *socket);
+
+ int32_t init(void);
+ void debug(const char * string);
+ void setid(bool set, int id);
+
+private:
+
+ SpwfSADevice _spwf;
+ bool _ids[SPWFSA_SOCKET_COUNT];
+ multimap <char *, vector <uint16_t> > c_table;
+
+ // Implementation of the SocketInterface for the SpwfSA
+ class SpwfSASocket : public SocketInterface
+ {
+ public:
+
+ // SpwfSA specific details
+ SpwfSADevice *__spwf;
+ SpwfSAInterface *_itf;
+ ns_protocol_t _proto;
+ int _id;
+
+ SpwfSASocket(SpwfSAInterface *itf, SpwfSADevice *spwf, ns_protocol_t proto)
+ : __spwf(spwf), _itf(itf), _proto(proto) {}
+
+ virtual ~SpwfSASocket() {
+ _itf = 0;
+ __spwf = 0;
+ }
+
+ // Implementation of SocketInterface
+ virtual int32_t open(const char *ip, uint16_t port);
+ virtual int32_t close();
+
+ virtual int32_t send(const void *data, uint32_t size);
+ virtual int32_t recv(void *data, uint32_t size);
+ };
+
+};
+
+/*Function to export singleton instance*/
+SpwfSAInterface *createSPWFInstance(void);
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/WIFI_API/x-nucleo-idw01m1.cpp Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,399 @@
+/* mbed Microcontroller Library
+* Copyright (c) 2006-2013 ARM Limited
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/**
+ ******************************************************************************
+ * @file x-nucleo-idw01m1.cpp
+ * @author STMicroelectronics
+ * @brief Implementation of SpwfSADevice class for Wi-Fi mbed
+ ******************************************************************************
+ * @copy
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
+ ******************************************************************************
+ */
+
+
+#include "x-nucleo-idw01m1.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void Rx_irq_handler(void);
+void Wifi_scheduler(void);
+void Wifi_ticker(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+extern void setSpwfSADevice(SpwfSADevice * dev);
+
+SpwfSADevice::SpwfSADevice(PinName tx, PinName rx, PinName rst, PinName wkup, PinName rts):
+ uart_(tx,rx),
+ term_(SERIAL_TX, SERIAL_RX),
+ wakeup_(wkup, PIN_INPUT, PullNone, 0),
+ rst_(rst, PIN_INPUT, PullUp, 1),
+ rts_(rts, PIN_INPUT, PullUp, 0)
+{
+ setSpwfSADevice(this);
+ sync_wait_signal = false;
+}
+
+SpwfSADevice::~SpwfSADevice(void)
+{
+ //de-constructor
+}
+
+int32_t SpwfSADevice::init(void)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ Timer timer;
+
+ timer.start();
+ rst_.output();
+ wakeup_.output();
+ rts_.output();
+
+ term_.baud(9600);
+ term_.format(8, SerialBase::None, 1);
+
+ uart_.baud(115200);
+ uart_.format(8, SerialBase::None, 1);
+ uart_.set_flow_control(SerialBase::RTS, PA_12, NC);//RTSCTS
+ uart_.attach(Rx_irq_handler, SerialBase::RxIrq);
+
+ config.power=wifi_active;
+ config.power_level=high;
+ config.dhcp=on;//use DHCP IP address
+
+ /*Initialize the tickers*/
+ wifi_isr.attach_us(Wifi_ticker, 1000); //decreasing the time period to 1ms may be causing overrun issue with UART?\
+ //UART error not evident but characters are sometimes missing in pipeline(ring_buffer)\
+ //specifically in the +WIND:25:WiFi Association with 'STM' successful WIND (why specifically this?)
+
+ wifi_callback.attach_us(Wifi_scheduler, 2000);//How low can we go?
+
+ sync_wait_signal = false;
+ status = wifi_init(&config);
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return -1;
+ }
+
+ while(!sync_wait_signal)
+ {
+ if (timer.read_ms() > _timeout) {
+ return -1;
+ }
+ asm("NOP");
+ }
+
+ return 0;
+}
+
+int32_t SpwfSADevice::connect(char * ssid, char * sec_key, WiFi_Priv_Mode priv_mode)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ Timer timer;
+
+ timer.start();
+ sync_wait_signal = false;
+ status = wifi_connect(ssid, sec_key, priv_mode);
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return -1;
+ }
+
+ while(!sync_wait_signal)
+ {
+ if (timer.read_ms() > _timeout) {
+ return -1;
+ }
+ asm("NOP");
+ }
+
+ return 0;
+}
+
+int32_t SpwfSADevice::disconnect()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ status = wifi_disconnect();
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+const char *SpwfSADevice::getIPAddress()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ status = WiFi_Get_IP_Address((uint8_t *)_ip_buffer);
+
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return NULL;
+ } else
+ return _ip_buffer;
+}
+
+const char *SpwfSADevice::getMACAddress()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ status = WiFi_Get_MAC_Address((uint8_t *)_mac_buffer);
+
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return NULL;
+ } else
+ return _mac_buffer;
+}
+
+int32_t SpwfSADevice::socket_client_open(uint8_t * hostname, uint32_t port_number, uint8_t * protocol, uint8_t * sock_id)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ //Timeout of synchronous functions?
+ status = wifi_socket_client_open(hostname, port_number, protocol, sock_id);
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ *sock_id = 9;//make sure socket id is not set(set to out of bounds of SPWFSA_SOCKET_COUNT range)
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int32_t SpwfSADevice::socket_client_write(uint8_t sock_id, uint16_t DataLength,char * pData)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ status = wifi_socket_client_write(sock_id, DataLength, pData);
+ //map error to enum ns_error_t
+
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return -1;
+ }
+ return 0;
+}
+
+
+int32_t SpwfSADevice::socket_client_recv(uint8_t sock_id, uint16_t RecvLength,char * pData)
+{
+ Timer timer;
+
+ timer.start();
+ bytes_to_read = RecvLength;
+
+ __disable_irq();
+ bytes_read=0;
+ sync_wait_signal = false;
+ recv_buff = (uint8_t*)pData;
+ __enable_irq();
+
+ while(!sync_wait_signal)
+ {
+ if (timer.read_ms() > _timeout) {
+ sync_wait_signal = true;
+ if(bytes_read==0) return -1;//return error if no bytes are read!
+ return bytes_read;//return amount of data arrived so far
+ }
+ asm("NOP");
+ }
+
+ return bytes_read;
+
+}
+
+void SpwfSADevice::network_scan(wifi_scan *scan_result, uint16_t max_scan_number)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ status = wifi_network_scan(scan_result, max_scan_number);
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return;
+ }
+}
+
+void SpwfSADevice::http_get(uint8_t * hostname, uint8_t * path, uint32_t port_number)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ status = wifi_http_get((uint8_t *)hostname, (uint8_t *)path, port_number);
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return;
+ }
+}
+
+void SpwfSADevice::http_post(uint8_t * url_path)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ status = wifi_http_post(url_path);
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return;
+ }
+}
+
+void SpwfSADevice::signal_data_receive(uint8_t socket_id, uint8_t * data_ptr, uint32_t message_size, uint32_t chunk_size)
+{
+ char debug_str[10];
+ //Data will be copied or returned to user only if there is a pending request
+ //Copy data to pData
+ if(recv_buff && !sync_wait_signal)
+ {
+ if((bytes_read + message_size)<= bytes_to_read)
+ {
+ memcpy(recv_buff + bytes_read, data_ptr, message_size);//only copy bytes_to_read asked by user//rest of the data is lost!!
+ bytes_read += message_size;
+ }
+ else
+ {
+ uint32_t x_size = (bytes_read + message_size) - bytes_to_read;
+ memcpy(recv_buff + bytes_read, data_ptr, message_size-x_size);
+ bytes_read += (message_size-x_size);
+ }
+
+ if(bytes_read >= bytes_to_read)
+ {
+ __disable_irq();
+ sync_wait_signal = true;
+ __enable_irq();
+ }
+ }
+ else
+ {
+ debug_print("\r\n Socket:: Data Dropped: ");
+ sprintf((char*)debug_str,"%d\r\n",message_size);
+ debug_print(debug_str);
+ __disable_irq();
+ sync_wait_signal = true;
+ __enable_irq();
+ }
+
+}
+
+void SpwfSADevice::signal_synch_wait(WiFi_Status_t code)
+{
+ if(code == WiFi_DISASSOCIATION)
+ {
+ //do nothing
+ }
+ else
+ {
+ __disable_irq();
+ sync_wait_signal = true;
+ __enable_irq();
+ }
+}
+
+int32_t SpwfSADevice::socket_client_close(uint8_t sock_close_id)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ status = wifi_socket_client_close(sock_close_id);
+ //map error to enum ns_error_t
+ if(status!=WiFi_MODULE_SUCCESS)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+
+void SpwfSADevice::spwf_attach_irq(wifi_bool attach)
+{
+ if(attach)
+ {
+ uart_.attach(Rx_irq_handler, SerialBase::RxIrq);
+ }
+ else
+ {
+ //rts_ = DigitalInOut(PA_12, PIN_INPUT, PullDown, 0);
+ //STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)
+ //pin_function(PA_12, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, GPIO_AF7_USART1));
+ //pin_mode(PA_12, PullUp);
+ }
+}
+
+void SpwfSADevice::spwf_send(const char * cmd, uint16_t size)
+{
+ Timer timer;
+ int i;
+ //timer.start();
+
+ //uart_.puts(cmd);//string may contain '\0' character in between hence not used
+
+ for(i=0;i<size;i++)
+ {
+ uart_.putc(cmd[i]);
+ //if (timer.read_ms() > _timeout) {
+ //return -1;
+ //}
+ }
+}
+
+char SpwfSADevice::spwf_get(void)
+{
+ return(uart_.getc());
+}
+
+void SpwfSADevice::spwf_wakeup(int wake)
+{
+ wakeup_.write(wake);
+}
+
+void SpwfSADevice::spwf_reset(int reset)
+{
+ rst_.write(reset);
+}
+
+void SpwfSADevice::spwf_rts(int rts)
+{
+ rts_.write(rts);
+}
+
+int SpwfSADevice::spwf_read_rts()
+{
+ return(rts_.read());
+}
+
+void SpwfSADevice::debug_print(const char * string)
+{
+ term_.puts(string);
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/WIFI_API/x-nucleo-idw01m1.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,115 @@
+/* mbed Microcontroller Library
+* Copyright (c) 2006-2013 ARM Limited
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/**
+ ******************************************************************************
+ * @file x-nucleo-idw01m1.h
+ * @author STMicroelectronics
+ * @brief Header File of SpwfSADevice class for Wi-Fi mbed
+ ******************************************************************************
+ * @copy
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
+ ******************************************************************************
+ */
+
+#ifndef __SPWFSA_DEVICE_H__
+#define __SPWFSA_DEVICE_H__
+
+
+#include "mbed.h"
+#include "RawSerial.h"
+#include "Ticker.h"
+#include "Timer.h"
+#include "wifi_interface.h"
+
+
+/*Class describing the SPWF Device*/
+class SpwfSADevice
+{
+
+public:
+ SpwfSADevice(PinName tx, PinName rx, PinName rst, PinName wkup, PinName rts);
+ ~SpwfSADevice(void);
+
+ int32_t init(void);
+ int32_t connect(char * ssid, char * sec_key, WiFi_Priv_Mode priv_mode);
+ int32_t disconnect(void);
+ const char *getIPAddress();
+ const char *getMACAddress();
+ void network_scan(wifi_scan *scan_result, uint16_t max_scan_number);
+
+ int32_t socket_client_open(uint8_t * hostname, uint32_t port_number, uint8_t * protocol, uint8_t * sock_id);
+ int32_t socket_client_write(uint8_t sock_id, uint16_t DataLength,char * pData);
+ int32_t socket_client_recv(uint8_t sock_id, uint16_t RecvLength,char * pData);
+ int32_t socket_client_close(uint8_t sock_close_id);
+ void socket_client_security(uint8_t* tls_mode, uint8_t* root_ca_server, uint8_t* client_cert, uint8_t* client_key, uint8_t* client_domain, uint32_t tls_epoch_time);
+
+ void socket_server_open(uint32_t port_number, uint8_t * protocol);
+ void socket_server_write(uint16_t DataLength,char * pData);
+ void socket_server_close(void);
+
+ void http_get(uint8_t * hostname, uint8_t * path, uint32_t port_number);
+ void http_post(uint8_t * url_path);
+
+ /*These functions should be pure virtual functions for ppl to derive and implement there own stuff*/
+ char spwf_get(void);
+ void spwf_send(const char * cmd, uint16_t size);
+ void spwf_wakeup(int wake);
+ void spwf_reset(int reset);
+ void spwf_rts(int rts);
+ void spwf_attach_irq(wifi_bool attach);
+ int spwf_read_rts();
+
+ const char *getVersion(void);
+ void waitForEvent(void);
+ void signal_data_receive(uint8_t socket_id, uint8_t * data_ptr, uint32_t message_size, uint32_t chunk_size);
+ void signal_synch_wait(WiFi_Status_t code);
+ bool getIsInitialized(void);
+ void setTimeout(int timeout) {
+ _timeout = timeout;
+ }
+ void debug_print(const char * string);
+
+private:
+ bool isInitialized;
+
+ RawSerial uart_;
+ RawSerial term_;
+ Ticker wifi_isr;
+ Ticker wifi_callback;
+ DigitalInOut wakeup_;
+ DigitalInOut rst_;
+ DigitalInOut rts_;
+ wifi_config config;
+ bool sync_wait_signal;
+ uint16_t bytes_read;
+ uint16_t bytes_to_read;
+ uint8_t * recv_buff;
+ int _timeout;
+
+ char _ip_buffer[16];
+ char _mac_buffer[18];
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/intermediate.cpp Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,159 @@
+/* mbed Microcontroller Library
+* Copyright (c) 2006-2013 ARM Limited
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/**
+ ******************************************************************************
+ * @file intermediate.c
+ * @author STMicroelectronics
+ * @brief Wrapper Functions for access to SPWFSADevice class/vice-versa
+ ******************************************************************************
+ * @copy
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
+ ******************************************************************************
+ */
+
+#include "x-nucleo-idw01m1.h"
+
+SpwfSADevice * device;
+
+void setSpwfSADevice(SpwfSADevice * dev);
+
+void setSpwfSADevice(SpwfSADevice * dev)
+ {
+ device = dev;
+ }
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+void callSpwfSADevice_init(void* object);
+char callSpwfSADevice_getChar(void* object);
+void callSpwfSADevice_write(void* object, const char * cmd, uint16_t size);
+void callSpwfSADevice_wakeup(void* object, int wake);
+void callSpwfSADevice_reset(void* object, int reset);
+void callSpwfSADevice_rts(void* object, int rts);
+void callSpwfSADevice_attach(wifi_bool attach);
+void callSpwfSADevice_debug(void* object, const char * string);
+void destroySpwfSADevice(void);
+int callSpwfSADevice_read_rts(void* object);
+
+
+void callSpwfSADevice_init(void* object)
+ {
+ //static_cast<SpwfSADevice*>(object)->init();
+ device->init();
+ return;
+ }
+
+char callSpwfSADevice_getChar(void* object)
+ {
+ return(device->spwf_get());
+ }
+
+void callSpwfSADevice_write(void* object, const char * cmd, uint16_t size)
+ {
+ device->spwf_send(cmd, size);
+ }
+
+void callSpwfSADevice_wakeup(void* object, int wake)
+{
+ device->spwf_wakeup(wake);
+}
+
+void callSpwfSADevice_reset(void* object, int reset)
+{
+ device->spwf_reset(reset);
+}
+
+void callSpwfSADevice_rts(void* object, int rts)
+{
+ device->spwf_rts(rts);
+}
+
+int callSpwfSADevice_read_rts(void* object)
+{
+ return(device->spwf_read_rts());
+}
+
+void callSpwfSADevice_attach(wifi_bool attach)
+{
+ device->spwf_attach_irq(attach);
+}
+
+void callSpwfSADevice_debug(void* object, const char * string)
+{
+ device->debug_print(string);
+}
+
+void destroySpwfSADevice()
+ {
+
+ }
+
+/*Callbacks implementation*/
+
+void ind_wifi_on()
+{
+ device->signal_synch_wait(WiFi_MODULE_SUCCESS);
+}
+
+void ind_wifi_connected()
+{
+ device->signal_synch_wait(WiFi_MODULE_SUCCESS);
+}
+
+void ind_wifi_connection_error(WiFi_Status_t code)
+{
+ switch(code)
+ {
+ case WiFi_DISASSOCIATION:
+ device->signal_synch_wait(code);
+ break;
+ case WiFi_DE_AUTH:
+ break;
+ default:
+ break;
+ }
+}
+
+void ind_wifi_socket_data_received(uint8_t socket_id, uint8_t * data_ptr, uint32_t message_size, uint32_t chunk_size)
+{
+ device->signal_data_receive(socket_id, data_ptr, message_size, chunk_size);
+}
+
+void ind_wifi_http_data_available(uint8_t * data_ptr, uint32_t message_size)
+{
+ //spwf->debug("\r\nrx>>\r\n");
+ //memcpy(user_buffer, data_ptr, 511);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/intermediate.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,19 @@
+ // intermediate.h
+
+#ifndef __INTERMEDIATE_H__
+#define __INTERMEDIATE_H__
+
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
+
+
+ #ifdef __cplusplus
+ extern }
+ #endif
+
+
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/inc/wifi_const.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,131 @@
+/**
+ ******************************************************************************
+ * @file wifi_const.h
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief Describes the constants and defines in X-CUBE-WIFI1
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/** @defgroup NUCLEO_WIFI_INTERFACE_Private_Defines
+ * @{
+ */
+
+#define EPOCH_TIME 1453727657//Human time (GMT): Mon, 25 Jan 2016 13:14:17 GMT
+#define EXTI_CONF_TIMER 1900 //millisec
+#define PROCESS_WIFI_TIMER 1
+#define SLEEP_RESUME_PREVENT 2000
+#define RINGBUF_SIZE 2048//1024//3072//2048
+#define MAX_BUFFER_GLOBAL 512
+#define MAX_PREFETCH_BUFFER 20
+#define MAX_WIFI_SCAN_NETWORK 256
+#define RxBufferSize 64
+#define AT_RESP_LEN_OK 6 //\r\nOK\r\n
+#define AT_RESP_LEN_GPIOR 21//GPIO n = 0,in\r\n\r\nOK\r\n
+#define AT_RESP_HELP_TEXT_LEN 512
+#define AT_ATTENTION "AT\r"
+#define AT_WIFI_ENABLE "AT+S.WIFI=%d\r"
+#define AT_GET_CONFIGURATION_VALUE "AT+S.GCFG=%s\r"
+#define AT_SET_CONFIGURATION_VALUE "AT+S.SCFG=%s,%d\r"
+#define AT_SET_CONFIGURATION_ADDRESS "AT+S.SCFG=%s,%s\r"
+//#define AT_GET_SSID "AT&F\r"
+#define AT_SET_SSID "AT+S.SSIDTXT=%s\r"
+#define AT_SET_SEC_KEY "AT+S.SCFG=wifi_wpa_psk_text,%s\r"
+#define AT_RESTORE_DEFAULT_SETTING "AT&F\r"
+#define AT_SAVE_CURRENT_SETTING "AT&W\r"
+#define AT_SET_POWER_STATE "AT+CFUN=%d\r"
+#define AT_HELP_TEXT "AT+S.HELP\r"
+#define AT_RESET_MSG "\r\n+WIND:2:Reset\r\n"
+
+#define UNDEFINE_LENGTH 0xFFFF
+#define AT_WiFi_SCAN "AT+S.SCAN\r"
+#define AT_SOCKET_OPEN "AT+S.SOCKON=%s,%d,%s,ind\r"
+#define AT_SOCKET_WRITE "AT+S.SOCKW=%d,%d\r"
+#define AT_SOCKET_READ "AT+S.SOCKR=%d,%d\r"
+#define AT_SOCKET_CLOSE "AT+S.SOCKC=%d\r"
+#define AT_SERVER_SOCKET_OPEN "AT+S.SOCKD=%d,%s,ind\r" //with indication option
+#define AT_SERVER_SOCKET_CLOSE "AT+S.SOCKD=0\r"
+#define AT_QUERY_PENDING_DATA "AT+S.SOCKQ=%d\r"
+#define AT_DISPLAY_FILE_NAME "AT+S.FSL\r"
+#define AT_DISPLAY_FILE_CONTENT "AT+S.FSP=/%s\r"
+#define AT_CREATE_NEW_HTML_FILE "AT+S.FSC=/%s,%d\r"
+#define AT_APPEND_FILE "AT+S.FSA=/%s,%d\r"
+#define AT_DELETE_FILE "AT+S.FSD=/%s\r"
+#define AT_DOWNLOAD_IMAGE_FILE "AT+S.HTTPDFSUPDATE=%s,/%s,%d\r"
+#define AT_ERASE_FLASH_MEMORY "AT+S.HTTPDFSERASE\r"
+
+#define AT_CMD_TO_DATA_MODE "AT+S.\r"
+#define AT_DATA_TO_CMD_MODE "at+s." /* NOT \r */
+#define AT_HTTPPOST_REQUEST "AT+S.HTTPPOST=%s\r"
+#define AT_HTTPD "AT+S.HTTPD=%d\r"
+#define AT_GET_STATUS_VALUE "AT+S.STS=%s\r"
+
+/************Wi-Fi Config Variables**************/
+
+#define BLINK_LED "blink_led"
+#define LOCALECHO1 "localecho1"
+#define CONSOLE1_HWFC "console1_hwfc"
+#define CONSOLE1_SPEED "console1_speed"
+#define WIFI_PRIV_MODE "wifi_priv_mode"
+#define IP_USE_DHCP_SERVER "ip_use_dhcp"
+#define IP_USE_HTTPD "ip_use_httpd"
+#define WIFI_MODE "wifi_mode"
+#define WIFI_WPA_SECURITY "wifi_wpa_psk_text"
+#define WIFI_CHANNEL_NUMBER "wifi_channelnum"
+#define WIFI_IP_ADDRESS "ip_ipaddr"
+#define WIFI_IP_DEFAULT_GATEWAY "ip_gw"
+#define WIFI_IP_DNS "ip_dns"
+#define WIFI_IP_NETMASK "ip_netmask"
+#define WIFI_IP_HOSTNAME "ip_hostname"
+#define WIFI_IP_APDOMAINNAME "ip_apdomainname"
+#define WIFI_IP_APREDIRECT "ip_apredirect"
+#define WIFI_IP_HTTP_TIMEOUT "ip_http_get_recv_timeout"
+#define WIFI_IP_DHCP_TIMEOUT "ip_dhcp_timeout"
+
+#define WIFI_SLEEP_ENABLED "sleep_enabled"
+#define WIFI_HT_MODE "wifi_ht_mode"
+#define WIFI_OPR_RATE_MASK "wifi_opr_rate_mask"
+#define WIFI_POWERSAVE "wifi_powersave"
+#define WIFI_OPERATIONAL_MODE "wifi_operational_mode"
+#define WIFI_LISTEN_INTERVAL "wifi_listen_interval"
+#define WIFI_BEACON_WAKEUP "wifi_beacon_wakeup"
+#define WIFI_STANDBY_ENABLED "standby_enabled"
+#define WIFI_STANDBY_TIME "standby_time"
+#define WIFI_TX_POWER "wifi_tx_power"
+#define WIFI_IBSS_IP_ADDR "192.168.2.100"
+#define WIFI_IBSS_DEFAULT_GATEWAY "192.168.2.1"
+#define WIFI_IBSS_IP_DNS_ADDR "192.168.2.1"
+#define WIFI_IBSS_IP_MASK "255.255.255.0"
+#define WIFI_IP_USE_DHCP 0
+
+/**
+ * @}
+ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_IDW01M1/spwf/inc/wifi_driver.h Fri Apr 08 12:07:17 2016 +0000 @@ -0,0 +1,40 @@ + +#include "wifi_module.h" + +extern volatile Wifi_Status_Var status_flag; + +extern wifi_bool Uartx_Rx_Processing; +extern buffer_td big_buff; +extern wifi_bool resume_receive_data; +extern wifi_bool AT_Cmd_Processing; +extern WiFi_AT_CMD_Response_t WiFi_Module_State; +extern volatile WiFi_WIND_State_TypeDef WiFi_WIND_State; +extern volatile uint8_t wifi_connected; +extern wifi_bool WiFi_Enabled; +extern wifi_bool Standby_Enabled; +extern wifi_bool Deep_Sleep_Enabled; +extern uint8_t WiFi_AT_Cmd_Buff[]; + +extern void callSpwfSADevice_init(void* object); +extern char callSpwfSADevice_getChar(void* object); +extern void callSpwfSADevice_write(void* object, const char * cmd, uint16_t size); +extern void callSpwfSADevice_wakeup(void* object, int wake); +extern void callSpwfSADevice_reset(void* object, int reset); +extern void callSpwfSADevice_rts(void* object, int rts); +extern void callSpwfSADevice_attach(wifi_bool attach); +extern void callSpwfSADevice_debug(void* object, const char * string); +extern void destroySpwfSADevice(void); +extern int callSpwfSADevice_read_rts(void* object); + +extern void Stop_Timer(void); +extern void Start_Timer(void); + +extern void Wifi_TIM_Handler(void); +extern void Wifi_SysTick_Isr(void); + +void *spwf_dev; + +void Wifi_scheduler(void); +void Rx_irq_handler(void); +void Wifi_ticker(void); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/inc/wifi_interface.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,332 @@
+/**
+ ******************************************************************************
+ * @file wifi_interface.h
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief Header file for X-CUBE-WIFI1 API
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __WIFI_INTERFACE_H
+#define __WIFI_INTERFACE_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include<stdint.h>
+
+ /** @addtogroup MIDDLEWARES
+* @{
+*/
+
+
+/** @addtogroup NUCLEO_WIFI_API
+ * @brief Wi-Fi_interface API
+ * @{
+ */
+
+
+/** @addtogroup NUCLEO_WIFI_API_Private_Macros
+ * @{
+ */
+
+
+ /**
+ * @}
+ */
+
+
+/** @addtogroup NUCLEO_WIFI_API_Private_Variables
+ * @{
+ */
+/* Private variables ---------------------------------------------------------*/
+
+
+/* Exported macro ------------------------------------------------------------*/
+#define _ARG6(_0, _1, _2, _3, _4, _5, _6, ...) _6
+#define NARG6(...) _ARG6(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
+#define _FIVE_OR_SIX_ARGS_5(NAME, a, b, c, d, e) a, b, c, d, e, 1453727657
+#define _FIVE_OR_SIX_ARGS_6(NAME, a, b, c, d, e, f) a, b, c, d, e, f
+#define __FIVE_OR_SIX_ARGS(NAME, N, ...) _FIVE_OR_SIX_ARGS_ ## N (NAME, __VA_ARGS__)
+#define _FIVE_OR_SIX_ARGS(NAME, N, ...) __FIVE_OR_SIX_ARGS(NAME, N, __VA_ARGS__)
+#define FIVE_OR_SIX_ARGS(NAME, ...) NAME(_FIVE_OR_SIX_ARGS(NAME, NARG6(__VA_ARGS__), __VA_ARGS__))
+
+#define wifi_socket_client_security(...) FIVE_OR_SIX_ARGS(wifi_socket_client_security, __VA_ARGS__)
+
+/* Exported constants --------------------------------------------------------*/
+#define GPIO_IN "in"
+#define GPIO_OUT "out"
+
+#define GPIO_Off '0'
+#define GPIO_Rising 'R'
+#define GPIO_Falling 'F'
+#define GPIO_Both 'B'
+
+typedef enum GpioWriteValue
+{
+ GPIO_OFF = 0,
+ GPIO_ON,
+} GpioWriteValue;
+
+typedef enum GpioPin
+{
+ GPIO_PIN0 = 0,
+ GPIO_PIN1,
+ GPIO_PIN2,
+ GPIO_PIN3,
+ GPIO_PIN4,
+ GPIO_PIN5,
+ GPIO_PIN6,
+ GPIO_PIN7,
+ GPIO_PIN8,
+ GPIO_PIN9,
+ GPIO_PIN10,
+ GPIO_PIN11,
+ GPIO_PIN12,
+ GPIO_PIN13,
+ GPIO_PIN14,
+ GPIO_PIN15
+} GpioPin;
+
+typedef enum wifi_bool
+{
+ WIFI_FALSE = 0,
+ WIFI_TRUE = 1,
+ Undefine = 0xFF
+} wifi_bool;
+
+typedef enum WiFi_Priv_Mode
+{
+ None = 0,
+ WEP = 1,
+ WPA_Personal = 2,
+} WiFi_Priv_Mode;
+
+/********** Wi-Fi Error *************/
+typedef enum WiFi_Status_t
+{
+ WiFi_MODULE_SUCCESS = 0,
+ WiFi_TIME_OUT_ERROR = 1,
+ WiFi_MODULE_ERROR,
+ WiFi_HAL_OK,
+ WiFi_NOT_SUPPORTED,
+ WiFi_NOT_READY,
+ WiFi_SCAN_FAILED,
+ WiFi_AT_CMD_BUSY,
+ WiFi_SSID_ERROR,
+ WiFi_SecKey_ERROR,
+ WiFi_CONFIG_ERROR,
+ WiFi_STA_MODE_ERROR,
+ WiFi_AP_MODE_ERROR,
+ WiFi_AT_CMD_RESP_ERROR,
+ WiFi_AT_FILE_LENGTH_ERROR,
+ WiFi_HAL_UART_ERROR,
+ WiFi_IN_LOW_POWER_ERROR,
+ WiFi_HW_FAILURE_ERROR,
+ WiFi_HEAP_TOO_SMALL_WARNING,
+ WiFi_STACK_OVERFLOW_ERROR,
+ WiFi_HARD_FAULT_ERROR,
+ WiFi_MALLOC_FAILED_ERROR,
+ WiFi_INIT_ERROR,
+ WiFi_POWER_SAVE_WARNING,
+ WiFi_SIGNAL_LOW_WARNING,
+ WiFi_JOIN_FAILED,
+ WiFi_SCAN_BLEWUP,
+ WiFi_START_FAILED_ERROR,
+ WiFi_EXCEPTION_ERROR,
+ WiFi_DE_AUTH,
+ WiFi_DISASSOCIATION,
+ WiFi_UNHANDLED_IND_ERROR,
+ WiFi_RX_MGMT,
+ WiFi_RX_DATA,
+ WiFi_RX_UNK
+} WiFi_Status_t;
+
+typedef enum power_mode
+{
+ wifi_active = 0,
+ wifi_reactive = 1,
+ wifi_sleep = 2,
+} power_mode;
+
+typedef enum tx_power_level
+{
+ low = 0,
+ medium = 1,
+ high = 2,
+ max = 3,
+} tx_power_level;
+
+typedef enum dhcp_mode
+{
+ off = 0,
+ on = 1,
+ custom = 2,
+} dhcp_mode;
+
+typedef struct wifi_security
+{
+ wifi_bool wpa;
+ wifi_bool wpa2;
+ wifi_bool wps;
+} wifi_security;
+
+typedef struct wifi_scan
+{
+ uint8_t channel_num;
+ int rssi;
+ char ssid[30];
+ wifi_security sec_type;
+} wifi_scan;
+
+typedef struct wifi_config
+{
+ wifi_bool ht_mode;
+ power_mode power;
+ tx_power_level power_level;
+ dhcp_mode dhcp;
+ char* ip_addr;
+ char* netmask_addr;
+ char* gateway_addr;
+ char* dns_addr;
+ char* host_name;
+ wifi_bool web_server;
+ char* ap_domain_name;
+ char* ap_config_page_name;
+ uint32_t http_timeout;
+ uint32_t dhcp_timeout;
+ uint8_t wifi_region;
+ uint32_t wifi_baud_rate;
+} wifi_config;
+
+/* Exported functions ------------------------------------------------------- */
+
+#ifdef WIFI_USE_VCOM
+void wifi_vcom(void);
+#endif
+
+WiFi_Status_t wifi_init(wifi_config* config);
+WiFi_Status_t wifi_restore(void);
+WiFi_Status_t wifi_enable(wifi_bool enable);
+WiFi_Status_t wifi_disconnect(void);
+WiFi_Status_t wifi_connect(char * ssid, char * sec_key, WiFi_Priv_Mode priv_mode);
+WiFi_Status_t wifi_ap_start(uint8_t * ssid, uint8_t channel_num);
+WiFi_Status_t wifi_adhoc_create(uint8_t * ssid, WiFi_Priv_Mode priv_mode);
+WiFi_Status_t wifi_network_scan(wifi_scan *scan_result, uint16_t max_scan_number);
+void wifi_reset(void);
+
+/******** Wi-Fi Socket Function **********/
+WiFi_Status_t wifi_socket_client_open(uint8_t * hostname, uint32_t port_number, uint8_t * protocol, uint8_t * sock_id);
+WiFi_Status_t wifi_socket_client_write(uint8_t sock_id, uint16_t DataLength,char * pData);
+WiFi_Status_t wifi_socket_client_close(uint8_t sock_close_id);
+WiFi_Status_t wifi_socket_client_security(uint8_t* tls_mode, uint8_t* root_ca_server, uint8_t* client_cert, uint8_t* client_key, uint8_t* client_domain, uint32_t tls_epoch_time);
+
+/********* Wi-Fi Socket Server ********/
+WiFi_Status_t wifi_socket_server_open(uint32_t port_number, uint8_t * protocol);
+WiFi_Status_t wifi_socket_server_write(uint16_t DataLength,char * pData);
+WiFi_Status_t wifi_socket_server_close(void);
+
+/*** FileSystem Request ***********/
+WiFi_Status_t wifi_file_create(char *pFileName,uint16_t alength,char * databuff);
+WiFi_Status_t wifi_file_delete(char * pFileName);
+WiFi_Status_t wifi_file_list(void);
+WiFi_Status_t wifi_file_show(uint8_t * pFileName);
+WiFi_Status_t wifi_file_image_create(uint8_t * pHostName,uint8_t * pFileName, uint32_t port_number);
+WiFi_Status_t wifi_file_erase_external_flash(void);
+
+/*** HTTP File Request ***********/
+WiFi_Status_t wifi_http_get(uint8_t * hostname, uint8_t * path, uint32_t port_number);
+WiFi_Status_t wifi_http_post(uint8_t * url_path);
+
+WiFi_Status_t wifi_fw_update(uint8_t * hostname, uint8_t * filename_path, uint32_t port_number);
+
+/*** Power Configuration **********/
+WiFi_Status_t wifi_standby(uint8_t arg_standby_time);
+WiFi_Status_t wifi_wakeup(wifi_bool enable);
+
+/*** GPIO Configuration **********/
+uint8_t wifi_gpio_init(GpioPin pin, char* dir, char irq);
+uint8_t wifi_gpio_read(GpioPin pin, uint8_t *val, uint8_t *dir);
+uint8_t wifi_gpio_write(GpioPin pin, GpioWriteValue value);
+
+WiFi_Status_t WiFi_Get_IP_Address(uint8_t *ip_addr);
+WiFi_Status_t WiFi_Get_MAC_Address(uint8_t *mac_addr);
+
+void UART_Configuration(uint32_t baud_rate);
+void GPIO_Configuration(void);
+void Timer_Config(void);
+void UART_Msg_Gpio_Init(void);
+void USART_PRINT_MSG_Configuration(uint32_t baud_rate);
+
+/******** Wi-Fi Indication User Callback: For User to implement *********/
+void ind_wifi_warning(WiFi_Status_t warning_code);
+void ind_wifi_error(WiFi_Status_t error_code);
+void ind_wifi_connection_error(WiFi_Status_t status_code);
+void ind_wifi_connected(void);
+void ind_wifi_ap_ready(void);
+void ind_wifi_ap_client_joined(uint8_t * client_mac_address);
+void ind_wifi_ap_client_left(uint8_t * client_mac_address);
+void ind_wifi_on(void);
+void ind_wifi_packet_lost(WiFi_Status_t status_code);
+void ind_wifi_gpio_changed(void);
+void ind_wifi_socket_data_received(uint8_t socket_id, uint8_t * data_ptr, uint32_t message_size, uint32_t chunk_size);
+void ind_wifi_socket_client_remote_server_closed(uint8_t * socketID);
+void ind_wifi_socket_server_data_lost(void);
+void ind_socket_server_client_joined(void);
+void ind_socket_server_client_left(void);
+void ind_wifi_http_data_available(uint8_t * data_ptr,uint32_t message_size);
+void ind_wifi_file_data_available(uint8_t * data_ptr);
+void ind_wifi_resuming(void);
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* __WIFI_INTERFACE_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/inc/wifi_module.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,379 @@
+ /**
+ ******************************************************************************
+ * @file wifi_module.h
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief Header file for Wi-Fi module
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __WIFI_MODULE_H
+#define __WIFI_MODULE_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+//#include "stm32_spwf_wifi.h"
+#include "wifi_const.h"
+#include "wifi_interface.h"
+#include "event_buffer.h"
+
+/** @addtogroup MIDDLEWARES
+* @{
+*/
+
+
+/** @addtogroup NUCLEO_WIFI_MODULE
+ * @brief Wi-Fi_driver modules
+ * @{
+ */
+
+
+/** @addtogroup NUCLEO_WIFI_MODULE_Private_Macros
+ * @{
+ */
+
+//#define USART3_INT_MODE
+#define USART3_POLLING_MODE
+ /**
+ * @}
+ */
+
+
+/** @addtogroup NUCLEO_WIFI_MODULE_Private_Variables
+ * @{
+ */
+/* Private variables ---------------------------------------------------------*/
+
+/* Exported macro ------------------------------------------------------------*/
+
+/* Exported constants --------------------------------------------------------*/
+
+typedef struct Wifi_Status_Var
+{
+ wifi_bool Single_Digit_Indication;
+ wifi_bool WiFi_Enabled;
+ wifi_bool http_req_pending;
+ wifi_bool WiFi_Configuration_Done;
+ wifi_bool Timer_Running;
+ wifi_bool resume_receive_data;
+ wifi_bool enable_dequeue;
+ wifi_bool stop_event_dequeue;
+ wifi_bool Standby_Timer_Running;
+ wifi_bool trigger_wakeup_callback;
+ wifi_bool Deep_Sleep_Enabled;
+ wifi_bool Standby_Enabled;
+ wifi_bool Low_Power_Enabled;
+ wifi_bool command_mode;
+ wifi_bool data_mode;
+ wifi_bool Scan_Ongoing;
+ wifi_bool AT_Cmd_Ongoing;
+ wifi_bool AT_Cmd_Processing;
+ wifi_bool Uartx_Rx_Processing;
+ wifi_bool Client_Connected;
+ wifi_bool Client_Disconnected;
+ wifi_bool switch_by_default_to_command_mode;
+ wifi_bool start_sock_read;
+ wifi_bool enable_receive_data_chunk;
+ wifi_bool data_pending_sockD;
+ wifi_bool enable_sock_read;
+ wifi_bool enable_query;
+ wifi_bool Set_AT_Cmd_Response_False;
+ wifi_bool enable_fw_update_read;
+ wifi_bool Q_Contains_Message;
+ wifi_bool Q_Contains_Data;
+ wifi_bool enable_receive_http_response;
+ wifi_bool enable_receive_file_response;
+ wifi_bool enable_receive_wifi_scan_response;
+ wifi_bool prevent_push_OK_event;
+ wifi_bool client_socket_close_ongoing;
+ wifi_bool prevent_push_WIFI_event;
+ wifi_bool sock_read_ongoing;
+ wifi_bool enable_client_socket_write;
+ wifi_bool event_deQ_x_wind64;
+ wifi_bool do_not_reset_push_WIFI_event;
+ wifi_bool message_pending;
+ wifi_bool Pending_SockON_Callback;
+ wifi_bool Pending_SockD_Callback;
+ wifi_bool SockON_Server_Closed_Callback;
+ wifi_bool Client_Socket_Close_Cmd;
+ wifi_bool standby_resume_callback;
+ wifi_bool HTTP_Data_available;
+ wifi_bool FILE_Data_available;
+ wifi_bool AT_Response_Received;
+ wifi_bool Deep_Sleep_Timer;
+ wifi_bool Timeout_Timer;
+ wifi_bool Deep_Sleep_Callback;
+} Wifi_Status_Var;
+
+/******* Wi-Fi Configuration Setting Parameters *****************/
+
+typedef enum WiFi_Mode_TypeDef {
+ WiFi_IDLE_MODE =0,
+ WiFi_STA_MODE,
+ WiFi_IBSS_MODE,
+ WiFi_MiniAP_MODE
+} WiFi_Mode_TypeDef;
+
+
+/********** Wi-Fi Indications*************/
+
+#pragma pack(1)
+typedef struct WiFi_WIND_State_TypeDef
+{
+ wifi_bool ConsoleActive;
+ wifi_bool WiFiPowerON;
+ wifi_bool WiFiReset;
+ wifi_bool WiFiHWFailure;
+ wifi_bool HardFault;
+ wifi_bool StackOverflow;
+ wifi_bool MallocFailed;
+ wifi_bool InitFailure;
+ wifi_bool StartFailed;
+ wifi_bool PS_Mode_Failure;
+ wifi_bool HeapTooSmall;
+ wifi_bool WiFiSignalLOW;
+ wifi_bool WiFiJoin;
+ wifi_bool WiFiScanning;
+ wifi_bool WiFiUp;
+ wifi_bool WiFiAssociation;
+ wifi_bool WiFiStarted_MiniAPMode;
+ wifi_bool WiFiAPClientJoined;
+ wifi_bool WiFiAPClientLeft;
+ wifi_bool WiFiException;
+ wifi_bool WiFiHWStarted;
+ wifi_bool WiFiScanComplete;
+ wifi_bool WiFiPowerDown;
+ wifi_bool WiFiMiniAPMode;
+ wifi_bool WiFiDeauthentication;
+
+ /*Wifi Connection Errors*/
+ wifi_bool WiFiJoinFailed;
+ wifi_bool WiFiScanBlewUp;
+ wifi_bool WiFiScanFailed;
+ wifi_bool WiFiDeAuth;
+ wifi_bool WiFiDisAssociation;
+
+ /*Wifi packet lost INDs*/
+ wifi_bool WiFiUnHandledInd;
+ wifi_bool WiFiRXMgmt;
+ wifi_bool WiFiRXData;
+ wifi_bool WiFiRxUnk;
+ wifi_bool WiFiSockdDataLost;
+
+} WiFi_WIND_State_TypeDef;
+#pragma pack()
+
+typedef enum {
+ Console_Active = 0,
+ Poweron = 1,
+ WiFi_Reset,
+ Watchdog_Running,
+ Heap_Too_Small,
+ WiFi_Hardware_Dead = 5,
+ Watchdog_Terminating,
+ SysTickConfigure,
+ Hard_Fault =8,
+ StackOverflow,
+ MallocFailed,
+ Error,
+ WiFi_PS_Mode_Failure = 12,
+ CopyrightInfo,
+ WiFi_BSS_Regained = 14,
+ WiFi_Signal_LOW = 15,
+ WiFi_Signal_OK = 16,
+ FW_update = 17,
+ Encryption_key_Not_Recognized,
+ WiFi_Join = 19,
+ JOINFAILED = 20,
+ WiFi_Scanning = 21,
+ SCANBLEWUP,
+ SCANFAILED,
+ WiFi_Up = 24,
+ WiFi_Association_Successful = 25,
+ WiFi_Started_MiniAP_Mode = 26,
+ Start_Failed = 27,
+ WiFi__MiniAP_Associated = 28,
+ WiFi_EXCEPTION = 31,
+ WiFi_Hardware_Started = 32,
+ WiFi_BSS_LOST,
+ WiFi_Unhandled_Event,
+ Scan_Complete = 35,
+ WiFi_UNHANDLED_IND,
+ WiFi_UNHANDLED,
+ WiFi_Powered_Down,
+ WiFi_MiniAP_Mode = 39,
+ WiFi_Deauthentication = 40,
+ WiFi_Disassociation,
+ RX_MGMT,
+ RX_DATA,
+ RX_UNK,
+ DOT11_AUTHILLEGAL,
+ Creating_PSK = 46,
+ WPA_Terminated = 49,
+ WPA_Supplicant_Failed,
+ WPA_Handshake_Complete = 51,
+ GPIO_line,
+ Wakeup,
+ Factory_debug,
+ SockON_Data_Pending = 55,
+ Remote_Configuration = 57,
+ SockON_Server_Socket_Closed = 58,
+ In_Command_Mode = 59,
+ In_Data_Mode = 60,
+ Incoming_socket_client = 61,
+ Outgoing_socket_client = 62,
+ SockD_Dropping_Data = 63,
+ SockD_Pending_Data = 64,
+ Low_Power_Mode_Enabled = 66,
+ Going_Into_Standby = 67,
+ Resuming_From_Standby = 68,
+ Going_Into_DeepSleep = 69,
+ Resuming_From_DeepSleep = 70,
+ WiFi_MiniAP_Disassociated = 72,
+ Undefine_Indication = 0xFF
+} WiFi_Indication_t;
+
+typedef enum WiFi_Indication_t WiFi_Indication;
+
+typedef enum WiFi_Power_State_t
+{
+ Active_State,
+ PowerSave_State,
+ Sleep_State=3,
+ StandBy_State=4
+} WiFi_Power_State_t;
+
+typedef enum WiFi_AT_CMD_Response_t {
+ Process_Event =0,
+} WiFi_AT_CMD_Response_t;
+
+#ifdef WIFI_USE_VCOM
+void console_input(void);
+#endif
+
+void PowerUp_WiFi_Module(void);
+void WiFi_Module_Init(void);
+void WiFi_Application(void);
+/******* Wi-Fi AT CMD SET ****************/
+WiFi_Status_t Attention_Cmd(void);
+WiFi_Status_t USART_Transmit_AT_Cmd(uint16_t size);
+WiFi_Status_t USART_Receive_AT_Resp(WiFi_AT_CMD_Response_t);
+WiFi_Status_t Save_Current_Setting(void);
+WiFi_Status_t Restore_Default_Setting(void);
+WiFi_Status_t SET_SSID(char* ssid);
+WiFi_Status_t GET_SSID(void);
+WiFi_Status_t SET_Configuration_Value(char* sVar_name,uint32_t aValue);
+WiFi_Status_t GET_Configuration_Value(char* sVar_name,uint32_t *aValue);
+WiFi_Status_t SET_Configuration_Addr(char* sVar_name,char* addr);
+WiFi_Status_t Display_Help_Text(void);
+WiFi_Status_t SET_Power_State(WiFi_Power_State_t state);
+void Process_Wind_Indication(uint8_t *process_buff_ptr);
+void Process_WiFi_Indication_Cmd(event_s_TypeDef * event_pop_s1);
+//void USART2_SendBuffer(USART_TypeDef* USARTx, uint8_t *pData, uint8_t length);
+WiFi_Status_t Read_WiFi_SSID(char *string);
+void Reset_AT_CMD_Buffer(void);
+WiFi_Status_t Open_Serial_Port(void);
+WiFi_Status_t WaitForResponse(uint16_t alength);
+WiFi_Status_t config_init_value(char* sVar_name,uint8_t aValue);
+WiFi_Status_t config_init_addr(char* sVar_name,char* addr);
+
+char* Delete_Colon(char* );
+WiFi_Status_t Read_WiFi_Mode(char *string);
+WiFi_Status_t Read_WiFi_SecKey(char *string);
+
+WiFi_Status_t Write_WiFi_SSID(char *string);
+WiFi_Status_t Write_WiFi_SecKey(char *string);
+void PrintErrorMsg (void);
+void Print_Msg(char * msgBuff,uint8_t length);
+char *search_buffer(char *pSourceBuff, uint16_t sourceBuffLen, char *pSearchStringBuff, uint16_t seartchStringLen);
+void Error_Handler(void);
+WiFi_Status_t SET_WiFi_SecKey(char* seckey);
+void WiFi_Receive_Indication_Msg(void);
+
+void ResetBuffer(void);
+void Start_Timer(void);
+void Stop_Timer(void);
+void Request_Time_Out(void);
+void Start_DeepSleep_Timer(void);
+void Stop_DeepSleep_Timer(void);
+
+void HTTP_Read_Data(void);
+WiFi_Status_t Socket_Read(uint16_t DataLength);
+void Read_Socket_Data(void);
+void Socket_Pending_Data(void);
+void WiFi_switch_to_command_mode(void);
+void WiFi_switch_to_data_mode(void);
+void WiFi_Configuration(void);
+
+void Receive_Data(void);
+void Process_Buffer(uint8_t * ptr);
+void Process_WiFi(void);
+#if 0
+void configure_to_exti(void);
+#endif
+void Stop_Dequeue(void);
+void Resume_Dequeue(void);
+void wait_for_command_mode(void);
+void Wifi_SysTick_Isr(void);
+void RX_EXTI_Isr(uint16_t GPIO_Pin);
+//void Wifi_TIM_Handler(TIM_HandleTypeDef *htim);
+void Queue_Http_Event(uint8_t * hostname, uint8_t * path, uint32_t port_number,uint8_t * pURL_path);
+void Queue_Client_Write_Event(uint8_t sock_id, uint16_t DataLength, char * pData);
+void Queue_Wifi_FW_Update_Event(uint8_t * hostname, uint8_t * filename_path, uint32_t port_number);
+void Queue_Wifi_File_Event(uint8_t * pHostName, uint8_t * pFileName, uint32_t port_number);
+void Queue_Client_Open_Event(uint8_t * hostname, uint32_t port_number, uint8_t * protocol);
+void Queue_Client_Close_Event(uint8_t sock_id);
+void Wait_For_Sock_Read_To_Complete(void);
+void initialize_status_flags(void);
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+ }
+#endif
+#endif /* __WIFI_MODULE_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/utils/event_buffer.c Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,242 @@
+/**
+ ******************************************************************************
+ * @file event_buffer.c
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief Implements the Event Buffer management of the Wi-Fi module
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "event_buffer.h"
+#include "wifi_module.h"
+
+/** @addtogroup BSP
+* @{
+*/
+
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT
+ * @brief Wi-Fi_driver modules
+ * @{
+ */
+
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Defines
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Variables
+ * @{
+ */
+extern event_s_TypeDef event_buffer[1024];
+#define ELEMENT_SIZE sizeof(event_s_TypeDef) //1
+
+//extern UART_HandleTypeDef UartMsgHandle;
+//extern char print_msg_buff[512];
+extern event_s_TypeDef element;
+
+/*
+#ifdef USART_PRINT_MSG
+#define printf(arg) sprintf((char*)print_msg_buff,arg); \
+ HAL_UART_Transmit(&UartMsgHandle, (uint8_t*)print_msg_buff, strlen(print_msg_buff), 1000);
+#endif
+*/
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief init
+ * Initialize a circular buffer of type buffer_t
+ * @param None
+ * @retval None
+ */
+void event_init(buffer_e *buffer, int size) {
+ uint32_t element_size;
+ element_size = sizeof(event_s_TypeDef);
+ buffer->size = element_size*size;
+ buffer->start = 0;
+ buffer->count = 0;
+ buffer->end = 0;
+ buffer->element = event_buffer;
+}
+
+/**
+ * @brief full
+ * indicates if the given buffer is full or not
+ * @param None
+ * @retval None
+ */
+int event_full(buffer_e *buffer)
+{
+ int bufsize = buffer->size;
+ if (buffer->count == (bufsize/ELEMENT_SIZE))
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/**
+ * @brief empty
+ * indicates if the given buffer is empty or not
+ * @param None
+ * @retval None
+ */
+int event_empty(buffer_e *buffer) {
+ if (buffer->count == 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * @brief push_buffer
+ * pushes the data structure onto the circular buffer (queues it)
+ * @param None
+ * @retval None
+ */
+void push_eventbuffer(buffer_e *buffer, event_s_TypeDef data)
+{
+ int bufsize;
+ uint32_t index;
+
+ if (event_full(buffer))
+ {
+ //Buffer overflow and no more space
+ //MPD: No Action taken here; in case of buffer overflow, do we need to overwrite last buffer?
+ //printf("\r\nRing Buffer Full!!\r\n");
+ //printf(data);
+ return;
+ } else
+ {
+ index=buffer->end/ELEMENT_SIZE;
+ buffer->element[index].data_length = data.data_length;
+ buffer->element[index].wind64_pending_packet_no = data.wind64_pending_packet_no;
+ buffer->element[index].enc = data.enc;
+ buffer->element[index].ok_eval = data.ok_eval;
+ buffer->element[index].socket_id = data.socket_id;
+ buffer->element[index].wind = data.wind;
+ buffer->element[index].event = data.event;
+ buffer->element[index].event_pop = data.event_pop;
+ buffer->count++;
+ buffer->end = buffer->end + ELEMENT_SIZE;
+
+ //wrap around if max size is reached
+ bufsize = (buffer->size);
+ if (buffer->end >= bufsize)
+ {
+ buffer->end = 0;
+ }
+ }
+}
+
+/**
+ * @brief pop_buffer_queue
+ * dequeues the circular buffer
+ * @param None
+ * @retval None
+ */
+event_s_TypeDef * pop_eventbuffer_queue(buffer_e *buffer)
+{
+ int bufsize;
+ uint32_t index;
+
+ if (event_empty(buffer))
+ {
+ //printf("\r\Event Buffer Empty!!\r\n");
+ return NULL;
+ }
+ else
+ {
+ /* First in First Out*/
+ index=buffer->start/ELEMENT_SIZE;
+ element.data_length = buffer->element[index].data_length;
+ element.enc = buffer->element[index].enc;
+ element.ok_eval = buffer->element[index].ok_eval;
+ element.socket_id = buffer->element[index].socket_id;
+ element.wind64_pending_packet_no = buffer->element[index].wind64_pending_packet_no;
+ element.wind = buffer->element[index].wind;
+ element.event = buffer->element[index].event;
+ element.event_pop = buffer->element[index].event_pop;
+ buffer->start = buffer->start + ELEMENT_SIZE;
+ buffer->count--;
+
+ bufsize = (buffer->size);
+ if (buffer->start >= bufsize)
+ {
+ buffer->start = 0;
+ }
+ return &element;
+ }
+}
+
+void reset_event(event_s_TypeDef *r_event)
+{
+ r_event->data_length = 0;
+ r_event->enc = WIFI_FALSE;
+ r_event->event = WIFI_NO_EVENT;
+ r_event->ok_eval = WIFI_FALSE;
+ r_event->socket_id = 9; //Socket ID 0-7
+ r_event->wind64_pending_packet_no = 9; //Max pending packets = 4
+ r_event->wind = 99; //any default value
+ r_event->event_pop = WIFI_TRUE;
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/utils/event_buffer.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,157 @@
+ /**
+ ******************************************************************************
+ * @file event_buffer.h
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief Header File for Event Buffer management of the Wi-Fi module
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include "wifi_module.h"
+#ifndef __EVENT_BUFFER_H
+#define __EVENT_BUFFER_H
+
+/** @addtogroup BSP
+* @{
+*/
+
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT
+ * @brief Wi-Fi_driver modules
+ * @{
+ */
+
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_TypesDefinitions
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Defines
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Macros
+ * @{
+ */
+
+
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Variables
+ * @{
+ */
+
+typedef enum
+{
+ WIFI_NO_EVENT,
+ WIFI_WIND_EVENT = 0x0001,
+ WIFI_SOCK_ID_EVENT,
+ WIFI_GCFG_EVENT,
+ WIFI_GPIO_EVENT,
+ WIFI_OK_EVENT,
+ WIFI_ERROR_EVENT,
+ WIFI_STANDBY_CONFIG_EVENT,
+ WIFI_RESUME_CONFIG_EVENT,
+ WIFI_HTTP_EVENT,
+ WIFI_CLIENT_SOCKET_WRITE_EVENT,
+ WIFI_FILE_EVENT,
+ WIFI_CLIENT_SOCKET_OPEN_EVENT,
+ WIFI_CLIENT_SOCKET_CLOSE_EVENT,
+ WIFI_FW_UPDATE_EVENT,
+} event_e;
+
+
+typedef struct
+{
+ uint32_t wind;
+ uint32_t data_length;
+ uint16_t socket_id;
+ uint8_t wind64_pending_packet_no;
+ wifi_bool enc;
+ wifi_bool ok_eval;
+ wifi_bool event_pop;
+ event_e event;
+} event_s_TypeDef;
+
+struct event_buffer {
+ volatile int start; // position of first data from USART
+ volatile int end; // position of last data from USART
+ volatile int size; //Max size in terms of number of data packets (Total Bytes/size of each packet (8 bytes))
+ volatile int count; // number of currently filled data packets (=size if full & =0 if empty)
+
+ /*unsigned main buffer pointer*/
+ event_s_TypeDef *element;
+};
+
+typedef struct event_buffer buffer_e;
+
+void event_init(buffer_e *buffer, int size);
+int event_full(buffer_e *buffer);
+int event_empty(buffer_e *buffer);
+void push_eventbuffer(buffer_e *buffer, event_s_TypeDef data);
+event_s_TypeDef * pop_eventbuffer_queue(buffer_e *buffer);
+void reset_event(event_s_TypeDef *r_event);
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/utils/ring_buffer.c Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,368 @@
+/**
+ ******************************************************************************
+ * @file ring_buffer.c
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief Implements the Circular Buffer management of the Wi-Fi module
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "ring_buffer.h"
+#include "wifi_module.h"
+
+/** @addtogroup MIDDLEWARES
+* @{
+*/
+
+
+/** @defgroup NUCLEO_WIFI_UTILS
+ * @brief Wi-Fi buffer utility
+ * @{
+ */
+
+
+/** @defgroup NUCLEO_WIFI_UTILS_Private_Defines
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_UTILS_Private_Variables
+ * @{
+ */
+
+extern uint8_t ring_buffer[RINGBUF_SIZE];
+extern uint8_t pop_buffer[MAX_BUFFER_GLOBAL];
+extern uint8_t prefetch_buffer[20];
+//extern wifi_bool enable_receive_data_chunk;
+extern volatile Wifi_Status_Var status_flag;
+extern uint32_t pop_buffer_size;
+
+#define ELEMENT_SIZE 1
+
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_UTILS_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief init
+ * Initialize a circular buffer of type buffer_td
+ * @param None
+ * @retval None
+ */
+void init(buffer_td *buffer, int size)
+{
+ buffer->size = size;
+ buffer->start = 0;
+ buffer->count = 0;
+ buffer->end = 0;
+ buffer->element = ring_buffer;
+}
+
+/**
+ * @brief flush_buffer_queue
+ * flushes the buffer
+ * @param None
+ * @retval None
+ */
+void flush_buffer_queue(buffer_td *buffer)
+{
+ buffer->start = buffer->end;//the tail goes up to the head and buffer becomes empty
+ buffer->count = 0;
+}
+
+/**
+ * @brief is_half_full
+ * checks if the buffer is half full (empty)
+ * @param None
+ * @retval None
+ */
+int is_half_full(buffer_td *buffer)
+{
+ int bufsize = buffer->size;
+ if (buffer->count >= bufsize - 100)
+ {
+ //printf("half full!");
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/**
+ * @brief is_half_empty
+ * checks if the buffer is less than half
+ * @param None
+ * @retval None
+ */
+int is_half_empty(buffer_td *buffer)
+{
+ //int bufsize = buffer->size;
+ if (buffer->count <= 100)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/**
+ * @brief full
+ * indicates if the given buffer is full or not
+ * @param None
+ * @retval None
+ */
+int full(buffer_td *buffer)
+{
+ int bufsize = buffer->size;
+ if (buffer->count == bufsize)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/**
+ * @brief empty
+ * indicates if the given buffer is empty or not
+ * @param None
+ * @retval None
+ */
+int empty(buffer_td *buffer) {
+ if (buffer->count == 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * @brief prefetch_buffer_queue
+ * prefetches the pipeline upto xx bytes
+ * @param None
+ * @retval None
+ */
+uint8_t * prefetch_buffer_queue(buffer_td *buffer)
+{
+ //int i = 0;
+ uint8_t * element;
+ int bufsize;
+
+ memset(prefetch_buffer,0x00,20);
+ element = &prefetch_buffer[0];
+ element[4] = '\0';
+
+ if(!empty(buffer))
+ {
+ bufsize = (buffer->count);
+ if(buffer->count <= 20)
+ memcpy(element, &buffer->element[buffer->start], bufsize);
+ else
+ memcpy(element, &buffer->element[buffer->start], 20);
+ return element;
+ }
+ else return NULL;
+}
+
+/*
+ * @brief push_buffer
+ * pushes a new item onto the circular buffer (queues it)
+ * @param None
+ * @retval None
+ */
+void push_buffer(buffer_td *buffer, uint8_t *data)
+{
+ int bufsize;
+
+ if (full(buffer))
+ {
+ //Buffer overflow and no more space
+ //MPD: No Action taken here; in case of buffer overflow, do we need to overwrite last buffer?
+ //printf("\r\nRing Buffer Full!!\r\n");
+ //printf(data);
+ return;
+ }
+ else
+ {
+ buffer->count++;
+ memcpy(&buffer->element[buffer->end], data, ELEMENT_SIZE);
+ buffer->end = buffer->end + ELEMENT_SIZE;
+
+ //wrap around if max size is reached
+ bufsize = (buffer->size);
+ if (buffer->end >= bufsize)
+ {
+ buffer->end = 0;
+ }
+ }
+}
+
+/**
+ * @brief pop_buffer_queue
+ * dequeues the circular buffer
+ * @param None
+ * @retval None
+ */
+uint8_t * pop_buffer_queue(buffer_td *buffer)
+{
+ uint8_t * element;
+ int bufsize;
+
+ element = &pop_buffer[0];
+ if (empty(buffer))
+ {
+ //printf("\r\nRing Buffer Empty!!\r\n");
+ return NULL;
+ }
+ else
+ {
+ memset(pop_buffer, 0x00 , MAX_BUFFER_GLOBAL);
+ if(status_flag.enable_receive_data_chunk)
+ {
+ int buf_end = buffer->end;
+ // int buf_start = buffer->start;
+ if(buffer->count < 512)
+ {
+ pop_buffer_size = buffer->count;
+ if(buf_end >= buffer->start)
+ {
+ memcpy(element, &buffer->element[buffer->start], pop_buffer_size);
+ }
+ else
+ {
+ int buf_start = buffer->start;
+ memcpy(element, &buffer->element[buffer->start], RINGBUF_SIZE - buf_start);
+ memcpy(element+(RINGBUF_SIZE-buffer->start), &buffer->element[0], buf_end);
+ }
+ buffer->start = buffer->end;
+ buffer->count = 0;
+ }
+ else
+ {
+ if(buf_end >= buffer->start)
+ {
+ memcpy(element, &buffer->element[buffer->start], 511);
+ buffer->start = buffer->start + 511;
+ buffer->count = buf_end - buffer->start;
+ }
+ else
+ {
+ if(buffer->start + 511 < RINGBUF_SIZE)
+ {
+ memcpy(element, &buffer->element[buffer->start], 511);
+ buffer->start = buffer->start + 511;
+ buffer->count = (RINGBUF_SIZE - buffer->start)+ buf_end;
+ }
+ else
+ {
+ int buf_start = buffer->start;
+ memcpy(element, &buffer->element[buffer->start], RINGBUF_SIZE-buf_start);
+ memcpy(element+(RINGBUF_SIZE-buffer->start), &buffer->element[0], buf_start-513); //(buffer->start + 511) - 1024;
+ buffer->start = (buffer->start-513);
+ buffer->count = buf_end - buffer->start;
+ }
+ }
+ pop_buffer_size = 511;
+ }
+ }
+ else
+ {
+ /* First in First Out*/
+ memcpy(element, &buffer->element[buffer->start], ELEMENT_SIZE);
+ buffer->start = buffer->start + ELEMENT_SIZE;
+ buffer->count--;
+ pop_buffer_size = 1;
+ bufsize = (buffer->size);
+ if (buffer->start >= bufsize)
+ {
+ buffer->start = 0;
+ }
+ }
+ return element;
+ }
+}
+
+/**
+ * @brief rewinds_buffer_queue
+ * rewinds the circular buffer
+ * @param None
+ * @retval None
+ */
+void rewind_buffer_queue(buffer_td *buffer , int count)
+{
+ int buf_end = buffer->end;
+ if(buffer->start - count >= 0)
+ {
+ buffer->start = buffer->start - count;
+ if(buf_end > buffer->start) {
+ buffer->count = buf_end - buffer->start;
+ }
+ else {
+ buffer->count = (RINGBUF_SIZE-buffer->start)+buf_end;
+ }
+ }
+ else
+ {
+ buffer->start = RINGBUF_SIZE - (count - buffer->start);
+ buffer->count = (RINGBUF_SIZE - buffer->start)+ buf_end;
+ }
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/utils/ring_buffer.h Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,130 @@
+ /**
+ ******************************************************************************
+ * @file ring_buffer.h
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief Header File for Circular Buffer management of the Wi-Fi module
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#ifndef __RING_BUFFER_H
+#define __RING_BUFFER_H
+
+/** @addtogroup BSP
+* @{
+*/
+
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT
+ * @brief Wi-Fi_driver modules
+ * @{
+ */
+
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_TypesDefinitions
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Defines
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Macros
+ * @{
+ */
+
+
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Variables
+ * @{
+ */
+
+struct buffer {
+ volatile int start; // position of first data from USART
+ volatile int end; // position of last data from USART
+ volatile int size; //Max size in terms of number of data packets (Total Bytes/size of each packet (8 bytes))
+ volatile int count; // number of currently filled data packets (=size if full & =0 if empty)
+
+ /*unsigned main buffer pointer*/
+ uint8_t *element;
+};
+
+typedef struct buffer buffer_td;
+
+void init(buffer_td *buffer, int size);
+void flush_buffer_queue(buffer_td *buffer);
+int is_half_full(buffer_td *buffer);
+int is_half_empty(buffer_td *buffer);
+int full(buffer_td *buffer);
+int empty(buffer_td *buffer);
+void push_buffer(buffer_td *buffer, uint8_t *data);
+uint8_t * pop_buffer_queue(buffer_td *buffer);
+uint8_t * popstack(buffer_td *buffer);
+uint8_t * prefetch_buffer_queue(buffer_td *buffer);
+void rewind_buffer_queue(buffer_td *buffer , int count);
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/wifi_driver.c Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,187 @@
+/**
+ ******************************************************************************
+ * @file wifi_driver.c
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 01-March-2016
+ * @brief Enable Wi-Fi functionality using AT cmd set
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+/* Includes ------------------------------------------------------------------*/
+
+#include <stddef.h>
+#include "wifi_module.h"
+#include "ring_buffer.h"
+#include "device.h"
+#include "wait_api.h"
+#include "stdio.h"
+#include "string.h"
+#include "wifi_driver.h"
+
+void Wifi_ticker(void)
+{
+ Wifi_SysTick_Isr();
+}
+
+void Wifi_scheduler(void)
+{
+ Wifi_TIM_Handler();
+}
+
+void Rx_irq_handler(void)
+{
+
+ uint8_t data_byte = (uint8_t)callSpwfSADevice_getChar(spwf_dev);
+
+ status_flag.Uartx_Rx_Processing = WIFI_FALSE;
+
+ Stop_Timer();
+ __disable_irq();
+ push_buffer(&big_buff, &data_byte);
+ __enable_irq();
+ Start_Timer();
+
+ status_flag.Uartx_Rx_Processing = WIFI_TRUE;
+
+ /*if(is_half_full(&big_buff))
+ {
+ status_flag.resume_receive_data = WIFI_TRUE;
+ if(callSpwfSADevice_read_rts(spwf_dev))
+ callSpwfSADevice_rts(spwf_dev, GPIO_PIN_SET);
+ //callSpwfSADevice_attach(0);
+ } else
+ {
+ if(status_flag.AT_Cmd_Processing == WIFI_FALSE)
+ {
+ status_flag.Uartx_Rx_Processing = WIFI_TRUE;
+ }
+ }*/
+}
+
+
+/**
+* @brief wifi_reset
+* Reset WiFi module using PC12 gpio pin
+* @param None
+* @retval None
+*/
+void wifi_reset(void)
+{
+ WiFi_Module_State = Process_Event;
+ WiFi_WIND_State.WiFiHWStarted = WIFI_FALSE;
+ wifi_connected = 0; //reset wifi_connected to get user callback
+ memset((void*)&WiFi_WIND_State,0x00,sizeof(WiFi_WIND_State)); /*reset the WIND State?*/
+
+ /* === RESET PIN - PC12 ===*/
+
+ callSpwfSADevice_reset(spwf_dev, 0);
+ wait_ms(100);
+
+ callSpwfSADevice_reset(spwf_dev, 1);
+ wait_ms(100);
+
+ while(WiFi_WIND_State.WiFiHWStarted != WIFI_TRUE)
+ {
+ //nothing to do
+ __NOP();
+ }
+}
+
+
+/**
+* @brief PowerUp_WiFi_Module
+* Power up Wi-Fi module,SET GPIO PA0 pin
+* @param None
+* @retval None
+*/
+void PowerUp_WiFi_Module(void)
+{
+ /* === SET PIN - PC12 ===*/
+ callSpwfSADevice_reset(spwf_dev, 1);
+ wait_ms(50);
+}
+
+/**
+* @brief Receive_Data
+* Receive data from UART port
+* @param uint8_t number of bytes to be received
+* @retval None
+*/
+void Receive_Data(void)
+{
+ callSpwfSADevice_rts(spwf_dev, 0);
+}
+
+
+/**
+* @brief USART_Transmit_AT_Cmd
+* send AT cmd on UART port of wifi module.
+* @param size size of the AT command
+* @retval WiFi_Status_t : status of AT cmd
+*/
+WiFi_Status_t USART_Transmit_AT_Cmd(uint16_t size)
+{
+ //Check for Hardware Started
+ if(status_flag.WiFi_Enabled == WIFI_FALSE)
+ return WiFi_NOT_READY;
+ //Check for Deep-Sleep or Standby Mode, return error if true
+ if (status_flag.Standby_Enabled == WIFI_TRUE || status_flag.Deep_Sleep_Enabled == WIFI_TRUE)
+ return WiFi_IN_LOW_POWER_ERROR;
+
+ status_flag.AT_Cmd_Processing = WIFI_TRUE;//Stop Any Rx between the TX call
+
+ if (size == 0)
+ {
+ return WiFi_UNHANDLED_IND_ERROR;
+ }
+
+#if defined(USART3_INT_MODE)
+ if(HAL_UART_Transmit_IT(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, size)!= HAL_OK)
+ {
+ Error_Handler();
+ return WiFi_HAL_UART_ERROR;
+ }
+ while (UartReady != SET);
+ UartReady = RESET;
+
+#elif defined(USART3_POLLING_MODE)
+
+ callSpwfSADevice_write(spwf_dev, (const char *) WiFi_AT_Cmd_Buff, size);
+
+#else
+ #error "Please select USART mode in your application (in wifi_module.h file)"
+#endif
+
+ status_flag.AT_Cmd_Processing = WIFI_FALSE;//Re-enable Rx for UART
+ if(status_flag.Uartx_Rx_Processing == WIFI_FALSE)
+ Receive_Data();//Start receiving Rx from the UART again, if and only if it was stopped in the previous Uartx_Rx_Handler
+ return WiFi_MODULE_SUCCESS;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/wifi_interface.c Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,1449 @@
+/**
+ ******************************************************************************
+ * @file wifi_interface.c
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief User APIs implementation for X-CUBE-WIFI1
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "wifi_module.h"
+//#include "stm32_spwf_wifi.h"
+#include "ring_buffer.h"
+#include "stdio.h"
+#include "string.h"
+#include "gpio_irq_api.h"
+#include "gpio_api.h"
+#include "wait_api.h"
+#include "serial_api.h"
+
+/** @addtogroup MIDDLEWARES
+* @{
+*/
+
+
+/** @defgroup NUCLEO_WIFI_INTERFACE
+ * @brief Wi-Fi User API modules
+ * @{
+ */
+
+
+/** @defgroup NUCLEO_WIFI_INTERFACE_Private_Defines
+ * @{
+ */
+
+
+/**
+ * @}
+ */
+
+/** @addtogroup NUCLEO_WIFI_INTERFACE_Private_Variables
+ * @{
+ */
+/* Private variables ---------------------------------------------------------*/
+
+#if defined (USE_STM32F4XX_NUCLEO) || (USE_STM32L4XX_NUCLEO)
+extern uint8_t WiFi_AT_Cmd_Buff[2048];
+#else
+extern uint8_t WiFi_AT_Cmd_Buff[1024];
+#endif
+
+extern volatile Wifi_Status_Var status_flag;
+
+extern char UserDataBuff[MAX_BUFFER_GLOBAL];
+extern wifi_scan *wifi_scanned_list;//[15];
+extern char print_msg_buff[MAX_BUFFER_GLOBAL];
+extern uint8_t user_scan_number;
+extern uint8_t no_of_open_client_sockets;
+extern wifi_bool open_sockets[8];//Max open sockets allowed is 8. Each array element depicts one socket (true=open, false=closed)
+extern WiFi_AT_CMD_Response_t WiFi_Module_State;
+extern volatile uint8_t wifi_client_connected;
+extern uint8_t gpio_value, gpio_direc;
+extern volatile uint8_t wifi_connected;
+extern uint32_t SockON_Data_Length;
+extern uint8_t Socket_Open_ID, sockon_query_id;
+extern volatile uint32_t WIND64_count;
+extern uint32_t process_buffer_index;
+extern uint32_t epoch_time;
+
+/*SPWFSADevice Class functions and variables*/
+void * spwf_device_class;
+extern void callSpwfSADevice_wakeup(void* object, int wake);
+extern void callSpwfSADevice_debug(void* object, const char * string);
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_INTERFACE_Private_Functions
+ * @{
+ */
+#ifdef USART_PRINT_MSG
+#define printf(arg) {sprintf((char*)print_msg_buff,arg); \
+HAL_UART_Transmit(&UartMsgHandle, (uint8_t*)print_msg_buff, strlen(print_msg_buff), 1000);}
+#endif
+
+/**
+ *Changed/introduced functions for MBED implementation:
+
+- WiFi_Status_t wifi_init(wifi_config* config)
+- WiFi_Status_t wifi_wakeup(wifi_bool wakeup)
+- WiFi_Status_t wifi_socket_server_write(uint16_t DataLength,char * pData)
+- void wifi_reset(void);
+- WiFi_Status_t wifi_enable(wifi_bool enable)
+
+*/
+
+
+/**
+ * @brief wifi_init
+ * User API for wifi init
+ * @param None
+ * @retval None
+ */
+WiFi_Status_t wifi_init(wifi_config* config)
+{
+#ifndef WIFI_USE_VCOM
+ uint8_t tx_level;
+#endif
+
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+#if DEBUG_PRINT
+ printf("\r\n[SPWF]Initializing SPWF01SA1 Interface\r\n");
+#endif
+ callSpwfSADevice_debug(spwf_device_class, "\r\n[SPWF] Initializing mbed SPWF01SA1 Interface\r\n");
+
+ WiFi_Module_Init();
+
+ callSpwfSADevice_debug(spwf_device_class, "\r\n[SPWF] Module Init done\r\n");
+
+#ifndef WIFI_USE_VCOM
+
+ wifi_wakeup(WIFI_TRUE);//Prevent from going to sleep during configuration
+
+ /* Soft reset the module */
+ wifi_reset();
+
+ callSpwfSADevice_debug(spwf_device_class, "\r\n[SPWF] Hardware started\r\n");
+
+ /* Set localecho1 to 0*/
+ status = SET_Configuration_Value(LOCALECHO1, 0);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+
+ /* Restore default setting*/
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_RESTORE_DEFAULT_SETTING);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ /* Switch on HW Flow Control*/
+ status = SET_Configuration_Value(CONSOLE1_HWFC, 1);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+
+ if(config->wifi_baud_rate)
+ {
+ /* Set USART Speed*/
+ status = SET_Configuration_Value(CONSOLE1_SPEED, config->wifi_baud_rate);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ /* Set wifi_mode to idle*/
+ status = SET_Configuration_Value(WIFI_MODE, WiFi_IDLE_MODE);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+
+ switch(config->ht_mode)
+ {
+ case WIFI_FALSE:
+ status = SET_Configuration_Value(WIFI_HT_MODE, 0);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Addr(WIFI_OPR_RATE_MASK, "0x00003FCF");
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ break;
+ case WIFI_TRUE:
+ status = SET_Configuration_Value(WIFI_HT_MODE, 1);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Addr(WIFI_OPR_RATE_MASK, "0x003FFFCF");
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ break;
+ default:
+ break;
+ }
+
+ switch(config->power)
+ {
+ case wifi_active:
+ status = SET_Configuration_Value(WIFI_POWERSAVE, 0);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_SLEEP_ENABLED, 0);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ break;
+ case wifi_reactive:
+ status = SET_Configuration_Value(WIFI_POWERSAVE, 1);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_OPERATIONAL_MODE, 11);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_BEACON_WAKEUP, 0);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_LISTEN_INTERVAL, 0);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_SLEEP_ENABLED, 0);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ break;
+ case wifi_sleep:
+ status = SET_Configuration_Value(WIFI_POWERSAVE, 1);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_OPERATIONAL_MODE, 12);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_BEACON_WAKEUP, 10);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_LISTEN_INTERVAL, 1);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ status = SET_Configuration_Value(WIFI_SLEEP_ENABLED, 1);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ break;
+ default:
+ break;
+ }
+
+ switch(config->power_level)
+ {
+ case low:
+ case medium:
+ case high:
+ case max:
+ tx_level=config->power_level*6;
+ status = SET_Configuration_Value(WIFI_TX_POWER, tx_level);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ break;
+ default:
+ break;
+ }
+
+ switch(config->dhcp)
+ {
+ case off:
+ case on:
+ case custom:
+ status = SET_Configuration_Value(IP_USE_DHCP_SERVER, config->dhcp);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ break;
+ default:
+ break;
+ }
+
+ /* Set IP address */
+ if(config->ip_addr)
+ {
+ status = SET_Configuration_Addr(WIFI_IP_ADDRESS, config->ip_addr);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+ /* Set netmask address */
+ if(config->netmask_addr)
+ {
+ status = SET_Configuration_Addr(WIFI_IP_NETMASK, config->netmask_addr);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+ /* Set default gateway address */
+ if(config->gateway_addr)
+ {
+ status = SET_Configuration_Addr(WIFI_IP_DEFAULT_GATEWAY, config->gateway_addr);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+ /* Set dns address */
+ if(config->dns_addr)
+ {
+ status = SET_Configuration_Addr(WIFI_IP_DNS, config->dns_addr);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+ /* Set hostname */
+ if(config->host_name)
+ {
+ status = SET_Configuration_Addr(WIFI_IP_HOSTNAME, config->host_name);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ if(config->ap_domain_name)
+ {
+ status = SET_Configuration_Addr(WIFI_IP_APDOMAINNAME, config->ap_domain_name);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ if(config->ap_config_page_name)
+ {
+ status = SET_Configuration_Addr(WIFI_IP_APREDIRECT, config->ap_config_page_name);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ if(config->http_timeout)
+ {
+ status = SET_Configuration_Value(WIFI_IP_HTTP_TIMEOUT, config->http_timeout*1000);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+ if(config->dhcp_timeout)
+ {
+ status = SET_Configuration_Value(WIFI_IP_DHCP_TIMEOUT, config->dhcp_timeout);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+#ifdef MODULE_VERSION_SPWF01Sx_1y
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_HTTPD, config->web_server);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+#endif
+
+ /*AT+S.TLSCERT2=clean,all */
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT2=clean,all\r");
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ /* save current setting in flash */
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SAVE_CURRENT_SETTING);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ if(config->wifi_baud_rate)
+ {
+ UART_Configuration(config->wifi_baud_rate);
+ Receive_Data();//Restart data reception
+ }
+
+ /* Soft reset the module, Do the second reset after setting all parameters and saving in flash */
+ wifi_reset();
+
+ wifi_wakeup(WIFI_FALSE);//De-assert wakeup signal (PC13) to allow sleep if enabled
+#endif //WIFI_USE_VCOM
+
+#if DEBUG_PRINT
+ printf("\r\nEnd of Initialization..\r\n");
+#endif
+ callSpwfSADevice_debug(spwf_device_class, "\r\n[SPWF] End of mbed Initialization\r\n");
+
+ return status;
+}
+
+
+/**
+* @brief wifi_socket_client_security
+* Set the security certificates and key for secure socket (TLS)
+* @param None
+* @retval WiFi_Status_t : return status
+*/
+WiFi_Status_t wifi_socket_client_security(uint8_t* tls_mode, uint8_t* root_ca_server, uint8_t* client_cert, uint8_t* client_key, uint8_t* client_domain, uint32_t tls_epoch_time)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ /*AT+S.TLSCERT2=clean,all */
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT2=clean,all\r");
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ /* AT+S.SETTIME=<seconds> */
+ Reset_AT_CMD_Buffer();
+ if(tls_epoch_time==0)
+ epoch_time = EPOCH_TIME;
+ else
+ epoch_time = tls_epoch_time;
+
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.SETTIME=%lu\r",(unsigned long)epoch_time);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ /*AT+S.TLSCERT=f_ca,<size><CR><data>*/
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT=f_ca,%d\r%s",strlen((const char *)root_ca_server) - 1, root_ca_server);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ /*AT+S.TLSCERT=f_cert,<size><CR><data>*/
+ if(tls_mode[0]=='m')
+ {
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT=f_cert,%d\r%s",strlen((const char *)client_cert) - 1, client_cert);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ /*AT+S.TLSCERT=f_key,<size><CR><data>*/
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT=f_key,%d\r%s",strlen((const char *)client_key) - 1, client_key);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+ }
+
+ /*AT+S.TLSDOMAIN=f_domain,<server domain>*/
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSDOMAIN=f_domain,%s\r", client_domain);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ if(status != WiFi_MODULE_SUCCESS) return status;
+ }
+
+ return status;
+}
+
+/**
+* @brief wifi_socket_client_open
+* Open a network socket
+* @param Hostname hostname to connect to
+* portnumber portnumber of the Host to connect to
+* protocol tcp or udp protocol
+* sock_id socket id of the opened socket returned to the user
+* @retval WiFi_Status_t : return status of socket open request
+*/
+WiFi_Status_t wifi_socket_client_open(uint8_t * hostname, uint32_t port_number, uint8_t * protocol, uint8_t * sock_id)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ Queue_Client_Open_Event(hostname,port_number,protocol);
+ status = USART_Receive_AT_Resp(Process_Event);
+
+ *sock_id = Socket_Open_ID; //return the socket id to the user
+
+ return status;
+}
+
+/**
+* @brief Open_Serial_Port
+* Open a network socket
+* @param None
+* @retval WiFi_Status_t : Wifi status
+*/
+WiFi_Status_t Open_Serial_Port()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ /* AT+S.SOCKOS=2<cr> */
+ Reset_AT_CMD_Buffer();
+ //sprintf((char*)WiFi_AT_Cmd_Buff,"\rAT+S.SOCKOS=%d\r",SerialPortNo);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+
+ if(status==WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+}
+
+/**
+* @brief wifi_socket_client_write
+* Write len bytes of data to socket
+* @param sock_id socket ID of the socket to write to
+* DataLength: data length to send
+* pData : pointer of data buffer to be written
+* @retval WiFi_Status_t : return status of socket write request
+*/
+WiFi_Status_t wifi_socket_client_write(uint8_t sock_id, uint16_t DataLength, char * pData)
+{
+ /* AT+S.SOCKW=00,11<cr> */
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ //Check if sock_id is open
+ if(!open_sockets[sock_id])
+ return WiFi_NOT_READY;
+
+ if(DataLength>=1021 || DataLength<=0)
+ return WiFi_NOT_SUPPORTED;
+
+ Queue_Client_Write_Event(sock_id,DataLength,pData);
+ status = USART_Receive_AT_Resp(Process_Event);
+ return status;
+}
+
+/**
+* @brief Socket_Read
+* Return len bytes of data from socket
+* @param DataLength: data length to read
+* @retval WiFi_Status_t : return status of socket read request
+*/
+WiFi_Status_t Socket_Read(uint16_t DataLength)
+{
+ /* AT+S.SOCKR=01,12<cr> */
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ wait_for_command_mode();
+
+ /* AT+S.SOCKON=myserver,1234,t<cr> */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SOCKET_READ,sockon_query_id,DataLength);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ if(status_flag.stop_event_dequeue == WIFI_FALSE)
+ status_flag.stop_event_dequeue = WIFI_TRUE;
+ SockON_Data_Length = DataLength;
+ status_flag.enable_sock_read = WIFI_TRUE;
+ process_buffer_index =5;
+ status_flag.enable_receive_data_chunk = WIFI_TRUE;
+ WiFi_Module_State = Process_Event;
+ status_flag.Set_AT_Cmd_Response_False = WIFI_TRUE;
+ memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);
+ }
+ return status;
+}
+
+/**
+* @brief wifi_socket_client_close
+* The SOCKC command allows to close socket
+* @param sock_close_id the socket ID of the socket which needs to be closed.
+* @retval WiFi_Status_t : return status of socket close request
+*/
+WiFi_Status_t wifi_socket_client_close(uint8_t sock_close_id)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ if(open_sockets[sock_close_id])
+ {
+ Queue_Client_Close_Event(sock_close_id);
+ return status;
+ }
+ else
+ return WiFi_MODULE_ERROR;
+
+}
+
+/**
+* @brief Socket_Pending_Data
+* Query pending data.It will returns the number of bytes of data waiting on socket
+* @param None
+* @retval uint8_t :number of bytes of data waiting on socket
+*/
+void Socket_Pending_Data()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ /* AT+S.SOCKQ=01<cr> */
+ Reset_AT_CMD_Buffer();
+
+ wait_for_command_mode();
+
+ if(open_sockets[sockon_query_id])
+ {
+ if(status_flag.stop_event_dequeue == WIFI_FALSE)
+ status_flag.stop_event_dequeue = WIFI_TRUE;
+
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_QUERY_PENDING_DATA,sockon_query_id);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status==WiFi_MODULE_SUCCESS)
+ {
+ /* EQ. Set state to Process_Event */
+ WiFi_Module_State = Process_Event;
+ status_flag.Set_AT_Cmd_Response_False = WIFI_TRUE;
+ }
+}
+}
+
+/**
+* @brief wifi_socket_server_open
+* Open a Server socket
+* @param None
+* @retval WiFi_Status_t : return status of server socket request
+*/
+WiFi_Status_t wifi_socket_server_open(uint32_t port_number, uint8_t * protocol)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+Reset_AT_CMD_Buffer();
+
+/* AT+S.SOCKD=portNo,t<cr> */
+sprintf((char*)WiFi_AT_Cmd_Buff,AT_SERVER_SOCKET_OPEN,(int)port_number,protocol);
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+{
+status = USART_Receive_AT_Resp(Process_Event);
+}
+return status;
+}
+
+/**
+* @brief wifi_socket_server_write
+* Write to a Server socket
+* @param None
+* @retval WiFi_Status_t : return status of server socket request
+*/
+WiFi_Status_t wifi_socket_server_write(uint16_t DataLength,char * pData)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+/*Can only write if there is a client connected*/
+if(!wifi_client_connected)
+{
+return WiFi_NOT_READY;
+}
+ __disable_irq();
+
+status_flag.do_not_reset_push_WIFI_event = WIFI_TRUE;
+status_flag.prevent_push_WIFI_event = WIFI_TRUE;
+__enable_irq();
+
+while(status_flag.sock_read_ongoing || WIND64_count!= 0)//wait till any pending data is read
+{
+ asm("NOP");
+}
+
+wait_for_command_mode();
+
+/*to make sure that by default the mode is not switched to command mode from data mode*/
+status_flag.switch_by_default_to_command_mode = WIFI_FALSE;
+
+/*Switch to Data Mode first*/
+if(!status_flag.data_mode)
+{
+WiFi_switch_to_data_mode();//switch by default
+while(!status_flag.data_mode)
+{
+ //Wait till data_mode is active
+ asm("NOP");
+}
+}
+
+/*Write the data on the uart*/
+/*if(HAL_UART_Transmit(&UartWiFiHandle, (uint8_t *)pData, DataLength,1000)!= HAL_OK)
+{
+Error_Handler();
+return WiFi_HAL_UART_ERROR;
+}*/
+//HAL_Delay(100);//Wait for tx before switching back to command mode
+
+/*Switch back to Command Mode*/
+if(!status_flag.command_mode)
+{
+WiFi_switch_to_command_mode();//switch by default
+while(!status_flag.command_mode)
+{
+ //Wait till command_mode is active
+ asm("NOP");
+}
+}
+
+status_flag.switch_by_default_to_command_mode = WIFI_TRUE; /*back to default behaviour*/
+
+__disable_irq();
+status_flag.prevent_push_WIFI_event = WIFI_FALSE;
+status_flag.do_not_reset_push_WIFI_event = WIFI_FALSE;
+__enable_irq();
+
+return status;
+}
+
+/**
+* @brief Server Socket Close
+* Close a Server socket
+* @param None
+* @retval WiFi_Status_t : return status of server socket request
+*/
+WiFi_Status_t wifi_socket_server_close()
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+Reset_AT_CMD_Buffer();
+
+/* AT+S.SOCKD=portNo,t<cr> */
+sprintf((char*)WiFi_AT_Cmd_Buff,AT_SERVER_SOCKET_CLOSE);
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+{
+status = USART_Receive_AT_Resp(Process_Event);
+}
+
+return status;
+}
+
+
+/**
+* @brief wait_for_command_mode
+* Waits till we are in command mode
+* @param None
+* @retval None
+*/
+void wait_for_command_mode(void)
+{
+while(!status_flag.command_mode)
+ {
+ //Make sure we are in command mode, ideally we should do this in every User API?
+ asm("NOP");
+ }
+}
+
+
+/**
+* @brief wifi_file_delete
+* Delete a file
+* @param pFileName : File Name to be deleted
+* @retval WiFi_Status_t : return status of delete file request
+*/
+WiFi_Status_t wifi_file_delete(char * pFileName)
+{
+/* AT+S.FSD: delete an existing file */
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+Reset_AT_CMD_Buffer();
+/* AT+S.FSL */
+sprintf((char*)WiFi_AT_Cmd_Buff,AT_DELETE_FILE,pFileName);
+
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+{
+status = USART_Receive_AT_Resp(Process_Event);
+}
+return status;
+}
+
+/**
+* @brief wifi_file_list
+* List existing filename
+* @param None
+* @retval WiFi_Status_t : return status of AT cmd request
+*/
+
+WiFi_Status_t wifi_file_list()
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+Queue_Wifi_File_Event(NULL,NULL,0);
+status = USART_Receive_AT_Resp(Process_Event);
+return status;
+}
+
+/**
+* @brief wifi_file_show
+* Print the contents of an existing file
+* @param pFileName : pinter of file name
+* @retval WiFi_Status_t : return status of AT cmd request
+*/
+
+WiFi_Status_t wifi_file_show(uint8_t * pFileName)
+{
+if(pFileName==NULL)
+ return WiFi_MODULE_ERROR;
+
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+Queue_Wifi_File_Event(NULL,pFileName,0);
+status = USART_Receive_AT_Resp(Process_Event);
+return status;
+}
+
+/**
+* @brief wifi_file_create
+* Create file for HTTP server
+* @param pFileName : pointer of file name to be created
+* alength : length of file
+* @retval WiFi_Status_t : return status of AT cmd request
+*/
+
+WiFi_Status_t wifi_file_create(char *pFileName, uint16_t alength, char * pUserFileBuff)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+if(alength >1024)
+return WiFi_AT_FILE_LENGTH_ERROR;
+
+Reset_AT_CMD_Buffer();
+
+/* AT+S.FSC=/index.html */
+sprintf((char*)WiFi_AT_Cmd_Buff, AT_CREATE_NEW_HTML_FILE, pFileName, alength);
+
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+{
+status = USART_Receive_AT_Resp(Process_Event);
+int len = strlen(pUserFileBuff);
+
+if(len >= 1024)
+ return WiFi_AT_FILE_LENGTH_ERROR;
+
+/* AT+S.FSA=/index.html */
+sprintf((char*)WiFi_AT_Cmd_Buff,AT_APPEND_FILE,pFileName,len);
+
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+{
+ memset(WiFi_AT_Cmd_Buff, 0x00, sizeof WiFi_AT_Cmd_Buff);
+ memcpy((char*)(char*)WiFi_AT_Cmd_Buff, (char*) pUserFileBuff,len);
+ WiFi_AT_Cmd_Buff[len+1]='\r';
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+}
+}
+return status;
+}
+
+/**
+* @brief wifi_http_get
+* Issue an HTTP GET of the given path to the specified host
+* @param None
+* @retval WiFi_Status_t : return status of AT cmd response
+*/
+
+WiFi_Status_t wifi_http_get(uint8_t * hostname, uint8_t * path, uint32_t port_number)
+{
+if(hostname == NULL || path == NULL)
+return WiFi_MODULE_ERROR;
+
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+while(status_flag.sock_read_ongoing || WIND64_count!= 0); //wait till any pending data is read
+{
+ asm("NOP");
+}
+
+// AT+S.HTTPGET=host.example.com,/index.html, port_number<cr>
+//Queue the http-get command
+Queue_Http_Event(hostname, path, port_number,NULL);
+
+//Make the user wait anyway
+status = USART_Receive_AT_Resp(Process_Event);
+
+return status;
+
+}
+
+/**
+* @brief wifi_http_post
+* Issue an HTTP GET of the given path to the specified host
+* @param None
+* @retval WiFi_Status_t : status of Http Post Request
+*/
+
+WiFi_Status_t wifi_http_post(uint8_t * pURL_path)
+{
+if(pURL_path == NULL)
+return WiFi_MODULE_ERROR;
+
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+while(status_flag.sock_read_ongoing || WIND64_count!= 0);//wait till any pending data is read
+{
+ asm("NOP");
+}
+
+// AT+S.HTTPPOST = posttestserver.com,/post.php,name=demo&email=mymail&subject=subj&body=message<cr>
+Queue_Http_Event(NULL,NULL,0,pURL_path);
+
+//Make the user wait anyway
+status = USART_Receive_AT_Resp(Process_Event);
+return status;
+}
+
+/**
+* @brief wifi_file_image_create
+* Downloads an updated file system via a single HTTP GET request to the
+* named host and path.
+* @param None
+* @retval WiFi_Status_t
+*/
+WiFi_Status_t wifi_file_image_create(uint8_t * pHostName, uint8_t * pFileName, uint32_t port_number)
+{
+if(pHostName == NULL || pFileName == NULL || port_number ==0)
+return WiFi_MODULE_ERROR;
+
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+Queue_Wifi_File_Event(pHostName,pFileName,port_number);
+status = USART_Receive_AT_Resp(Process_Event);
+
+/* Soft reset the module */
+SET_Power_State(PowerSave_State);
+return status;
+}
+
+/**
+* @brief wifi_file_erase_external_flash
+* This API allows to erase the content of the external flash
+* @param None
+* @retval WiFi_Status_t
+*/
+WiFi_Status_t wifi_file_erase_external_flash()
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+Reset_AT_CMD_Buffer();
+ResetBuffer();
+
+/* AT+S.HTTPDFSERASE */
+sprintf((char*)WiFi_AT_Cmd_Buff,AT_ERASE_FLASH_MEMORY);
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+
+/* Soft reset the module */
+SET_Power_State(PowerSave_State);
+
+return status;
+}
+
+/**
+* @brief wifi_fw_update
+* Issue an HTTP GET of the given path to the specified host and get the firmware updated
+* @param None
+* @retval None
+*/
+WiFi_Status_t wifi_fw_update(uint8_t * hostname, uint8_t * filename_path, uint32_t port_number)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+Queue_Wifi_FW_Update_Event(hostname,filename_path,port_number);
+status = USART_Receive_AT_Resp(Process_Event);
+/* Soft reset the module */
+SET_Power_State(PowerSave_State);
+return status;
+}
+
+/**
+* @brief wifi_network_scan
+* Performs an immediate scan for available network
+* @param None
+* @retval WiFi_Status_t : WiFi status error
+*/
+WiFi_Status_t wifi_network_scan(wifi_scan *scan_result, uint16_t max_scan_number)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+wifi_scanned_list = scan_result;
+if(max_scan_number>MAX_WIFI_SCAN_NETWORK)
+return WiFi_NOT_SUPPORTED;
+user_scan_number = max_scan_number;
+
+if(status_flag.Scan_Ongoing)
+{
+return WiFi_AT_CMD_BUSY;
+}
+
+status_flag.Scan_Ongoing = WIFI_TRUE;
+
+#if 0 //TBD
+if(WiFi_Param.WiFi_Module_State == WiFi_MiniAP_MODE)
+return WiFi_NOT_SUPPORTED;
+#endif
+
+/* AT+S.SCAN: performs an immediate scan for available networks */
+Reset_AT_CMD_Buffer();
+sprintf((char*)WiFi_AT_Cmd_Buff,AT_WiFi_SCAN);
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+{
+status = USART_Receive_AT_Resp(Process_Event);
+}
+
+/*At this point we have WiFi_Scan_Buffer filled with RSSI and SSID values*/
+return status;
+}
+
+/**
+* @brief Set_MiniAP_Mode
+* Configure Wi-Fi module in AP mode.
+ MiniAP is always configured in open mode (WEP not supported)
+* @param None
+* @retval WiFi_Status_t : status of AT cmd
+*/
+WiFi_Status_t wifi_ap_start(uint8_t * ssid, uint8_t channel_num)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+/* Set the SSID : AT+S.SSIDTXT=<SSID>*/
+//if(ssid)
+ status = SET_SSID((char*)ssid);
+
+
+if(status != WiFi_MODULE_SUCCESS)
+return WiFi_SSID_ERROR;
+
+/* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,0*/
+status = SET_Configuration_Value(WIFI_PRIV_MODE, None);
+if(status != WiFi_MODULE_SUCCESS)
+return WiFi_CONFIG_ERROR;
+
+/* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,3*/
+status = SET_Configuration_Value(WIFI_MODE, WiFi_MiniAP_MODE);
+if(status != WiFi_MODULE_SUCCESS)
+return WiFi_CONFIG_ERROR;
+
+/* Set the channel number */
+status = SET_Configuration_Value(WIFI_CHANNEL_NUMBER, channel_num);
+if(status != WiFi_MODULE_SUCCESS)
+return WiFi_CONFIG_ERROR;
+
+/* Save the settings on the flash memory : AT&W*/
+Save_Current_Setting();
+
+status_flag.WiFi_Configuration_Done = WIFI_TRUE;
+WiFi_Module_State = Process_Event;
+
+/* Soft reset the module */
+SET_Power_State(PowerSave_State);
+
+return status;
+}
+
+
+/**
+* @brief SET_WiFi_STA_Mode
+* Configure Wi-Fi module in STA mode
+* @param SSID : SSID name
+* @param sec_key : security key
+* @param priv_mode : network privecy mode
+* @retval WiFi_Status_t : status of AT cmd
+*/
+WiFi_Status_t wifi_connect(char * ssid, char * sec_key, WiFi_Priv_Mode priv_mode)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+if(status_flag.AT_Cmd_Ongoing == WIFI_FALSE)
+status_flag.AT_Cmd_Ongoing = WIFI_TRUE;
+else
+{
+return WiFi_AT_CMD_BUSY;
+}
+
+if(sec_key) {
+status = SET_WiFi_SecKey((char*)sec_key);
+if(status != WiFi_MODULE_SUCCESS)
+ return WiFi_SecKey_ERROR;
+}
+
+/* Set the SSID : AT+S.SSIDTXT=<SSID>*/
+
+ status = SET_SSID((char*)ssid);
+
+if(status != WiFi_MODULE_SUCCESS)
+return WiFi_SSID_ERROR;
+
+/* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,2*/
+status = SET_Configuration_Value(WIFI_PRIV_MODE, priv_mode);
+if(status != WiFi_MODULE_SUCCESS)
+return WiFi_CONFIG_ERROR;
+
+/* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,1*/
+status = SET_Configuration_Value(WIFI_MODE, WiFi_STA_MODE);
+if(status != WiFi_MODULE_SUCCESS)
+return WiFi_CONFIG_ERROR;
+
+/* Save the settings on the flash memory : AT&W*/
+Save_Current_Setting();
+
+status_flag.WiFi_Configuration_Done = WIFI_TRUE;
+//WiFi_Module_State = WiFi_Process_Event;
+
+/* Soft reset the module */
+SET_Power_State(PowerSave_State);
+
+status_flag.AT_Cmd_Ongoing = WIFI_FALSE;
+
+return status;
+}
+
+/**
+* @brief SET_WiFi_IBSS_Mode
+* Configure Wi-Fi module in IBSS mode
+* @param SSID : SSID name
+* @param priv_mode : network privecy mode
+* @retval WiFi_Status_t : status of AT cmd
+*/
+WiFi_Status_t wifi_adhoc_create(uint8_t * ssid, WiFi_Priv_Mode priv_mode)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+Attention_Cmd();
+/* Set the SSID : AT+S.SSIDTXT=<SSID>*/
+status = SET_SSID((char*)ssid);
+if(status != WiFi_MODULE_SUCCESS)
+return WiFi_SSID_ERROR;
+
+/* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,0*/
+status = SET_Configuration_Value(WIFI_PRIV_MODE, priv_mode);
+if(status != WiFi_MODULE_SUCCESS)
+ return WiFi_CONFIG_ERROR;
+
+
+/* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,2*/
+status = SET_Configuration_Value(WIFI_MODE, WiFi_IBSS_MODE);
+if(status != WiFi_MODULE_SUCCESS)
+ return WiFi_CONFIG_ERROR;
+
+/* Set IP address */
+status = SET_Configuration_Addr(WIFI_IP_ADDRESS, WIFI_IBSS_IP_ADDR);
+if(status != WiFi_MODULE_SUCCESS)
+ return WiFi_CONFIG_ERROR;
+
+/* Set IP default gateway */
+status = SET_Configuration_Addr(WIFI_IP_DEFAULT_GATEWAY, WIFI_IBSS_DEFAULT_GATEWAY);
+if(status != WiFi_MODULE_SUCCESS)
+ return WiFi_CONFIG_ERROR;
+
+
+/* Set IP DNS */
+status = SET_Configuration_Addr(WIFI_IP_DNS, WIFI_IBSS_IP_DNS_ADDR);
+if(status != WiFi_MODULE_SUCCESS)
+ return WiFi_CONFIG_ERROR;
+
+/* Set IP netmask */
+status = SET_Configuration_Addr(WIFI_IP_NETMASK, WIFI_IBSS_IP_MASK);
+if(status != WiFi_MODULE_SUCCESS)
+ return WiFi_CONFIG_ERROR;
+
+/* Turn OFF the DHCP */
+SET_Configuration_Value(IP_USE_DHCP_SERVER, WIFI_IP_USE_DHCP);
+if(status != WiFi_MODULE_SUCCESS)
+ return WiFi_CONFIG_ERROR;
+
+/* Save the settings on the flash memory : AT&W*/
+Save_Current_Setting();
+
+/* Soft reset the module */
+SET_Power_State(PowerSave_State);
+return status;
+}
+
+
+/**
+* @brief wifi_standby
+* Configured WiFi module to enter standby
+* @param arg_standby_time: standby time
+* @retval WiFi_Status_t : status of AT cmd
+*/
+WiFi_Status_t wifi_standby(uint8_t arg_standby_time)
+{
+/*
+For Standby, the presence of Jumpers on JP4 and JP3 has the following behaviour:
+JP3 (middle and bottom): prevents standby and immediately wakes-up module
+JP3 (middle and top): no effect on standby
+JP4 (middle and right): prevents wakeup and standby runs forever
+JP4 (middle and left): no effect on standby
+*/
+
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+/*if(arg_standby_time<2)
+return WiFi_NOT_SUPPORTED;*/
+
+SET_Configuration_Value(WIFI_SLEEP_ENABLED, 0);
+SET_Configuration_Value(WIFI_STANDBY_ENABLED, 1);
+status = SET_Configuration_Value(WIFI_STANDBY_TIME, arg_standby_time);
+
+/* save current setting in flash */
+Save_Current_Setting();
+
+/* AT : send AT command */
+sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_POWER_STATE,1); //cfun=4
+WiFi_Module_State = Process_Event; //make sure the WiFi module is in this state to receive WINDS after wakeup
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+
+if(status == WiFi_MODULE_SUCCESS)//if transmit is success, prepare for resume
+{
+/*
+status_flag.AT_Cmd_Processing = WIFI_TRUE;//We do not want the next UART data_byte fetch to be done
+HAL_NVIC_DisableIRQ(USARTx_IRQn);//Disable UART IRQ
+status_flag.Standby_Timer_Running=WIFI_TRUE;
+printf("\r\nGoing into Standby Mode...\r\n");*/
+}
+
+return status;
+
+}
+
+/**
+* @brief wifi_wakeup
+* wakeup the module from sleep by setting the GPIO6 through PC13
+* or allow it to go to sleep
+* Jumper needed on JP4
+* @param wakeup wakeup (WIFI_TRUE) or allow sleep(WIFI_FALSE)
+* @retval WiFi_Status_t : status of function call
+*/
+WiFi_Status_t wifi_wakeup(wifi_bool wakeup)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+
+/*RESET_WAKEUP_GPIO_CLK_ENABLE();
+
+WAKEUP_InitStruct.Pin = WiFi_WAKEUP_GPIO_PIN;
+WAKEUP_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+WAKEUP_InitStruct.Pull = GPIO_NOPULL;
+WAKEUP_InitStruct.Speed = GPIO_SPEED_HIGH;
+
+HAL_GPIO_Init(WiFi_WAKEUP_GPIO_PORT, &WAKEUP_InitStruct);
+*/
+
+ if(wakeup)
+ callSpwfSADevice_wakeup(spwf_device_class, 1);
+ else
+ callSpwfSADevice_wakeup(spwf_device_class, 0);
+
+
+return status;
+}
+
+
+/**
+* @brief wifi_disconnect
+* disconnect the module from any AP
+* @param None
+* @retval WiFi_Status_t : status of AT cmd
+*/
+WiFi_Status_t wifi_disconnect(void)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+/* Set wifi_mode to idle*/
+status = SET_Configuration_Value(WIFI_MODE, WiFi_IDLE_MODE);
+
+/*If module was connected, reset the status*/
+if(wifi_connected == 1)
+ {
+ wifi_connected = 0;//this will allow the TIM handler to make the callback on connection(WiFiUp)
+ }
+
+/* save current setting in flash */
+Save_Current_Setting();
+
+/* Soft reset the module */
+status = SET_Power_State(PowerSave_State);//CFUN=1
+
+return status;
+}
+
+/**
+* @brief wifi_enable
+* Enable/Disable the Wi-Fi interface
+* @param enable enable Wi-Fi (WIFI_TRUE) disable Wi-Fi (WIFI_FALSE)
+* @retval WiFi_Status_t : status of AT cmd
+*/
+WiFi_Status_t wifi_enable(wifi_bool enable)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+/* Enable or Disable wifi interface*/
+Reset_AT_CMD_Buffer();
+sprintf((char*)WiFi_AT_Cmd_Buff,AT_WIFI_ENABLE, enable);
+
+/*if(HAL_UART_Transmit(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, strlen((char*)WiFi_AT_Cmd_Buff),1000)!= HAL_OK)
+{
+Error_Handler();
+#if DEBUG_PRINT
+printf("HAL_UART_Transmit Error");
+#endif
+return WiFi_HAL_UART_ERROR;
+} */
+
+status = USART_Receive_AT_Resp(Process_Event);
+
+//wait for power down/hw started
+if(enable)
+while(status_flag.WiFi_Enabled != WIFI_TRUE)
+{
+ asm("NOP");
+}
+else
+while(status_flag.WiFi_Enabled != WIFI_FALSE)
+{
+ asm("NOP");
+}
+
+return status;
+
+}
+
+
+
+/**
+* @brief wifi_restore
+* Restore the Wi-Fi with default values.
+* @param None
+* @retval WiFi_Status_t : status of AT cmd
+*/
+WiFi_Status_t wifi_restore()
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+/* Restore default setting*/
+Restore_Default_Setting();
+
+/* Set wifi_mode to idle*/
+SET_Configuration_Value(WIFI_MODE, WiFi_IDLE_MODE);
+
+/* set the local echo */
+SET_Configuration_Value(LOCALECHO1, 0);
+
+/* save current setting in flash */
+Save_Current_Setting();
+
+/* Soft reset the module */
+status = SET_Power_State(PowerSave_State);//CFUN=1
+
+return status;
+}
+
+/*GPIO Configuration Functions*/
+
+/**
+* @brief wifi_gpio_init
+* Configure a GPIO pin as in or out with IRQ setting
+* @param pin GPIO pin number
+* @param irq configuration of the pin
+* @retval WiFi_Status_t : status of AT cmd
+*/
+uint8_t wifi_gpio_init(GpioPin pin, char* dir, char irq)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+/* AT+S.GPIOC=pin,dir,irq */
+Reset_AT_CMD_Buffer();
+
+memset(WiFi_AT_Cmd_Buff, 0x00, sizeof WiFi_AT_Cmd_Buff);
+
+if(irq!=GPIO_Off)
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOC=%d,%s,%c\r", pin, dir, irq);
+else
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOC=%d,%s\r", pin, dir);
+
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+
+
+return status;
+
+}
+
+/**
+* @brief wifi_gpio_read
+* Read the configuration of a GPIO pin
+* @param pin GPIO pin number
+* @param val value returned
+* @param dir configuration direction returned
+* @retval WiFi_Status_t : status of AT cmd
+*/
+uint8_t wifi_gpio_read(GpioPin pin, uint8_t *val, uint8_t *dir)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+/* AT+S.GPIOR=pin */
+Reset_AT_CMD_Buffer();
+
+sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOR=%d\r", pin);
+
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+*val = gpio_value;
+*dir = gpio_direc;
+
+return status;
+}
+
+/**
+* @brief wifi_gpio_write
+* Read the value of a GPIO pin
+* @param pin GPIO pin number
+* @param val value to be configured
+* @retval WiFi_Status_t : status of AT cmd
+*/
+uint8_t wifi_gpio_write(GpioPin pin, GpioWriteValue value)
+{
+WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+/* AT+S.GPIOW=pin,value */
+Reset_AT_CMD_Buffer();
+
+sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOW=%d,%d\r", pin, value);
+
+status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+
+return status;
+}
+
+void UART_Configuration(uint32_t baud_rate)
+{
+}
+
+#ifdef USART_PRINT_MSG
+void USART_PRINT_MSG_Configuration(uint32_t baud_rate)
+{
+}
+#endif
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1/spwf/wifi_module.c Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,3427 @@
+/**
+ ******************************************************************************
+ * @file wifi_module.c
+ * @author Central LAB
+ * @version V2.0.0
+ * @date 10-February-2016
+ * @brief Enable Wi-Fi functionality using AT cmd set
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+/* Includes ------------------------------------------------------------------*/
+#include "wifi_module.h"
+//#include "stm32_spwf_wifi.h"
+#include "ring_buffer.h"
+#include "stdio.h"
+#include "string.h"
+#include "event_buffer.h"
+#include "device.h"
+#include "wait_api.h"
+#include <stddef.h>
+
+
+/** @addtogroup MIDDLEWARES
+* @{
+*/
+
+
+/** @defgroup NUCLEO_WIFI_MODULE
+ * @brief Wi-Fi driver modules
+ * @{
+ */
+
+
+/** @defgroup NUCLEO_WIFI_MODULE_Private_Defines
+ * @{
+ */
+
+
+/**
+ * @}
+ */
+
+
+/** @addtogroup NUCLEO_WIFI_MODULE_Private_Variables
+ * @{
+ */
+/* Private variables ---------------------------------------------------------*/
+
+/*All Buffers*/
+//uint8_t WiFi_AT_Cmd_Buff[1024];
+uint8_t process_buffer[MAX_BUFFER_GLOBAL];
+char UserDataBuff[MAX_BUFFER_GLOBAL];
+uint8_t USART_RxBuffer[64];//This buffer is only used in the Init phase (to receive "\r\nOK\r\n")
+char print_msg_buff[MAX_BUFFER_GLOBAL];
+volatile uint8_t ring_buffer[RINGBUF_SIZE];/* Default size for ring buffer */
+
+#ifdef USE_STM32L0XX_NUCLEO
+event_s_TypeDef event_buffer[10];
+#else
+event_s_TypeDef event_buffer[50];
+#endif
+
+volatile uint8_t pop_buffer[MAX_BUFFER_GLOBAL];
+volatile uint8_t prefetch_buffer[20];
+uint8_t uart_byte[1];
+buffer_td big_buff;
+buffer_e event_buff;
+event_s_TypeDef element;
+uint8_t HTTP_Runway_Buff[6];//Used to store the last 6 bytes in between User Callbacks during HTTP tx
+wifi_scan *wifi_scanned_list; //[MAX_WIFI_SCAN_NETWORK];
+
+volatile Wifi_Status_Var status_flag;
+
+uint32_t wind64_DQ_wait = 0;
+uint32_t UserDataBuff_index;
+volatile uint32_t tickcount;
+uint8_t SocketId;
+uint32_t SockON_Data_Len;
+uint32_t Socket_Data_Length =0;
+uint8_t Socket_Open_ID, sockon_query_id,sockon_id_user;
+uint32_t SockON_Data_Length;
+uint8_t enable_pending_data =0;
+
+volatile WiFi_WIND_State_TypeDef WiFi_WIND_State;//describes the current WIND number in processing
+
+uint8_t WiFi_Resp_OK = 0;
+uint32_t number_of_bytes=0;
+uint32_t interim_number_of_bytes=0;
+uint32_t Interim_SockON_Data_Len=0;
+uint32_t bytes_to_be_read = 0;
+uint32_t sock_total_count=0;
+uint32_t sockD_total_count=0;
+uint32_t ip_fragment_count=0;
+uint32_t chunk_size;
+uint32_t message_size;
+uint32_t WIND55_count=0;
+volatile uint32_t WIND64_count=0;
+uint8_t user_scan_number;
+uint32_t pop_queue_length;
+uint32_t pop_buffer_size=0;
+uint32_t process_buffer_index = 5;
+uint32_t epoch_time = 0;
+
+volatile WiFi_AT_CMD_Response_t WiFi_Module_State;
+
+uint8_t *WiFi_Scan_Buffer;
+uint8_t * curr_hostname;
+uint8_t * curr_path;
+uint8_t * curr_pURL;
+uint8_t * curr_protocol;
+uint32_t curr_port_number;
+char * curr_data;
+uint8_t curr_sockID;
+uint8_t * curr_filename;
+uint16_t curr_DataLength;
+uint16_t sock_server_write_datalength;
+char *sock_server_write_pdata;
+
+uint8_t socket_closed_id_callback;
+uint8_t remote_socket_closed_id;
+uint8_t client_socket_close_id;
+volatile uint8_t wifi_ready = WIFI_FALSE;//Set once if wifi is ready for first time
+volatile uint8_t wifi_connected = WIFI_FALSE;//Set once if wifi is connected for first time
+volatile uint8_t wifi_client_connected = 0;//Set once if client is connected
+volatile uint8_t wifi_client_disconnected = 0;//Set once if client is dis-connected
+uint8_t gpio_value, gpio_direc, get_cfg_value[64];
+WiFi_Status_t user_error_code = WiFi_MODULE_SUCCESS;
+
+uint8_t no_of_open_client_sockets = 0;
+wifi_bool open_sockets[8]; //Max open sockets allowed is 8. Each array element depicts one socket (true=open, false=closed)
+uint8_t client_MAC_address[17];//current client MAC address store
+
+uint8_t enable_uart_byte_data_receive=1;
+uint8_t uart_data_receive_ready=1;
+
+WiFi_Status_t AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+uint32_t sleep_count = 0;
+uint32_t standby_time = 0;
+uint8_t scanned_ssids = 0;
+char * prefetch_str;
+
+#if defined (USE_STM32F4XX_NUCLEO) || (USE_STM32L4XX_NUCLEO)
+uint8_t WiFi_AT_Cmd_Buff[2048];
+#else
+uint8_t WiFi_AT_Cmd_Buff[1024];
+#endif
+
+#ifdef USART_PRINT_MSG
+#define printf(arg) {sprintf((char*)print_msg_buff,arg); \
+HAL_UART_Transmit(&UartMsgHandle, (uint8_t*)print_msg_buff, strlen(print_msg_buff), 1000);}
+#endif
+
+void * spwf_dev_;
+
+extern void callSpwfSADevice_debug(void* object, const char * string);
+extern void callSpwfSADevice_attach(wifi_bool attach);
+
+#if defined (__CC_ARM)
+size_t strnlen (const char* s, size_t maxlen);
+
+size_t strnlen (const char* s, size_t maxlen)
+ {
+ size_t len = 0;
+
+ while ((len <= maxlen) && (*s))
+ {
+ s++;
+ len++;
+ }
+
+ return len;
+ }
+#endif
+
+event_s_TypeDef event_s;
+event_s_TypeDef * event_pop_s;
+
+// [DLI]
+#ifdef WIFI_USE_VCOM
+
+uint8_t console_listen_char[1];
+uint8_t console_input_char[1];
+uint8_t console_send_char[1];
+uint8_t console_echo_char[1];
+uint8_t console_send_ready = 0;
+uint8_t console_echo_ready = 1;
+uint8_t console_push_ready = 0;
+
+// Virtual-COM UART
+void console_input() {
+ //HAL_UART_Receive_IT(&UartMsgHandle, (uint8_t *)console_input_char, 1);
+}
+
+void wifi_vcom() {
+
+ uint8_t * temp;
+
+ if (console_push_ready == 1) {
+ push_buffer(&big_buff, uart_byte);
+ console_push_ready = 0;
+ //HAL_UART_Receive_IT(&UartWiFiHandle, (uint8_t *)uart_byte, 1);
+ }
+ if(console_echo_ready == 0) {
+ temp = pop_buffer_queue(&big_buff);
+ if(temp != NULL) {
+ console_echo_ready = 1;
+ //HAL_UART_Transmit_IT(&UartMsgHandle, temp, 1);
+ }
+ }
+}
+
+#endif
+
+/**
+ * @}
+ */
+
+/** @defgroup NUCLEO_WIFI_MODULE_Private_Functions
+ * @{
+ */
+
+/**
+ *Changed/introduced functions for MBED implementation:
+
+- void Wifi_TIM_Handler(void); - new fn
+- void Rx_irq_handler(void); - new fn - in place of HAL_UART_RxCpltCallback
+- Receive_Data(); - modified fn
+- void wifi_reset(void) - modified fn
+- void PowerUp_WiFi_Module(void) - modified fn
+- void RX_EXTI_Isr(uint16_t GPIO_Pin) - removed fn
+- void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandleArg) - removed fn
+- void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandleArg) - removed fn
+- void HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle) - removed fn
+- WiFi_Status_t USART_Transmit_AT_Cmd(uint16_t size)- modified fn
+*/
+
+
+
+/**
+ * @brief WiFi_Module_Init
+ * Initialize wifi module
+ * @param None
+ * @retval None
+ */
+void WiFi_Module_Init(void)
+{
+#ifdef WIFI_USE_VCOM
+ console_input();
+#else
+ WiFi_Module_State = Process_Event;
+#endif
+
+ initialize_status_flags();
+ init(&big_buff, RINGBUF_SIZE);//Init the ring buffer
+ wifi_ready = 0; //reset to get user callback on HW started
+ wifi_connected = 0; //reset to get user callback on WiFi UP
+ Receive_Data();
+
+#ifdef USE_STM32L0XX_NUCLEO
+ event_init(&event_buff, 10); //max 15 events can be Q'ed (Event Buffer is of size 15)
+#else
+ event_init(&event_buff, 50); //max 50 events can be Q'ed (Event Buffer is of size 50)
+#endif
+
+#ifndef WIFI_USE_VCOM
+ Start_Timer();
+ memset(open_sockets,0x00, 8); //init the open socket array
+
+#endif
+}
+
+/**
+* @brief initialize_status_flags
+* Default Wifi status values
+* @param None
+* @retval None
+*/
+void initialize_status_flags()
+{
+ status_flag.Single_Digit_Indication = WIFI_FALSE;
+ status_flag.WiFi_Enabled = WIFI_FALSE;
+ status_flag.http_req_pending = WIFI_FALSE;
+ status_flag.WiFi_Configuration_Done = WIFI_FALSE;
+ status_flag.Timer_Running = WIFI_FALSE;
+ status_flag.resume_receive_data = WIFI_FALSE;
+ status_flag.enable_dequeue = WIFI_TRUE;
+ status_flag.stop_event_dequeue = WIFI_FALSE;
+ status_flag.Standby_Timer_Running = WIFI_FALSE;
+ status_flag.trigger_wakeup_callback = WIFI_FALSE;
+ status_flag.Deep_Sleep_Enabled = WIFI_FALSE;
+ status_flag.Standby_Enabled = WIFI_FALSE;
+ status_flag.Low_Power_Enabled = WIFI_FALSE;
+ status_flag.command_mode=WIFI_TRUE;
+ status_flag.data_mode=WIFI_FALSE;
+ status_flag.Scan_Ongoing = WIFI_FALSE;
+ status_flag.AT_Cmd_Ongoing = WIFI_FALSE;
+ status_flag.AT_Cmd_Processing = WIFI_FALSE;
+ status_flag.Uartx_Rx_Processing = WIFI_FALSE;
+ status_flag.Client_Connected = WIFI_FALSE;
+ status_flag.Client_Disconnected = WIFI_FALSE;
+ status_flag.switch_by_default_to_command_mode = WIFI_TRUE;
+ status_flag.start_sock_read = WIFI_FALSE;
+ status_flag.enable_receive_data_chunk = WIFI_FALSE;
+ status_flag.data_pending_sockD=WIFI_FALSE;
+ status_flag.enable_sock_read = WIFI_FALSE;
+ status_flag.enable_query = WIFI_FALSE;
+ status_flag.Set_AT_Cmd_Response_False = WIFI_FALSE;
+ status_flag.enable_fw_update_read = WIFI_FALSE;
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ status_flag.Q_Contains_Data = WIFI_FALSE;
+ status_flag.enable_receive_http_response = WIFI_FALSE;
+ status_flag.enable_receive_file_response = WIFI_FALSE;
+ status_flag.enable_receive_wifi_scan_response = WIFI_FALSE;
+ status_flag.prevent_push_OK_event = WIFI_FALSE;
+ status_flag.client_socket_close_ongoing = WIFI_FALSE;
+ status_flag.prevent_push_WIFI_event = WIFI_FALSE;
+ status_flag.sock_read_ongoing = WIFI_FALSE;
+ status_flag.enable_client_socket_write = WIFI_FALSE;
+ status_flag.event_deQ_x_wind64 = WIFI_FALSE;
+ status_flag.do_not_reset_push_WIFI_event = WIFI_FALSE;
+ status_flag.message_pending = WIFI_FALSE;
+ status_flag.Pending_SockON_Callback = WIFI_FALSE;
+ status_flag.Pending_SockD_Callback = WIFI_FALSE;
+ status_flag.SockON_Server_Closed_Callback = WIFI_FALSE;
+ status_flag.Client_Socket_Close_Cmd = WIFI_FALSE;
+ status_flag.standby_resume_callback = WIFI_FALSE;
+ status_flag.HTTP_Data_available = WIFI_FALSE;
+ status_flag.FILE_Data_available = WIFI_FALSE;
+ status_flag.AT_Response_Received = WIFI_FALSE;
+ status_flag.Deep_Sleep_Timer = WIFI_FALSE;
+ status_flag.Deep_Sleep_Callback = WIFI_FALSE;
+}
+
+
+/**
+* @brief Period elapsed callback in non blocking mode
+* This timer is used for calling back User registered functions with information
+* @param htim : TIM handle
+* @retval None
+*/
+
+void Wifi_TIM_Handler(void)
+{
+ /**********************************************************************
+ * *
+ * Be careful not to make a blocking *
+ * call from this function, see *
+ * example Socket_Read() and Socket_Close() *
+ * *
+ **********************************************************************/
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ if(status_flag.stop_event_dequeue == WIFI_FALSE /*&& !status_flag.enable_receive_data_chunk*/)
+ {
+ __disable_irq();
+ event_pop_s = pop_eventbuffer_queue(&event_buff);
+ __enable_irq();
+
+ if(event_pop_s!=NULL && event_pop_s->event_pop == WIFI_TRUE)
+ {
+ switch(event_pop_s->event)
+ {
+ case WIFI_WIND_EVENT:
+ Process_WiFi_Indication_Cmd(event_pop_s);
+ break;
+
+ case WIFI_OK_EVENT:
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_MODULE_SUCCESS;
+ if(status_flag.Set_AT_Cmd_Response_False == WIFI_TRUE)
+ {
+ status_flag.Set_AT_Cmd_Response_False = WIFI_FALSE;
+ status_flag.AT_Response_Received = WIFI_FALSE;
+ }
+ if(status_flag.enable_client_socket_write) //allows the OK received after socket client write to be processed
+ {
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ status_flag.enable_client_socket_write = WIFI_FALSE;
+ }
+ break;
+
+ case WIFI_SOCK_ID_EVENT:
+ /*check ID and update SocketID array*/
+ no_of_open_client_sockets++;
+
+ if(no_of_open_client_sockets > 8) //Max number of clients is 8
+ {
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_NOT_SUPPORTED;
+ break;
+ }
+
+ open_sockets[event_pop_s->socket_id] = WIFI_TRUE;
+ Socket_Open_ID = event_pop_s->socket_id;
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_MODULE_SUCCESS;
+ break;
+
+ case WIFI_HTTP_EVENT:
+ Reset_AT_CMD_Buffer();
+ memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer
+
+ if(curr_pURL) {
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_HTTPPOST_REQUEST,curr_pURL);
+ }
+ else {
+ if(curr_port_number!=0)
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.HTTPGET=%s,%s,%d\r",curr_hostname, curr_path, (int)curr_port_number);
+ else
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.HTTPGET=%s,%s\r",curr_hostname, curr_path);
+ }
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS) {
+ WiFi_Module_State = Process_Event;
+ status_flag.stop_event_dequeue = WIFI_TRUE;
+ status_flag.http_req_pending = WIFI_TRUE;
+ }
+ else {
+ #if DEBUG_PRINT
+ printf("\r\n ERROR IN HTTP \r\n");
+ #endif
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ }
+ break;
+
+ case WIFI_CLIENT_SOCKET_WRITE_EVENT:
+ Reset_AT_CMD_Buffer();
+ /* AT+S.SOCKW=00,11<cr> */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SOCKET_WRITE,curr_sockID,curr_DataLength);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+
+ if(status == WiFi_MODULE_SUCCESS) {
+ Reset_AT_CMD_Buffer();
+ memcpy((char*)(char*)WiFi_AT_Cmd_Buff, (char*)curr_data,curr_DataLength);
+ WiFi_AT_Cmd_Buff[curr_DataLength]='\r';
+
+ status = USART_Transmit_AT_Cmd(curr_DataLength+2);
+ if(status == WiFi_MODULE_SUCCESS) {
+ WiFi_Module_State = Process_Event;
+ }
+ else {
+ #if DEBUG_PRINT
+ printf("\r\n ERROR IN SOCKET\r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ }
+ }
+ else {
+ #if DEBUG_PRINT
+ printf("\r\n ERROR In Socket\r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ }
+ break;
+
+ case WIFI_CLIENT_SOCKET_OPEN_EVENT:
+ Reset_AT_CMD_Buffer();
+
+ /* AT+S.SOCKON = myserver,1234,t <cr> */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SOCKET_OPEN,curr_hostname,(int)curr_port_number,curr_protocol);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status != WiFi_MODULE_SUCCESS)
+ {
+ #if DEBUG_PRINT
+ printf("\r\n ERROR During Socket Open \r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ }
+ break;
+
+ case WIFI_CLIENT_SOCKET_CLOSE_EVENT:
+ Reset_AT_CMD_Buffer();
+
+ /* AT+S.SOCKC=00<cr> */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SOCKET_CLOSE,event_pop_s->socket_id);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ AT_RESPONSE = WiFi_MODULE_SUCCESS;
+ status_flag.prevent_push_OK_event = WIFI_TRUE; //prevent the OK received after socket close command to be Q'ed
+ status_flag.stop_event_dequeue = WIFI_TRUE;
+ remote_socket_closed_id = event_pop_s->socket_id;
+ status_flag.client_socket_close_ongoing = WIFI_TRUE; //used for making changes in the value of open_sockets[sock_id] if no error is returned
+// status_flag.SockON_Server_Closed_Callback = WIFI_TRUE;
+ }
+ else
+ {
+ #if DEBUG_PRINT
+ printf("\r\n ERROR During Socket Close \r\n");
+ #endif
+ }
+ break;
+
+
+ case WIFI_FILE_EVENT:
+ Reset_AT_CMD_Buffer();
+
+ if(curr_filename == NULL)
+ {
+ /* AT+S.FSL */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_DISPLAY_FILE_NAME);
+ }
+ else if(curr_hostname == NULL)
+ {
+ /* AT+S.FSP=/index.html */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_DISPLAY_FILE_CONTENT,curr_filename);
+ }
+ else
+ {
+ /* AT+S.HTTPDFSUPDATE=%s,/outfile.img */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_DOWNLOAD_IMAGE_FILE,curr_hostname,curr_filename,(int)curr_port_number);
+ }
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ WiFi_Module_State = Process_Event;
+ status_flag.enable_receive_http_response = WIFI_TRUE;
+ status_flag.enable_receive_data_chunk = WIFI_TRUE;
+ status_flag.enable_receive_file_response = WIFI_TRUE;
+ }
+ else {
+ #if DEBUG_PRINT
+ printf("\r\n ERROR in FILE \r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ }
+ break;
+
+ case WIFI_FW_UPDATE_EVENT:
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.FWUPDATE=%s,/%s,%d\r",curr_hostname,curr_filename,(int)curr_port_number);
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ WiFi_Module_State = Process_Event;
+ status_flag.enable_fw_update_read = WIFI_TRUE;
+ status_flag.enable_receive_data_chunk = WIFI_TRUE;
+ }
+ else
+ {
+ #if DEBUG_PRINT
+ printf("\r\n ERROR in Firmware \r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ }
+ break;
+
+ case WIFI_ERROR_EVENT:
+ #if DEBUG_PRINT
+ printf("\r\n ERROR!\r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ break;
+
+ case WIFI_GCFG_EVENT:
+ case WIFI_GPIO_EVENT:
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_MODULE_SUCCESS;
+ break;
+
+ case WIFI_STANDBY_CONFIG_EVENT:
+ #if DEBUG_PRINT
+ printf("\r\nGoing into standby..\r\n");
+ #endif
+ WiFi_Module_State = Process_Event;
+ break;
+
+ case WIFI_RESUME_CONFIG_EVENT:
+ #if DEBUG_PRINT
+ printf("\r\nResuming from standby..\r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;//let main run-on
+ break;
+
+ case WIFI_NO_EVENT:
+ break;
+ }
+ }
+ }
+ /* If data is pending on client socket SOCKON, make read requests*/
+ if(status_flag.start_sock_read == WIFI_TRUE)
+ {
+ //flush_buffer_queue(&big_buff);
+ Socket_Read(Socket_Data_Length);
+ status_flag.start_sock_read = WIFI_FALSE;
+ }
+
+ /* Call Query, after notification for TLS is received */
+ else if(status_flag.enable_query == WIFI_TRUE && status_flag.enable_dequeue == WIFI_TRUE)
+ {
+ //@TBD: Flushing the buffer may be detrimental if we have genuine follow on WIND55?
+ //flush_buffer_queue(&big_buff); //Flush the buffer to remove WIND:55 in pipeline (This maybe a problem)
+ Socket_Pending_Data();
+ status_flag.enable_query = WIFI_FALSE;
+ }
+
+ else if(status_flag.Pending_SockON_Callback==WIFI_TRUE)//for client socket
+ {
+ //Now callback to user with user_data pointer <UserDataBuff>
+ ind_wifi_socket_data_received(sockon_id_user, (uint8_t *)UserDataBuff, message_size, chunk_size);
+ memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer
+ Resume_Dequeue();
+ status_flag.Pending_SockON_Callback=WIFI_FALSE;
+ }
+
+ else if(status_flag.Pending_SockD_Callback == WIFI_TRUE)//for server socket
+ {
+ //if(status_flag.command_mode)//if command_mode is achieved then callback else loop in this state
+ {
+ //Now callback to user with user_data pointer <UserDataBuff>
+ ind_wifi_socket_data_received(9, (uint8_t *)UserDataBuff, message_size, chunk_size);
+ memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer
+ Resume_Dequeue();
+ status_flag.Pending_SockD_Callback=WIFI_FALSE;
+ }
+ }
+
+ else if(status_flag.Client_Socket_Close_Cmd==WIFI_TRUE)//for client socket
+ {
+ //Close the socket
+ //Change State to AT_Cmd_Response before calling socket_close()
+ WiFi_Module_State = Process_Event;
+ wifi_socket_client_close(client_socket_close_id);
+ status_flag.Client_Socket_Close_Cmd = WIFI_FALSE;
+// status_flag.SockON_Server_Closed_Callback = WIFI_TRUE;
+ }
+
+ else if(status_flag.SockON_Server_Closed_Callback==WIFI_TRUE)//for client socket
+ {
+ //callback the user
+ ind_wifi_socket_client_remote_server_closed(&socket_closed_id_callback);
+ status_flag.SockON_Server_Closed_Callback = WIFI_FALSE;
+ }
+
+ else if(status_flag.HTTP_Data_available == WIFI_TRUE)
+ {
+ ind_wifi_http_data_available((uint8_t *)UserDataBuff,UserDataBuff_index);
+ memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer
+// memcpy(&UserDataBuff, &HTTP_Runway_Buff, 6);
+// memset(HTTP_Runway_Buff, 0x00, 6);
+ Resume_Dequeue();
+ status_flag.HTTP_Data_available=WIFI_FALSE;
+ }
+
+ else if (status_flag.FILE_Data_available == WIFI_TRUE)
+ {
+ ind_wifi_file_data_available((uint8_t *) UserDataBuff);
+ memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer
+ Resume_Dequeue();
+ status_flag.FILE_Data_available = WIFI_FALSE;
+ }
+ else if(status_flag.Client_Connected == WIFI_TRUE)
+ {
+ ind_socket_server_client_joined();
+ status_flag.Client_Connected = WIFI_FALSE;
+ }
+
+ else if(status_flag.Client_Disconnected == WIFI_TRUE)
+ {
+ ind_socket_server_client_left();
+ status_flag.Client_Disconnected = WIFI_FALSE;
+ }
+
+ //Make callbacks from here to user for pending events
+
+ if(WiFi_WIND_State.WiFiHWStarted==WIFI_TRUE)
+ {
+ if(wifi_ready == 2)//Twice reset for User Callback
+ {
+ wifi_ready++;
+ ind_wifi_on();//Call this once only...This if for wifi_on (instead of console active
+ }
+ }
+
+ if(WiFi_WIND_State.WiFiUp == WIFI_TRUE)
+ {
+ if(wifi_connected == 0)
+ {
+ wifi_connected = 1;
+ ind_wifi_connected();//wifi connected
+ }
+ WiFi_WIND_State.WiFiUp = WIFI_FALSE;
+ }
+
+ else if(WiFi_WIND_State.WiFiStarted_MiniAPMode == WIFI_TRUE)
+ {
+ ind_wifi_ap_ready();
+ WiFi_WIND_State.WiFiStarted_MiniAPMode = WIFI_FALSE;
+ }
+
+ else if(WiFi_WIND_State.WiFiAPClientJoined == WIFI_TRUE)
+ {
+ ind_wifi_ap_client_joined(client_MAC_address);
+ WiFi_WIND_State.WiFiAPClientJoined = WIFI_FALSE;
+ }
+
+ else if(WiFi_WIND_State.WiFiAPClientLeft == WIFI_TRUE)
+ {
+ ind_wifi_ap_client_left(client_MAC_address);
+ WiFi_WIND_State.WiFiAPClientLeft = WIFI_FALSE;
+ }
+
+ else if(status_flag.Deep_Sleep_Callback == WIFI_TRUE)
+ {
+ ind_wifi_resuming();
+ status_flag.Deep_Sleep_Callback = WIFI_FALSE;
+ }
+
+ else if(status_flag.standby_resume_callback == WIFI_TRUE)
+ {
+ ind_wifi_resuming();
+ status_flag.standby_resume_callback = WIFI_FALSE;
+ }
+
+ else if(WiFi_WIND_State.WiFiHWFailure==WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiHWFailure=WIFI_FALSE;
+ ind_wifi_error(WiFi_HW_FAILURE_ERROR);//call with error number
+ }
+
+ else if(WiFi_WIND_State.HardFault==WIFI_TRUE)
+ {
+ WiFi_WIND_State.HardFault=WIFI_FALSE;
+ ind_wifi_error(WiFi_HARD_FAULT_ERROR);//call with error number
+ }
+
+ else if(WiFi_WIND_State.StackOverflow==WIFI_TRUE)
+ {
+ WiFi_WIND_State.StackOverflow=WIFI_FALSE;
+ ind_wifi_error(WiFi_STACK_OVERFLOW_ERROR);//call with error number
+ }
+
+ else if(WiFi_WIND_State.MallocFailed==WIFI_TRUE)
+ {
+ WiFi_WIND_State.MallocFailed=WIFI_FALSE;
+ ind_wifi_error(WiFi_MALLOC_FAILED_ERROR);//call with error number
+ }
+
+ else if(WiFi_WIND_State.InitFailure==WIFI_TRUE)
+ {
+ WiFi_WIND_State.InitFailure=WIFI_FALSE;
+ ind_wifi_error(WiFi_INIT_ERROR);//call with error number
+ }
+
+ else if(WiFi_WIND_State.StartFailed==WIFI_TRUE)
+ {
+ WiFi_WIND_State.StartFailed=WIFI_FALSE;
+ ind_wifi_error(WiFi_START_FAILED_ERROR);//call with error number
+ }
+
+ else if(WiFi_WIND_State.WiFiException==WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiException=WIFI_FALSE;
+ ind_wifi_error(WiFi_EXCEPTION_ERROR);//call with error number
+ }
+
+ else if(WiFi_WIND_State.PS_Mode_Failure==WIFI_TRUE)
+ {
+ WiFi_WIND_State.PS_Mode_Failure=WIFI_FALSE;
+ ind_wifi_warning(WiFi_POWER_SAVE_WARNING);//call with error number
+ }
+
+ else if(WiFi_WIND_State.HeapTooSmall==WIFI_TRUE)
+ {
+ WiFi_WIND_State.HeapTooSmall=WIFI_FALSE;
+ ind_wifi_warning(WiFi_HEAP_TOO_SMALL_WARNING);//call with error number
+ }
+
+ else if(WiFi_WIND_State.WiFiSignalLOW==WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiSignalLOW=WIFI_FALSE;
+ ind_wifi_warning(WiFi_SIGNAL_LOW_WARNING);//call with error number
+ }
+
+ else if(WiFi_WIND_State.WiFiDeauthentication == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiDeauthentication = WIFI_FALSE;
+ ind_wifi_connection_error(WiFi_DE_AUTH);
+ }
+
+ else if(WiFi_WIND_State.WiFiDisAssociation == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiDisAssociation = WIFI_FALSE;
+ ind_wifi_connection_error(WiFi_DISASSOCIATION);
+ }
+
+ else if(WiFi_WIND_State.WiFiJoinFailed == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiJoinFailed = WIFI_FALSE;
+ ind_wifi_connection_error(WiFi_JOIN_FAILED);
+ }
+
+ else if(WiFi_WIND_State.WiFiScanBlewUp == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiScanBlewUp = WIFI_FALSE;
+ ind_wifi_connection_error(WiFi_SCAN_BLEWUP); //@TBD to check if user made call, so not call callback if true
+ }
+
+ else if(WiFi_WIND_State.WiFiScanFailed == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiScanFailed = WIFI_FALSE;
+ ind_wifi_connection_error(WiFi_SCAN_FAILED); //@TBD to check if user made call, so not call callback if true
+ }
+
+ else if(WiFi_WIND_State.WiFiUnHandledInd == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiUnHandledInd = WIFI_FALSE;
+ ind_wifi_packet_lost(WiFi_UNHANDLED_IND_ERROR); //@TBD to check if user made call, so not call callback if true
+ }
+
+ else if(WiFi_WIND_State.WiFiRXMgmt == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiRXMgmt = WIFI_FALSE;
+ ind_wifi_packet_lost(WiFi_RX_MGMT); //@TBD to check if user made call, so not call callback if true
+ }
+
+ else if(WiFi_WIND_State.WiFiRXData == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiRXData = WIFI_FALSE;
+ ind_wifi_packet_lost(WiFi_RX_DATA); //@TBD to check if user made call, so not call callback if true
+ }
+
+ else if(WiFi_WIND_State.WiFiRxUnk == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiRxUnk = WIFI_FALSE;
+ ind_wifi_packet_lost(WiFi_RX_UNK); //@TBD to check if user made call, so not call callback if true
+ }
+
+ else if(WiFi_WIND_State.WiFiSockdDataLost == WIFI_TRUE)
+ {
+ WiFi_WIND_State.WiFiSockdDataLost = WIFI_FALSE;
+ ind_wifi_socket_server_data_lost(); //@TBD to check if user made call, so not call callback if true
+ }
+
+}
+
+
+/**
+* @brief Start_Timer
+* Start Timer
+* @param None
+* @retval None
+*/
+void Start_Timer()
+{
+ //tickcount = WIFI_FALSE;
+ status_flag.Timer_Running = WIFI_TRUE;
+}
+
+/**
+* @brief Stop_Timer
+* Stop Timer request
+* @param None
+* @retval None
+*/
+void Stop_Timer()
+{
+ //tickcount = WIFI_FALSE;
+ status_flag.Timer_Running = WIFI_FALSE;
+ //UartReady = SET;
+}
+
+/**
+* @brief Stop_Dequeue
+* Stop dequeuing data from the ring buffer
+* @param None
+* @retval None
+*/
+void Stop_Dequeue()
+{
+ status_flag.enable_dequeue = WIFI_FALSE;
+}
+
+/**
+* @brief Resume_Dequeue
+* Resume dequeuing data from the ring buffer
+* @param None
+* @retval None
+*/
+void Resume_Dequeue()
+{
+ status_flag.enable_dequeue = WIFI_TRUE;
+}
+
+/**
+* @brief Wifi_SysTick_Isr
+* Function called every SysTick to process buffer
+* @param None
+* @retval None
+*/
+void Wifi_SysTick_Isr()
+{
+ //Check if Data is Paused
+ if((status_flag.Timer_Running) && (status_flag.enable_dequeue==WIFI_TRUE))
+ {
+ Process_WiFi();
+ }
+
+ if(status_flag.Timeout_Timer) tickcount++;
+
+ /*if(status_flag.resume_receive_data == WIFI_TRUE)
+ {
+ if(is_half_empty(&big_buff))
+ {
+ status_flag.resume_receive_data = WIFI_FALSE;
+ //callSpwfSADevice_attach(1);
+ Receive_Data();
+
+ }
+ }*/
+
+
+ if(status_flag.Standby_Timer_Running) // module is in sleep and after expiry RX will be conf as EXTI
+ {
+ if((standby_time++) >= EXTI_CONF_TIMER)
+ {
+ status_flag.Standby_Timer_Running=WIFI_FALSE;
+ standby_time = 0;
+ //configure_to_exti();
+ }
+ }
+
+ /*A Resume WIND:70 has come and triggered this
+ So checking here if after that resume we fall back to sleep (another WIND69) within SLEEP_RESUME_PREVENT time.
+ If yes, we assume it is a false resume and hence do nothing and go back to sleep
+ If no WIND69 (going into sleep) has come, we can assume the resume was genuine and then enable the callback
+ */
+ if((status_flag.Deep_Sleep_Timer) && ( sleep_count++) >= SLEEP_RESUME_PREVENT)
+ {
+ if(status_flag.Deep_Sleep_Enabled == WIFI_TRUE)//which means we have received another WIND69 in the 2 seconds
+ {
+ //do nothing, go back to sleep
+ status_flag.Deep_Sleep_Enabled = WIFI_TRUE;
+ status_flag.Deep_Sleep_Callback = WIFI_FALSE;
+ }
+ else if (status_flag.Deep_Sleep_Enabled == WIFI_FALSE) //which means we have not received any WIND69 during the last 2 seconds
+ {
+ //enable the user callback as it is a genuine WIND70
+ status_flag.Deep_Sleep_Callback = WIFI_TRUE;
+ }
+ Stop_DeepSleep_Timer();
+ }
+}
+
+
+/**
+* @brief USART_Receive_AT_Resp
+* Receive and check AT cmd response
+* @param WiFi_AT_CMD_Response_t : WIFi module next state
+* @retval WiFi_Status_t : Response of AT cmd
+*/
+
+WiFi_Status_t USART_Receive_AT_Resp(WiFi_AT_CMD_Response_t state)
+{
+ WiFi_Module_State = state;
+ tickcount=0;//reset timer
+ status_flag.Timeout_Timer = WIFI_TRUE;
+ while(status_flag.AT_Response_Received != WIFI_TRUE) {
+ if(tickcount >=20000)//20 sec wait
+ {
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ break;
+ }
+ __NOP();
+ }
+ status_flag.Timeout_Timer = WIFI_FALSE;
+ status_flag.AT_Response_Received = WIFI_FALSE;
+ return AT_RESPONSE;
+}
+
+
+/**
+* @brief Process_WiFi
+* Pop a byte from the circular buffer and send the byte for processing
+* This function should be called from main or should be run with a periodic timer
+* @param None
+* @retval None
+*/
+void Process_WiFi(void)
+{
+ uint8_t * temp;//pop buffer temporary
+
+ __disable_irq();
+ temp=pop_buffer_queue(&big_buff); //contents of temp(pop_buffer) will not change till another de-queue is made
+ __enable_irq();
+
+ if(temp!=NULL)
+ {
+ Process_Buffer(temp);
+ }
+
+ if(status_flag.event_deQ_x_wind64)//if de-Q is stopped due to WIND64 wait
+ {
+ wind64_DQ_wait++;//1ms for each count
+ if(wind64_DQ_wait>200)//wait for 50ms for example
+ {
+ wind64_DQ_wait=0;
+ status_flag.event_deQ_x_wind64 = WIFI_FALSE;
+ //re-enable event Q after 200ms
+ status_flag.stop_event_dequeue = WIFI_FALSE;
+ }
+ }
+}
+
+/**
+* @brief Process_Buffer
+* Process and construct a Wind Line buffer
+* @param ptr: pointer to one single byte
+* @retval None
+*/
+
+void Process_Buffer(uint8_t * ptr)
+{
+ static uint32_t Fillptr=0;//count=0;
+ static uint8_t index, chan_value;
+ unsigned char rxdata = 0;
+ int rssi_value = 0;
+ char SocketId_No[2];
+ char databytes_No[4];
+ char * pStr;
+
+ rxdata = *(ptr+0);
+ //printf(&rxdata);//check prints for debug...to be removed or kept in DEBUG statement
+ if(status_flag.enable_receive_data_chunk == WIFI_FALSE)
+ process_buffer[Fillptr++] = rxdata;
+ reset_event(&event_s);
+ switch (WiFi_Module_State)
+ {
+ case Process_Event:
+
+ if((process_buffer[Fillptr-2]==0xD) && (process_buffer[Fillptr-1]==0xA) && !status_flag.enable_receive_http_response && !status_flag.sock_read_ongoing)
+ {
+ if((strstr((const char *)process_buffer,"WIND:")) != NULL)
+ {
+ if((strstr((const char *)process_buffer,"+WIND:67:")) !=NULL)
+ event_s.event = WIFI_STANDBY_CONFIG_EVENT;
+
+ else if ((strstr((const char *)process_buffer,"+WIND:68:"))!= NULL)
+ event_s.event = WIFI_RESUME_CONFIG_EVENT;
+
+ else
+ {
+ //end of msg received. Will not receive any other msg till we process this.
+ //Stop_Timer();
+ //#if defined (USE_STM32L0XX_NUCLEO) || (USE_STM32F4XX_NUCLEO) || (USE_STM32L4XX_NUCLEO)
+ //__disable_irq();
+ //#endif
+ Process_Wind_Indication(&process_buffer[0]);
+ //#if defined (USE_STM32L0XX_NUCLEO) || (USE_STM32F4XX_NUCLEO) || (USE_STM32L4XX_NUCLEO)
+ //__enable_irq();
+ //#endif
+ //Start_Timer();
+ sock_total_count=0;
+ }
+
+ if(!status_flag.prevent_push_WIFI_event)
+ {
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+ reset_event(&event_s);
+ }
+
+ if (!status_flag.do_not_reset_push_WIFI_event) status_flag.prevent_push_WIFI_event = WIFI_FALSE;
+ if(status_flag.enable_sock_read)
+ {
+ status_flag.sock_read_ongoing = WIFI_FALSE;//we finished processing a message and now sock read will commence
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ }
+ Fillptr=0;
+ memset(process_buffer, 0x00, strlen((const char*)process_buffer));
+ }
+
+ else if((strstr((const char *)process_buffer,"\r\nOK\r\n")) != NULL)
+ {
+ /*Now Check to which AT Cmd response this OK belongs to so that correct parsing can be done*/
+
+ // SOCKON ID (Open a client socket)
+ if(((pStr=(strstr((const char *)process_buffer,"ID: "))) != NULL))
+ {
+ SocketId_No[0] = *(pStr + 4) ;
+ SocketId_No[1] = *(pStr + 5) ;
+ SocketId = (((SocketId_No[0] - '0') * 10 ) + (SocketId_No[1] - '0'));
+ event_s.socket_id = SocketId;
+ event_s.event = WIFI_SOCK_ID_EVENT;
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+ reset_event(&event_s);
+ if(status_flag.enable_sock_read)
+ {
+ status_flag.sock_read_ongoing = WIFI_FALSE; //we finished processing a message and now sock read will commence
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ }
+ Fillptr=0;
+ sock_total_count=0;
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ }
+
+ // DATALEN from SOCKQ
+ else if((pStr=(strstr((const char *)process_buffer,"DATALEN: "))) != NULL)
+ {
+ //Find the DataLength and do a socket read
+ databytes_No[0] = *(pStr + 9);
+ databytes_No[1] = *(pStr + 10);
+ databytes_No[2] = *(pStr + 11);
+ databytes_No[3] = *(pStr + 12);
+
+ if( databytes_No[1] == '\r')
+ {
+ SockON_Data_Len = databytes_No[0] - '0';
+ }
+ else if( databytes_No[2] == '\r')
+ {
+ SockON_Data_Len = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0'));
+ }
+ else if( databytes_No[3] == '\r')
+ {
+ SockON_Data_Len = (((databytes_No[0] - '0') * 100 ) + ((databytes_No[1] - '0') * 10 ) + (databytes_No[2] - '0'));
+ }
+ else //it's a 4-digit number
+ {
+ SockON_Data_Len = ((databytes_No[0] - '0') * 1000 ) + ((databytes_No[1] - '0') * 100 ) + ((databytes_No[2] - '0') * 10) + (databytes_No[3] - '0');
+ }
+ Socket_Data_Length = SockON_Data_Len;
+ if(Socket_Data_Length != 0)
+ {
+ status_flag.start_sock_read = WIFI_TRUE;
+ }
+ else if(Socket_Data_Length == 0)
+ {
+ status_flag.stop_event_dequeue = WIFI_FALSE; //continue popping events if nothing to read
+ status_flag.Set_AT_Cmd_Response_False = WIFI_FALSE;
+ }
+ Fillptr = 0;
+ sock_total_count = 0;
+ if(status_flag.enable_sock_read)
+ {
+ status_flag.sock_read_ongoing = WIFI_FALSE; //we finished processing a message and now sock read will commence
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ pop_buffer_size = 0;
+ pop_buffer[0]='\0'; // required as this byte is already used in process_buffer
+ }
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ }
+
+ else if((((strstr((const char *)process_buffer," = "))) != NULL))
+ {
+ // AT command GCFG
+ pStr = (char *) strstr((const char *)process_buffer," = ");
+ event_s.event = WIFI_GCFG_EVENT;
+ memcpy(get_cfg_value, pStr+2, (strlen(pStr)-2));
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+ reset_event(&event_s);
+ if(status_flag.enable_sock_read)
+ {
+ status_flag.sock_read_ongoing = WIFI_FALSE; //we finished processing a message and now sock read will commence
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ }
+ Fillptr=0;
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ }
+
+ else
+ {
+ //This is a standalone OK
+ /*Cases possible
+ - TLSCERT,TLSCERT2, TLSDOMAIN, SETTIME
+ - S.SOCKW, SOCKR, S.SOCKC, S.SOCKD (open a server socket)
+ - File Operations
+ - S.GPIOC and S.GPIOW
+ */
+ //Push a simple OK Event, if this is an OK event required to be pushed to Q
+ if(status_flag.prevent_push_OK_event)
+ {
+ //This OK is not to be handled, hence the pop action on OK completion to be done here
+ //since pop will not happen
+// stop_event_dequeue=WIFI_FALSE;
+
+ if(status_flag.client_socket_close_ongoing)
+ {
+ if(no_of_open_client_sockets > 0)
+ no_of_open_client_sockets--;
+ status_flag.prevent_push_OK_event = WIFI_FALSE;
+ open_sockets[remote_socket_closed_id] = WIFI_FALSE;
+ socket_closed_id_callback = remote_socket_closed_id;
+ status_flag.Set_AT_Cmd_Response_False = WIFI_FALSE;
+ status_flag.client_socket_close_ongoing = WIFI_FALSE;
+ status_flag.SockON_Server_Closed_Callback = WIFI_TRUE;
+ status_flag.stop_event_dequeue=WIFI_FALSE;
+ }
+
+ }
+
+ else
+ {
+ event_s.ok_eval = WIFI_TRUE;
+ event_s.event = WIFI_OK_EVENT;
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+ reset_event(&event_s);
+ }
+ status_flag.prevent_push_OK_event = WIFI_FALSE;
+ memset(process_buffer, 0x00, Fillptr);
+ Fillptr=0;
+ sock_total_count=0;
+ if(status_flag.enable_sock_read)
+ {
+ status_flag.sock_read_ongoing = WIFI_FALSE;//we finished processing a message and now sock read will commence
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ }
+ break;
+ }
+ }
+
+ else if((((strstr((const char *)process_buffer,"ERROR"))) != NULL))
+ {
+ //This is an ERROR
+ //There can be only ONE outstanding AT command and hence this ERROR belongs to that
+ //HTTP -> ERROR: host not found
+ //@TBD: Check all Errors Possible here???
+ if((strstr((const char *)process_buffer,"\r\nERROR: Pending data\r\n")) != NULL) //if Error after sock close command and not 'OK'
+ {
+ printf("\r\nERROR: Socket could not be closed..PENDING DATA\r\n");
+ status_flag.prevent_push_OK_event = WIFI_FALSE; //prevent the OK received after socket close command to be Q'ed
+ status_flag.client_socket_close_ongoing = WIFI_FALSE;
+ status_flag.stop_event_dequeue = WIFI_FALSE;
+ }
+ else
+ {
+ event_s.event = WIFI_ERROR_EVENT;
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+ reset_event(&event_s);
+ if(status_flag.stop_event_dequeue)
+ /*ERROR:Illegal Socket ID*/
+ status_flag.stop_event_dequeue= WIFI_FALSE;//continue popping events if nothing to read
+ }
+ Fillptr=0;
+ sock_total_count=0;
+ if(status_flag.enable_sock_read)
+ {
+ status_flag.sock_read_ongoing = WIFI_FALSE;//we finished processing a message and now sock read will commence
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ }
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ }
+
+ else if((((strstr((const char *)process_buffer,"GPIO "))) != NULL))
+ {
+ // Receive GPIO Read
+ pStr = (char *) strstr((const char *)process_buffer,"= 0,");
+ if(pStr != NULL)
+ {
+ gpio_value = 0;
+ }
+ else
+ gpio_value = 1;
+
+ pStr = (char *) strstr((const char *)process_buffer,"out");
+ if(pStr != NULL)
+ {
+ gpio_direc= 0; //out
+ }
+ else
+ {
+ gpio_direc= 1; //in
+ }
+ //Push GPIO Read Event on Event_Queue
+ event_s.event = WIFI_GPIO_EVENT;
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+ reset_event(&event_s);
+ if(status_flag.enable_sock_read)
+ {
+ status_flag.sock_read_ongoing = WIFI_FALSE; //we finished processing a message and now sock read will commence
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ }
+ Fillptr = 0;
+ memset(process_buffer, 0x00, strlen((const char*)process_buffer));
+ break;
+ }
+
+ else
+ {
+ if(status_flag.enable_sock_read && status_flag.Q_Contains_Message && !status_flag.message_pending)
+ {
+ printf((const char*)&process_buffer[0]);
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ status_flag.Q_Contains_Data = WIFI_TRUE;
+ //status_flag.enable_sock_read = WIFI_FALSE;
+ //status_flag.stop_event_dequeue= WIFI_FALSE;
+ }
+
+ //if in data mode, reset on \r\n
+ if(!status_flag.sock_read_ongoing && status_flag.data_mode)
+ {
+ Fillptr = 0;
+ memset(process_buffer, 0x00, strlen((const char*)process_buffer));
+ }
+ }
+ }
+
+ else if (status_flag.http_req_pending) //HTTP Response Check
+ {
+ if((strstr((const char *)&process_buffer[0],"200 OK\r")) != NULL || (strstr((const char *)&process_buffer[0],"400 Bad Request\r")) != NULL
+ || (strstr((const char *)&process_buffer[0],"401 Unauthorized\r")) != NULL || (strstr((const char *)&process_buffer[0],"403 Forbidden\r")) != NULL
+ || (strstr((const char *)&process_buffer[0],"404 Not Found\r")) != NULL || (strstr((const char *)&process_buffer[0],"408 Request Timeout\r")) != NULL
+ || (strstr((const char *)&process_buffer[0],"500 Internal Server Error\r")) != NULL || (strstr((const char *)&process_buffer[0],"502 Bad Gateway\r")) != NULL
+ || (strstr((const char *)&process_buffer[0],"504 Gateway Timeout\r")) != NULL)
+ {
+ status_flag.enable_receive_http_response = WIFI_TRUE;
+ status_flag.enable_receive_data_chunk = WIFI_TRUE;
+ status_flag.http_req_pending = WIFI_FALSE;
+ pop_buffer[0]='\0';
+ pop_buffer_size=0;
+ process_buffer_index =6;
+ }
+ }
+
+ else if ((process_buffer[Fillptr-1]==0x09) && (process_buffer[Fillptr-2]==':') && (process_buffer[Fillptr-3]=='1'))//<ht> Horizontal Tab for Scan Result?
+ {
+ status_flag.enable_receive_wifi_scan_response = WIFI_TRUE;
+ }
+
+ if(!status_flag.Pending_SockON_Callback && !status_flag.HTTP_Data_available && !status_flag.FILE_Data_available)
+ {
+ //Check Process Buffer for any pending message
+ if(status_flag.enable_receive_data_chunk)
+ {
+ if(!status_flag.Q_Contains_Data && pop_buffer_size)
+ {
+ pop_queue_length = pop_buffer_size;
+ if(Fillptr + pop_queue_length > 511)
+ {
+ uint32_t length = (Fillptr + pop_queue_length) - 511;
+ __disable_irq();
+ rewind_buffer_queue(&big_buff,length);
+ __enable_irq();
+ memset(ptr+(511 - Fillptr), 0x00, length);
+ pop_queue_length = 511 - Fillptr;
+ }
+ memcpy(process_buffer+Fillptr,(char const *)pop_buffer, pop_queue_length);
+ Fillptr = Fillptr + pop_queue_length;
+
+ if(Fillptr > 512)
+ {
+ printf("\r\nFillptr corrupted!!\r\n");
+ }
+
+ if((strstr((const char *)process_buffer,"ERROR: ")) != NULL)
+ {
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ status_flag.message_pending = WIFI_FALSE;
+ }
+ else if(!status_flag.sock_read_ongoing && !status_flag.enable_receive_http_response)
+ {
+ if(process_buffer[0]!='\0')
+ {
+ if(((process_buffer[0]==0xD) && (process_buffer[1]==0xA)) && process_buffer[2] != 0xD)
+ {
+ status_flag.message_pending = WIFI_TRUE;
+ if((pStr = (strstr((const char *)process_buffer+2,"\r\n"))) != NULL)
+ { // process buffer has complete message
+ int wind_length = ((uint8_t *)pStr - (uint8_t *)process_buffer)+2;
+
+ if(strstr((const char *)process_buffer+2,"DATALEN:"))
+ {
+ pStr = strstr((const char *)process_buffer + wind_length,"\r\nOK\r\n"); //find OK, as DATALEN has to be terminated by OK
+ if(pStr!=NULL)
+ {
+ wind_length = ((uint8_t *)pStr-(uint8_t *)process_buffer)+6;
+ }
+ }
+
+ if(Fillptr-wind_length)
+ {
+ __disable_irq();
+ rewind_buffer_queue(&big_buff, Fillptr - wind_length);
+ __enable_irq();
+ memset(process_buffer + wind_length,0x00,Fillptr - wind_length);
+ Fillptr = wind_length;
+ }
+ status_flag.message_pending = WIFI_FALSE;
+ }
+ status_flag.Q_Contains_Message = WIFI_TRUE;
+ }
+ }
+ }
+ }
+ }
+
+ if(!status_flag.Q_Contains_Message && status_flag.enable_sock_read && pop_buffer_size) /*read is enabled*/
+ {
+ status_flag.sock_read_ongoing = WIFI_TRUE;
+ sock_total_count = sock_total_count + pop_queue_length;
+
+ /* Check for "ERROR: Not enough data in buffer " */
+ pStr = (char *) strstr((const char *)&process_buffer,"ERROR: ");
+
+ if (pStr != NULL)
+ {
+ if((process_buffer[Fillptr-2]==0xD) && (process_buffer[Fillptr-1]==0xA))
+ {
+ if((pStr = (char *)strstr((const char *)&process_buffer,"\r\nERROR: Too many sockets\r\n")) !=NULL)
+ {
+ #if DEBUG_PRINT
+ printf("\r\nERROR: TOO MANY SOCKETS \r\n");
+ #endif
+
+ if(*(pStr+27)!='\0')
+ {
+ int len = (uint8_t *)pStr - (uint8_t *)process_buffer;
+ int extra_bytes = Fillptr - (len+27);
+ __disable_irq();
+ rewind_buffer_queue(&big_buff, extra_bytes);
+ __enable_irq();
+ }
+ Fillptr=0;
+ sock_total_count =0;
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ break;
+ }
+ else if((pStr = (char *)strstr((const char *)&process_buffer,"\r\nERROR: Pending data\r\n")) !=NULL)
+ {
+ #if DEBUG_PRINT
+ printf("\r\nERROR: PENDING DATA \r\n");
+ #endif
+
+ if(*(pStr+23)!='\0')
+ {
+ int len = (uint8_t *)pStr - (uint8_t *)process_buffer;
+ int extra_bytes = Fillptr - (len+23);
+ __disable_irq();
+ rewind_buffer_queue(&big_buff, extra_bytes);
+ __enable_irq();
+ }
+ Fillptr=0;
+ sock_total_count =0;
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ break;
+ }
+
+ printf("\rERROR DURING SOCK READ\r\n");
+ sock_total_count=0;
+ SockON_Data_Len=0;
+ SockON_Data_Length=0;
+ status_flag.enable_sock_read = WIFI_FALSE;
+ status_flag.stop_event_dequeue = WIFI_FALSE;
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ status_flag.Q_Contains_Data = WIFI_FALSE;
+ enable_pending_data = 0;
+ status_flag.enable_receive_data_chunk = WIFI_FALSE;
+ WIND64_count=0;
+ process_buffer_index =5;
+ //status_flag.enable_query = TRUE; //do we have more data?
+ Fillptr=0;
+ status_flag.sock_read_ongoing = WIFI_FALSE;
+ if(status_flag.data_pending_sockD)
+ {
+ status_flag.data_pending_sockD=WIFI_FALSE;
+ number_of_bytes=0;
+ status_flag.switch_by_default_to_command_mode=WIFI_TRUE;
+ WiFi_switch_to_command_mode(); //switch by default
+ }
+
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ break;
+ }
+ }
+
+ /*now check if end of msg received*/
+ if(sock_total_count >= SockON_Data_Length)
+ {
+ #if DEBUG_PRINT
+ printf("\nReached SockON_Data_Len \r\n");
+ #endif
+
+ if(sock_total_count > SockON_Data_Length)
+ {
+ int databytes = sock_total_count - SockON_Data_Length;
+ __disable_irq();
+ rewind_buffer_queue(&big_buff, databytes);
+ __enable_irq();
+ memset(process_buffer+(Fillptr - databytes), 0x00, databytes);
+ Fillptr = Fillptr - databytes;
+ }
+ chunk_size = Fillptr;
+ message_size = SockON_Data_Length;
+ memcpy(UserDataBuff, process_buffer, Fillptr);
+ Fillptr = 0;
+ sock_total_count = 0;
+ SockON_Data_Len = 0;
+ status_flag.Q_Contains_Data = WIFI_FALSE;
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ status_flag.enable_receive_data_chunk = WIFI_FALSE;
+ enable_pending_data = 0;
+
+ if(status_flag.data_pending_sockD)
+ {
+// status_flag.data_pending_sockD=WIFI_FALSE;
+ number_of_bytes=0;
+ sockon_id_user = 0;
+ if(WIND64_count>0)
+ WIND64_count--; //decrease the number of pending WIND:64 Events
+ if(WIND64_count==0) {
+ status_flag.switch_by_default_to_command_mode=WIFI_TRUE;
+ WiFi_switch_to_command_mode(); //switch by default
+ }
+ status_flag.enable_query = WIFI_FALSE;
+ }
+ else
+ {
+ status_flag.enable_query = WIFI_TRUE;
+ sockon_id_user = sockon_query_id;
+ /*@TODO: Do not need to prevent OK push in case of server socket*/
+ status_flag.prevent_push_OK_event = WIFI_TRUE; //prevent the qeueuing of the OK after this read operation
+ }
+
+ status_flag.enable_sock_read = WIFI_FALSE;
+ status_flag.sock_read_ongoing = WIFI_FALSE;
+ Stop_Dequeue(); //Stop dequeue till user callback returns
+ status_flag.Pending_SockON_Callback = WIFI_TRUE; //set this to callback to user with User Buffer pointer
+ //do we have more data?
+ if(status_flag.data_pending_sockD)
+ {
+ status_flag.stop_event_dequeue = WIFI_FALSE;
+ status_flag.data_pending_sockD = WIFI_FALSE;
+ }
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ break;
+ }
+
+ if(Fillptr >= MAX_BUFFER_GLOBAL-1)
+ {
+ message_size = SockON_Data_Length;
+ chunk_size = 511;
+ memcpy(UserDataBuff, process_buffer, Fillptr);
+ Fillptr = 0;
+ process_buffer_index = 5;
+ Stop_Dequeue();
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ status_flag.Pending_SockON_Callback = WIFI_TRUE; //set this to callback to user with User Buffer pointer
+ }
+ break;
+ }
+
+ if (status_flag.enable_receive_http_response && pop_buffer_size) // http response enabled
+ {
+ status_flag.sock_read_ongoing = WIFI_TRUE;
+ if((pStr = (strstr((const char *)process_buffer + process_buffer_index - 6,"\r\nOK\r\n"))) != NULL)
+ {
+ #if DEBUG_PRINT
+ printf("\r\nOK\r\n"); //http response completed
+ #endif
+
+ if(*(pStr+7) != '\0')
+ {
+ int len = (uint8_t *)pStr - (uint8_t *)process_buffer;
+ int extra_bytes = Fillptr - (len+6);
+ __disable_irq();
+ rewind_buffer_queue(&big_buff, extra_bytes);
+ __enable_irq();
+
+ memset(process_buffer+len+7, 0x00, extra_bytes);
+ Fillptr = Fillptr - extra_bytes;
+ }
+
+ memcpy(UserDataBuff, process_buffer, Fillptr);
+ UserDataBuff_index = Fillptr;
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ status_flag.enable_receive_data_chunk = WIFI_FALSE;
+ status_flag.enable_receive_http_response = WIFI_FALSE;
+ Stop_Dequeue();
+ AT_RESPONSE = WiFi_MODULE_SUCCESS;
+ status_flag.sock_read_ongoing = WIFI_FALSE;
+ status_flag.Q_Contains_Data = WIFI_FALSE;
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ status_flag.stop_event_dequeue = WIFI_FALSE;
+ process_buffer_index = 6;
+ memset(process_buffer, 0x00, Fillptr);
+ Fillptr=0;
+
+ if(status_flag.enable_receive_file_response)
+ status_flag.FILE_Data_available = WIFI_TRUE;
+ else
+ status_flag.HTTP_Data_available=WIFI_TRUE;
+ }
+
+ else if(((strstr((const char *)process_buffer + process_buffer_index-6,"ERROR"))) != NULL)
+ {
+ #if DEBUG_PRINT
+ printf("\r\nERROR\r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ status_flag.sock_read_ongoing = WIFI_FALSE;
+ status_flag.enable_receive_data_chunk = WIFI_FALSE;
+ status_flag.Q_Contains_Data = WIFI_FALSE;
+ status_flag.Q_Contains_Message = WIFI_FALSE;
+ Fillptr=0;
+ process_buffer_index=6;
+ status_flag.enable_receive_http_response = WIFI_FALSE;
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+
+ if(status_flag.enable_receive_file_response)
+ status_flag.FILE_Data_available = WIFI_FALSE;
+ else
+ status_flag.HTTP_Data_available=WIFI_FALSE;
+ }
+
+ process_buffer_index = Fillptr;
+ if(Fillptr == MAX_BUFFER_GLOBAL-1 )
+ {
+ memcpy(UserDataBuff, process_buffer, Fillptr);
+ memcpy(&HTTP_Runway_Buff, &UserDataBuff[505], 6);
+ memset(&UserDataBuff[505], 0x00, 6);
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ memcpy(&process_buffer, &HTTP_Runway_Buff, 6);
+ memset(HTTP_Runway_Buff, 0x00, 6);
+ Fillptr = 6;
+ process_buffer_index = 6;
+ UserDataBuff_index = 505;
+ Stop_Dequeue();
+
+ if(status_flag.enable_receive_file_response)
+ status_flag.FILE_Data_available = WIFI_TRUE;
+ else
+ status_flag.HTTP_Data_available=WIFI_TRUE;
+ }
+ break;
+ }
+ }
+ if((!status_flag.Q_Contains_Message) && status_flag.enable_receive_wifi_scan_response)
+ {
+ /*now check if end of msg received*/
+ if((process_buffer[Fillptr-2]==0xD) && (process_buffer[Fillptr-1]==0xA))
+ {
+ if(scanned_ssids < user_scan_number)
+ {
+ pStr = (char *) strstr((const char *)&process_buffer,"CHAN:");
+ if(pStr != NULL)
+ {
+ databytes_No[0] = *(pStr + 6) ;
+ databytes_No[1] = *(pStr + 7) ;
+
+ chan_value = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0'));
+ }
+
+ wifi_scanned_list[scanned_ssids].channel_num = chan_value;
+
+ pStr = (char *) strstr((const char *)&process_buffer,"RSSI:");
+ if(pStr != NULL)
+ {
+ databytes_No[0] = *(pStr + 7) ;
+ databytes_No[1] = *(pStr + 8) ;
+
+ rssi_value = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0'));
+ }
+
+ wifi_scanned_list[scanned_ssids].rssi = -(rssi_value);
+
+ pStr = (char *) strstr((const char *)&process_buffer,"SSID:");
+ if(pStr != NULL)
+ {
+ index = 7;
+ while(*(pStr + index) != 0x27)
+ {
+ wifi_scanned_list[scanned_ssids].ssid[index-7] = *(pStr + index);
+ index++;
+ if(index==35) break; //max ssid lenght is 30 characters
+ }
+ }
+
+ pStr = (char *) strstr((const char *)&process_buffer,"WPA ");
+ if(pStr != NULL)
+ {
+ wifi_scanned_list[scanned_ssids].sec_type.wpa = WIFI_TRUE;
+ } else
+ wifi_scanned_list[scanned_ssids].sec_type.wpa = WIFI_FALSE;
+
+ pStr = (char *) strstr((const char *)&process_buffer,"WPA2 ");
+ if(pStr != NULL)
+ {
+ wifi_scanned_list[scanned_ssids].sec_type.wpa2 = WIFI_TRUE;
+ } else
+ wifi_scanned_list[scanned_ssids].sec_type.wpa2 = WIFI_FALSE;
+
+ pStr = (char *) strstr((const char *)&process_buffer,"WPS ");
+ if(pStr != NULL)
+ {
+ wifi_scanned_list[scanned_ssids].sec_type.wps = WIFI_TRUE;
+ } else
+ wifi_scanned_list[scanned_ssids].sec_type.wps = WIFI_FALSE;
+
+ scanned_ssids++;//increment total_networks
+ //callSpwfSADevice_debug(spwf_dev_,(const char*)scanned_ssids);
+ }
+
+ //end of one line from SCAN result
+ pStr = (char *) strstr((const char *)&process_buffer,"ERROR");
+ if(pStr != NULL)
+ {
+ #if DEBUG_PRINT
+ printf("ERROR Scan Failed");
+ #endif
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ Fillptr=0;
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ status_flag.enable_receive_wifi_scan_response = WIFI_FALSE;
+ status_flag.Scan_Ongoing = WIFI_FALSE; //Enable next scan
+ AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR;
+ break;
+ }
+
+ #if DEBUG_PRINT
+ printf((const char*)process_buffer);
+ #endif
+
+ callSpwfSADevice_debug(spwf_dev_,(const char*)process_buffer);
+
+ if(((strstr((const char *)process_buffer,"OK\r\n"))) != NULL /*|| scanned_ssids==10*/)/*Max 10 networks supported*/
+ {
+ //print and go for next line
+ //If Any part of scan line contains "OK" this will exit!!
+ #if DEBUG_PRINT
+ printf("\nOK\r\n");
+ #endif
+ status_flag.Scan_Ongoing = WIFI_FALSE; //Enable next scan
+ scanned_ssids=0;
+ Fillptr=0;
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ status_flag.enable_receive_wifi_scan_response = WIFI_FALSE;
+ AT_RESPONSE = WiFi_MODULE_SUCCESS;
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ break;
+ }
+
+ Fillptr=0;
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ }
+
+ if(Fillptr>=MAX_BUFFER_GLOBAL-1)
+ {
+ #if DEBUG_PRINT
+ printf("\rHTTP: process_buffer Max Buffer Size reached\r\n");
+ #endif
+ Fillptr=0;
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ }
+ }
+
+ if((!status_flag.Q_Contains_Message) && status_flag.enable_fw_update_read)
+ {
+ #ifdef DEBUG_PRINT
+ printf("*"); //print * till finish
+ #endif
+
+ pStr = (char *) strstr((const char *)process_buffer,"Complete!");
+
+ if(pStr != NULL)
+ {
+ #ifdef DEBUG_PRINT
+ printf("\r\nUpdate complete\r\n");
+ #endif
+ status_flag.AT_Response_Received = WIFI_TRUE;
+ AT_RESPONSE = WiFi_MODULE_SUCCESS;
+ status_flag.enable_fw_update_read = WIFI_FALSE;
+ Fillptr=0;
+ memset(process_buffer, 0x00, strlen((char const *)process_buffer));
+ }
+ if(Fillptr>=MAX_BUFFER_GLOBAL)
+ {
+ Fillptr=0;
+ memset(process_buffer, 0x00, strlen((char const *)process_buffer));
+ }
+
+ //No change of state till we get "+WIND:17:F/W update complete!"
+ }
+
+ /*else no other case is satisfied at least do the following*/
+ {
+ if(Fillptr>=MAX_BUFFER_GLOBAL-1)
+ {
+ Fillptr=0;
+ memset(process_buffer, 0x00,MAX_BUFFER_GLOBAL-1);
+ }
+ }
+ }
+}
+
+/**
+* @brief Process_Wind_Indication_Cmd
+* Process Wind indication command
+* @param process_buff_ptr: pointer of WiFi indication buffer
+* @retval None
+*/
+
+void Process_Wind_Indication(uint8_t *process_buff_ptr)
+{
+ char * pStr = (char*)process_buff_ptr;
+ char Indication_No[2];
+ char databytes_No[4];
+ #if DEBUG_PRINT
+ printf((const char*)process_buff_ptr);
+ #endif
+ //callSpwfSADevice_debug(spwf_dev_,(const char*)process_buff_ptr);
+
+ char * ptr_offset;
+ int i;
+
+ uint32_t wind55_data_len=0;
+ WiFi_Indication_t Wind_No = Undefine_Indication;
+
+ if(pStr != NULL)
+ {
+ pStr = (char *) strstr((const char *)(pStr),"WIND:");///////
+
+ if(pStr != NULL)
+ {
+ Indication_No[0] = *(pStr + 5) ;
+ Indication_No[1] = *(pStr + 6) ;
+
+ if( Indication_No[1] == ':')
+ {
+ status_flag.Single_Digit_Indication = WIFI_TRUE;
+ /* Convert char to integer */
+ Wind_No = (WiFi_Indication_t)(Indication_No[0] - '0');
+ }
+ else
+ {
+ status_flag.Single_Digit_Indication = WIFI_FALSE;
+ /* Convert char to integer */
+ Wind_No = (WiFi_Indication_t)(((Indication_No[0] - '0') * 10 ) + (Indication_No[1] - '0'));
+ }
+
+ event_s.wind = Wind_No;
+ event_s.event = WIFI_WIND_EVENT;
+
+ switch (Wind_No)
+ {
+ case SockON_Data_Pending: /*WIND:55*/
+
+ /*+WIND:55:Pending Data:%d:%d*/
+ ptr_offset = (char *) strstr((const char *)&process_buffer,"Data:");
+
+ /*Need to find out which socket ID has data pending*/
+ databytes_No[0] = *(ptr_offset + 5);
+
+ SocketId = (databytes_No[0] - '0');//Max number of sockets is 8 (so single digit)
+ event_s.socket_id = SocketId;
+ enable_pending_data = 1;
+
+ /* EQ. Check for ENC string to identify TLS case. Set enable_query */
+ if ( (*(ptr_offset + 7) == 'E') && (*(ptr_offset + 8) == 'N') && (*(ptr_offset + 9) == 'C') )
+ {
+ event_s.enc = WIFI_TRUE;
+ }
+ else
+ {
+ //And find the length of the data
+ databytes_No[0] = *(ptr_offset + 7);
+ databytes_No[1] = *(ptr_offset + 8);
+ databytes_No[2] = *(ptr_offset + 9);
+ databytes_No[3] = *(ptr_offset + 10);
+
+ if( databytes_No[1] == '\r')
+ {
+ wind55_data_len = databytes_No[0] - '0';
+ }
+ else if( databytes_No[2] == '\r')
+ {
+ wind55_data_len = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0'));
+ }
+ else if( databytes_No[3] == '\r') //it's a 3-digit number
+ {
+ wind55_data_len = (((databytes_No[0] - '0') * 100 ) + ((databytes_No[1] - '0') * 10 ) + (databytes_No[2] - '0'));
+ }
+ else //it's a 4-digit number
+ {
+ wind55_data_len = ((databytes_No[0] - '0') * 1000 ) + ((databytes_No[1] - '0') * 100 ) + ((databytes_No[2] - '0') * 10) + (databytes_No[3] - '0');
+ }
+
+ event_s.data_length = wind55_data_len;
+ wind55_data_len = 0;
+ }
+ break;
+
+ case SockON_Server_Socket_Closed:
+ //Find the id of the socket closed
+ //ptr_offset = (char *) strstr((const char *)pStr,"+WIND:58");
+ databytes_No[0] = *(pStr + 22) ;
+ databytes_No[1] = *(pStr + 23) ;
+ if( databytes_No[1] == '\r')
+ {
+ remote_socket_closed_id = databytes_No[0] - '0';
+ }
+ else
+ {
+ remote_socket_closed_id = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0'));
+ }
+ event_s.socket_id = remote_socket_closed_id;
+ break;
+
+ case SockD_Pending_Data:
+ if(status_flag.prevent_push_WIFI_event)
+ {
+ #ifdef DEBUG_PRINT
+ printf(">>IG\r\n");
+ #endif
+ return; ///exit if push is prevented
+ }
+
+ /* @TODO: Do something to delay the de-Q of pending packets so that any further
+ pending WIND64 packets are allowed to arrive and get Q-ed */
+
+ if(status_flag.event_deQ_x_wind64) //which means there is already a previous WIND64
+ {
+ wind64_DQ_wait=0; //reset the timer
+ }
+ else
+ {
+ status_flag.stop_event_dequeue = WIFI_TRUE;//Stop the event de-Q
+ status_flag.event_deQ_x_wind64 = WIFI_TRUE;//Set the flag
+ }
+ //Start Reading data from Client Here.
+ // +WIND:64:Sockd Pending Data:1:130:130
+ ptr_offset = (char *) strstr((const char *)&process_buffer,"Data:");
+
+ //Store the packet number
+ databytes_No[0] = *(ptr_offset + 5) ;
+ event_s.wind64_pending_packet_no = databytes_No[0] - '0';
+
+ //And now find the data length
+ databytes_No[0] = *(ptr_offset + 8) ;//points to number just after 2nd colon
+ databytes_No[1] = *(ptr_offset + 9) ;
+ databytes_No[2] = *(ptr_offset + 10) ;
+ databytes_No[3] = *(ptr_offset + 11) ;
+
+ if( databytes_No[0] == ':')//then it is a 1 digit number
+ {
+ databytes_No[0] = *(ptr_offset + 7) ;
+ databytes_No[1] = *(ptr_offset + 8) ;
+ }
+ else if(databytes_No[1] == ':')//two digit number
+ {
+ databytes_No[0] = *(ptr_offset + 7) ;
+ databytes_No[1] = *(ptr_offset + 8) ;
+ databytes_No[2] = *(ptr_offset + 9) ;
+ //databytes_No[3] = *(ptr_offset + 13) ;
+ }
+ else if(databytes_No[2] == ':')//three digit number
+ {
+ databytes_No[0] = *(ptr_offset + 7) ;
+ databytes_No[1] = *(ptr_offset + 8) ;
+ databytes_No[2] = *(ptr_offset + 9) ;
+ databytes_No[3] = *(ptr_offset + 10) ;
+ }
+ else if(databytes_No[3] == ':')//four digit number
+ {
+ databytes_No[0] = *(ptr_offset + 7) ;
+ databytes_No[1] = *(ptr_offset + 8) ;
+ databytes_No[2] = *(ptr_offset + 9) ;
+ databytes_No[3] = *(ptr_offset + 10) ;
+ }
+
+ if( databytes_No[1] == ':')
+ {
+ interim_number_of_bytes = databytes_No[0] - '0';
+ }
+ else if( databytes_No[2] == ':')
+ {
+ interim_number_of_bytes = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0'));
+ }
+ else if( databytes_No[3] == ':')
+ {
+ interim_number_of_bytes = (((databytes_No[0] - '0') * 100 ) + ((databytes_No[1] - '0') * 10 ) + (databytes_No[2] - '0'));
+ }
+ else //it's a 4-digit number
+ {
+ interim_number_of_bytes = (((databytes_No[0] - '0') * 1000 ) + ((databytes_No[1] - '0') * 100 ) + ((databytes_No[2] - '0') * 10 ) + (databytes_No[3] - '0'));
+ }
+
+ if(WIND64_count >= 1) /*WIND:64 came after pop of previous event and switch to data mode was issued*/
+ /*WIND:64 came before pop of previous event and switch to data mode was issued*/
+ {
+ event_s.data_length = interim_number_of_bytes;// - (730*WIND64_count);
+ WIND64_count++; //Count of the number of queued WIND:64 Events
+ interim_number_of_bytes = 0;
+ break;
+ }
+ else
+ {
+ event_s.data_length = interim_number_of_bytes;
+ WIND64_count++; //Count of the number of queued WIND:64 Events
+ interim_number_of_bytes = 0;
+ }
+ break;
+
+ case In_Command_Mode:
+ status_flag.command_mode= WIFI_TRUE;
+ status_flag.data_mode= WIFI_FALSE;
+ WIND64_count=0; //reset the WIND64 count since the previous data mode would have consumed all data
+ break;
+
+ case In_Data_Mode:
+ status_flag.command_mode = WIFI_FALSE;
+ status_flag.data_mode = WIFI_TRUE;
+
+ if(status_flag.switch_by_default_to_command_mode == WIFI_TRUE)
+ {
+ if(!status_flag.command_mode)
+ {
+ WiFi_switch_to_command_mode();//switch by default
+ }
+ }
+ if(status_flag.data_pending_sockD == WIFI_TRUE)
+ {
+
+ process_buffer_index =5;
+ status_flag.enable_sock_read = WIFI_TRUE;//now data will start coming
+ //Set the data-length to read
+ SockON_Data_Length = number_of_bytes;
+ }
+ break;
+
+ case WiFi__MiniAP_Associated:
+ //Find out which client joined by parsing the WIND //+WIND:28
+ ptr_offset = (char *) strstr((const char *)&process_buffer,"+WIND:28");
+ for(i=17;i<=33;i++)
+ client_MAC_address[i-17] = *(ptr_offset + i) ;
+ WiFi_WIND_State.WiFiAPClientJoined = WIFI_TRUE;
+ break;
+
+ case WiFi_MiniAP_Disassociated:
+ //Find out which client left by parsing the WIND //+WIND:72
+ ptr_offset = (char *) strstr((const char *)&process_buffer,"+WIND:72");
+ for(i=17;i<=33;i++)
+ client_MAC_address[i-17] = *(ptr_offset + i) ;
+ WiFi_WIND_State.WiFiAPClientLeft = WIFI_TRUE;
+ break;
+
+ case Console_Active:
+ case Poweron :
+ case WiFi_Reset:
+ case Watchdog_Running:
+ case Heap_Too_Small:
+ case WiFi_Hardware_Dead:
+ case Watchdog_Terminating:
+ case SysTickConfigure:
+ case Hard_Fault:
+ case StackOverflow:
+ case MallocFailed:
+ case Error:
+ case WiFi_PS_Mode_Failure:
+ case CopyrightInfo:
+ case WiFi_BSS_Regained:
+ case WiFi_Signal_LOW:
+ case WiFi_Signal_OK:
+ case FW_update:
+ case Encryption_key_Not_Recognized:
+ case WiFi_Join:
+ case JOINFAILED:
+ case WiFi_Scanning:
+ case SCANBLEWUP:
+ case SCANFAILED:
+ case WiFi_Up:
+ case WiFi_Association_Successful:
+ case WiFi_Started_MiniAP_Mode:
+ case Start_Failed :
+ case WiFi_EXCEPTION :
+ case WiFi_Hardware_Started :
+ case WiFi_BSS_LOST:
+ case WiFi_Unhandled_Event:
+ case Scan_Complete:
+ case WiFi_UNHANDLED_IND:
+ case WiFi_UNHANDLED:
+ case WiFi_Powered_Down:
+ case WiFi_MiniAP_Mode :
+ case WiFi_Deauthentication:
+ case WiFi_Disassociation:
+ case RX_MGMT:
+ case RX_DATA:
+ case RX_UNK:
+ case DOT11_AUTHILLEGAL:
+ case Creating_PSK:
+ case WPA_Terminated :
+ case WPA_Supplicant_Failed:
+ case WPA_Handshake_Complete:
+ case GPIO_line:
+ case Wakeup:
+ case Factory_debug:
+ case Remote_Configuration:
+ break;
+ default:
+ break;
+ }
+ memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL);
+ }
+ }
+}
+
+/**
+* @brief Process_Dequeued_Wind_Indication
+* Process Wind Indication after popping from Queue
+* @param event_pop_s1 popped event contents
+* @retval None
+*/
+
+void Process_WiFi_Indication_Cmd(event_s_TypeDef * event_pop_s1)
+{
+ switch(event_pop_s1->wind)
+ {
+ case Console_Active:
+ WiFi_WIND_State.ConsoleActive = WIFI_TRUE;
+ break;
+ case Poweron :
+ WiFi_WIND_State.WiFiPowerON = WIFI_TRUE;
+ break;
+ case WiFi_Reset:
+ WiFi_WIND_State.WiFiReset = WIFI_TRUE;
+ break;
+ case Watchdog_Running:
+ break;
+ case Heap_Too_Small:
+ WiFi_WIND_State.HeapTooSmall=WIFI_TRUE;
+ break;
+ case WiFi_Hardware_Dead:
+ WiFi_WIND_State.WiFiHWFailure = WIFI_TRUE;
+ break;
+ case Watchdog_Terminating:
+ break;
+ case SysTickConfigure:
+ break;
+ case Hard_Fault:
+ WiFi_WIND_State.HardFault = WIFI_TRUE;
+ break;
+ case StackOverflow:
+ WiFi_WIND_State.StackOverflow = WIFI_TRUE;
+ break;
+ case MallocFailed:
+ WiFi_WIND_State.MallocFailed = WIFI_TRUE;
+ break;
+ case Error:
+ WiFi_WIND_State.InitFailure = WIFI_TRUE;
+ break;
+ case WiFi_PS_Mode_Failure:
+ WiFi_WIND_State.PS_Mode_Failure = WIFI_TRUE;
+ break;
+ case CopyrightInfo:
+ break;
+ case WiFi_BSS_Regained:
+ break;
+ case WiFi_Signal_LOW:
+ WiFi_WIND_State.WiFiSignalLOW = WIFI_TRUE;
+ break;
+ case WiFi_Signal_OK :
+ break;
+ case FW_update:
+ break;
+ case Encryption_key_Not_Recognized:
+ break;
+ case WiFi_Join :
+ WiFi_WIND_State.WiFiJoin = WIFI_TRUE;
+ break;
+ case JOINFAILED :
+ WiFi_WIND_State.WiFiJoinFailed = WIFI_TRUE;
+ break;
+ case WiFi_Scanning :
+ WiFi_WIND_State.WiFiScanning = WIFI_TRUE;
+ break;
+ case SCANBLEWUP:
+ WiFi_WIND_State.WiFiScanBlewUp = WIFI_TRUE;
+ break;
+ case SCANFAILED:
+ WiFi_WIND_State.WiFiScanFailed = WIFI_TRUE;
+ break;
+ case WiFi_Up:
+ WiFi_WIND_State.WiFiUp = WIFI_TRUE;
+ break;
+ case WiFi_Association_Successful:
+ WiFi_WIND_State.WiFiAssociation = WIFI_TRUE;
+ break;
+ case WiFi_Started_MiniAP_Mode:
+ WiFi_WIND_State.WiFiStarted_MiniAPMode = WIFI_TRUE;
+ break;
+ case Start_Failed :
+ WiFi_WIND_State.StartFailed = WIFI_TRUE;
+ break;
+ case WiFi_EXCEPTION :
+ WiFi_WIND_State.WiFiException = WIFI_TRUE;
+ break;
+ case WiFi_Hardware_Started :
+ wifi_ready++;
+ status_flag.WiFi_Enabled = WIFI_TRUE;
+ WiFi_WIND_State.WiFiHWStarted = WIFI_TRUE;
+ /*If this is a start-up after standby*/
+ if(status_flag.trigger_wakeup_callback == WIFI_TRUE)
+ {
+ status_flag.trigger_wakeup_callback = WIFI_FALSE;
+ status_flag.Standby_Enabled = WIFI_FALSE;
+ status_flag.standby_resume_callback = WIFI_TRUE;
+ }
+ break;
+ case WiFi_BSS_LOST:
+ break;
+ case WiFi_Unhandled_Event:
+ break;
+ case Scan_Complete:
+ WiFi_WIND_State.WiFiScanComplete = WIFI_TRUE;
+ status_flag.Scan_Ongoing = WIFI_FALSE;
+ break;
+ case WiFi_UNHANDLED_IND:
+ WiFi_WIND_State.WiFiUnHandledInd = WIFI_TRUE;
+ break;
+ case WiFi_UNHANDLED:
+ break;
+ case WiFi_Powered_Down:
+ status_flag.WiFi_Enabled = WIFI_FALSE;
+ //wifi_ready = 0;
+ WiFi_WIND_State.WiFiHWStarted = WIFI_FALSE;
+ WiFi_WIND_State.WiFiPowerDown = WIFI_TRUE;
+ break;
+ case WiFi_MiniAP_Mode :
+ WiFi_WIND_State.WiFiMiniAPMode = WIFI_TRUE;
+ break;
+ case WiFi_Deauthentication:
+ WiFi_WIND_State.WiFiDeauthentication = WIFI_TRUE;
+ break;
+ case WiFi_Disassociation:
+ WiFi_WIND_State.WiFiDisAssociation = WIFI_TRUE;
+ break;
+ case RX_MGMT:
+ WiFi_WIND_State.WiFiRXMgmt = WIFI_TRUE;
+ break;
+ case RX_DATA:
+ WiFi_WIND_State.WiFiRXData = WIFI_TRUE;
+ break;
+ case RX_UNK:
+ WiFi_WIND_State.WiFiRxUnk = WIFI_TRUE;
+ break;
+ case DOT11_AUTHILLEGAL:
+ break;
+ case Creating_PSK:
+ break;
+ case WPA_Terminated :
+ break;
+ case WPA_Supplicant_Failed:
+ break;
+ case WPA_Handshake_Complete:
+ break;
+ case GPIO_line:
+ break;
+ case Wakeup:
+ break;
+ case Factory_debug:
+ break;
+
+ case SockON_Data_Pending:
+
+ /* +WIND:55:Pending Data:%d:%d */
+ if (status_flag.enable_sock_read == WIFI_TRUE)
+ {
+ #if DEBUG_PRINT
+ printf ("\nAlert!\r\n");
+ #endif
+ status_flag.enable_sock_read = WIFI_FALSE;
+ status_flag.enable_receive_data_chunk = WIFI_FALSE;
+ //break;
+ }
+ sockon_query_id = event_pop_s1->socket_id;
+ if(open_sockets[sockon_query_id])
+ {
+ status_flag.enable_query = WIFI_TRUE;
+ status_flag.stop_event_dequeue = WIFI_TRUE;
+ }
+
+ break;
+
+ case SockON_Server_Socket_Closed:
+ client_socket_close_id = event_pop_s1->socket_id;
+ status_flag.Client_Socket_Close_Cmd = WIFI_TRUE;
+ break;
+
+ case SockD_Pending_Data:
+ number_of_bytes = event_pop_s1->data_length;
+ status_flag.data_pending_sockD = WIFI_TRUE;
+ status_flag.stop_event_dequeue = WIFI_TRUE; //Stop any more event de-queue
+ status_flag.enable_receive_data_chunk = WIFI_TRUE; // read data in chunk now from ring buffer
+
+ if(!status_flag.data_mode)
+ {
+ if(event_pop_s1->wind64_pending_packet_no == 1) { //If this is the first WIND64 pending event de-Q'ed
+ status_flag.switch_by_default_to_command_mode = WIFI_FALSE; //we don't want to switch back to command mode after changing to data mode here
+ WiFi_switch_to_data_mode(); //switch by default
+ }
+ }
+ else //already data is coming from previous WIND:64
+ {
+ process_buffer_index =5;
+ status_flag.enable_sock_read = WIFI_TRUE;//n
+ SockON_Data_Length = number_of_bytes;
+ }
+ break;
+
+ case Incoming_socket_client:
+ status_flag.Client_Connected = WIFI_TRUE;
+ wifi_client_connected=1; //Set this so that the callback can be made to the user
+ break;
+
+ case Outgoing_socket_client:
+ status_flag.Client_Disconnected = WIFI_TRUE;
+ wifi_client_disconnected=0;//Set this so that the callback can be made to the user
+ wifi_client_connected = 0;
+ break;
+
+ case SockD_Dropping_Data:
+ WiFi_WIND_State.WiFiSockdDataLost = WIFI_TRUE;
+ break;
+
+ case Low_Power_Mode_Enabled:
+ status_flag.Low_Power_Enabled = WIFI_TRUE;
+ break;
+
+ case Going_Into_Standby:
+ status_flag.Standby_Enabled = WIFI_TRUE;
+ break;
+
+ case Resuming_From_Standby:
+ status_flag.Standby_Enabled = WIFI_FALSE;
+ status_flag.standby_resume_callback = WIFI_TRUE;
+ break;
+ case Going_Into_DeepSleep:
+ status_flag.Deep_Sleep_Enabled = WIFI_TRUE;
+ break;
+ case Resuming_From_DeepSleep:
+ status_flag.Deep_Sleep_Enabled = WIFI_FALSE;
+ Start_DeepSleep_Timer();
+ break;
+ default:
+ break;
+ }
+}
+
+/**
+* @brief Queue_Http_Get_ Event
+* Queue an HTTP-Request Event (GET/POST)
+* @param hostname hostname for HTTP-GET/POST
+* @param path path for HTTP-GET
+* @param port_number port_number for HTTP-GET
+* @param pURL_path full URL for HTTP-POST
+* @retval None
+*/
+
+void Queue_Http_Event(uint8_t * hostname, uint8_t * path, uint32_t port_number, uint8_t * pURL_path)
+{
+ Wait_For_Sock_Read_To_Complete();
+ if(pURL_path == NULL)
+ {
+ curr_hostname = hostname;
+ curr_path = path;
+ curr_port_number = port_number;
+ }
+ else
+ curr_pURL = pURL_path;
+
+ event_s.event = WIFI_HTTP_EVENT;
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+
+ reset_event(&event_s);
+}
+
+/**
+* @brief Queue_Client_Write_Event
+* Queues a Client Socket write event.
+* @param sock_id socket ID to write to
+* @param DataLength length of the data to be written
+* @param pData pointer to data
+* @retval None
+*/
+void Queue_Client_Write_Event(uint8_t sock_id, uint16_t DataLength, char * pData)
+{
+ Wait_For_Sock_Read_To_Complete();
+ curr_DataLength = DataLength;
+ curr_data = pData;
+ curr_sockID = sock_id;
+ status_flag.enable_client_socket_write = WIFI_TRUE;
+
+ event_s.event = WIFI_CLIENT_SOCKET_WRITE_EVENT;
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+
+ reset_event(&event_s);
+}
+
+/**
+* @brief Queue_Wifi_File_Image_Create_Event
+* Queue a File Image Create Event
+* @param pHostName hostname
+* @param pFileName filename within host
+* @param port_number port number to connect to
+* @retval None
+*/
+void Queue_Wifi_File_Event(uint8_t * pHostName, uint8_t * pFileName, uint32_t port_number)
+{
+ Wait_For_Sock_Read_To_Complete();
+ event_s.event = WIFI_FILE_EVENT;
+ curr_filename = pFileName;
+ curr_hostname = pHostName;
+ curr_port_number = port_number;
+
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+
+ reset_event(&event_s);
+}
+
+/**
+* @brief Queue_Wifi_FW_Update_Event
+* Queue a Firmware update Event
+* @param hostname hostname
+* @param filename_path filename and path within host
+* @param port_number port number to connect to
+* @retval None
+*/
+void Queue_Wifi_FW_Update_Event(uint8_t * hostname, uint8_t * filename_path, uint32_t port_number)
+{
+ Wait_For_Sock_Read_To_Complete();
+ event_s.event = WIFI_FW_UPDATE_EVENT;
+ curr_filename = filename_path;
+ curr_hostname = hostname;
+ curr_port_number = port_number;
+
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+
+ reset_event(&event_s);
+}
+
+void Queue_Client_Open_Event(uint8_t * hostname, uint32_t port_number, uint8_t * protocol)
+{
+ Wait_For_Sock_Read_To_Complete();
+ curr_hostname = hostname;
+ curr_port_number = port_number;
+ curr_protocol = protocol;
+
+ event_s.event = WIFI_CLIENT_SOCKET_OPEN_EVENT;
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+
+ reset_event(&event_s);
+}
+
+void Queue_Client_Close_Event(uint8_t sock_id)
+{
+ Wait_For_Sock_Read_To_Complete();
+
+ event_s.event = WIFI_CLIENT_SOCKET_CLOSE_EVENT;
+ event_s.socket_id = sock_id;
+ __disable_irq();
+ push_eventbuffer(&event_buff, event_s);
+ __enable_irq();
+
+ reset_event(&event_s);
+}
+
+/**
+* @brief Wait_For_Sock_Read_To_Complete
+* Wait till sock is over and the OK of read arrives
+* @param None
+* @retval None
+*/
+void Wait_For_Sock_Read_To_Complete(void)
+{
+ //wait if read is ongoing or read OK is yet to arrive
+ while(status_flag.sock_read_ongoing==WIFI_TRUE || status_flag.prevent_push_OK_event==WIFI_TRUE)
+ {
+ asm("NOP");
+ }
+}
+
+/**
+* @brief Reset_AT_CMD_Buffer
+* Clear USART2 Rx buffer and Wi-Fi AT cmd buffer
+* @param None
+* @retval None
+*/
+void Reset_AT_CMD_Buffer()
+{
+ memset(WiFi_AT_Cmd_Buff, 0x00, sizeof WiFi_AT_Cmd_Buff);
+}
+
+#ifdef USE_FULL_ASSERT
+
+/**
+* @brief Reports the name of the source file and the source line number
+* where the assert_param error has occurred.
+* @param file: pointer to the source file name
+* @param line: assert_param error line source number
+* @retval None
+*/
+void assert_failed(uint8_t* file, uint32_t line)
+{
+ /* User can add his own implementation to report the file name and line number,
+ ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
+
+ /* Infinite loop */
+ while (1)
+ {
+ }
+}
+
+#endif
+
+
+/**
+* @brief search_buffer
+* search for substring in a buffer that contains null
+* @param pSourceBuff : pointer of source buffer
+* sourceBuffLen : length of string buffer
+* pSearchStringBuff : pointer of search string buffer
+* seartchStringLen : length of search string buffer
+* @retval pointer of source buffer
+*/
+char *search_buffer(char *pSourceBuff, uint16_t sourceBuffLen, char *pSearchStringBuff, uint16_t seartchStringLen)
+{ /* warning: O(n^2) */
+ int searchlen = sourceBuffLen - seartchStringLen + 1;
+ for ( ; searchlen-- > 0; pSourceBuff++)
+ if (!memcmp(pSourceBuff, pSearchStringBuff, seartchStringLen))
+ return pSourceBuff;
+ return NULL;
+}
+
+/**
+* @brief Delete_Colon
+* delete colon from input buffer
+* @param input : pointer of input buffer
+* @retval return pointer of updated buffer
+*/
+char* Delete_Colon(char* input)
+{
+ int i,j;
+ char *output=input;
+
+ /* Delete Colon */
+ for (i = 0, j = 0; i<strlen(input); i++,j++)
+ {
+#if 0
+ if (input[i]!=':') && (input[i]!='\r')&& (input[i]!='\n')&& (input[i]!='O')&& (input[i]!='K'))
+ output[j]=input[i];
+ else
+ j--;
+#else
+ if ((input[i] ==':') || (input[i]=='\r')|| (input[i]=='\n')|| (input[i]=='O')|| (input[i]=='K'))
+ j--;
+ else
+ output[j]=input[i];
+ }
+ //output[j]=NULL;
+#endif
+ return output;
+}
+
+/**
+* @brief Read_WiFi_SSID
+* Read SSID of WiFi module store in flash
+* @param string : pointer of SSID
+* @retval return status of AT cmd request
+*/
+WiFi_Status_t Read_WiFi_SSID(char *string)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ char * ssid = "wifi_ssid";
+ char * pStr;
+ /* AT+S.GCFG=wifi_ssid read SSID */
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,ssid);
+
+ /*
+ Response :
+ # wifi_ssid = 41:6E:53:53:49:44:00:00:00:00:00:00:00:00:00:00:00:00:00:
+ 00:00:00:00:00:00:00:00:00:00:00:00:00<cr><lf>
+ <cr><lf>OK<cr><lf>
+ */
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+
+ /* find a substring (# wifi_ssid = )inside a USART2_RxBuffer that may contain nulls */
+ uint16_t sourceBuffLen = sizeof(get_cfg_value)-1; /* exclude null terminator from length */
+ char searchStringBuff[] = "# wifi_ssid = ";
+ uint16_t stringBuffLen = sizeof(searchStringBuff)-1; /* exclude null terminator from length */
+ char *res = search_buffer((char *)&get_cfg_value, sourceBuffLen, searchStringBuff, stringBuffLen);
+
+ pStr = (char *) (strstr((const char *)res,"= "));
+ if(pStr != NULL)
+ {
+ strcat( string, (pStr + 2));
+ /* Remove colon,\r,\n,OK strings */
+ memcpy(string, Delete_Colon(string) , 32);
+ }
+ return status;
+}
+
+/**
+* @brief Read_WiFi_SecKey
+* Read Security key of WiFi module store in flash
+* @param string : pointer of Security key
+* @retval return status of AT cmd request
+*/
+WiFi_Status_t Read_WiFi_SecKey(char *string)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ char *seckey = "wifi_wpa_psk_text";
+ char *pStr;
+
+ /* AT+S.GCFG=wifi_ssid read SSID */
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,seckey);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+
+
+ /* find a substring (wifi_wpa_psk_text = )inside a USART2_RxBuffer that may contain nulls */
+ uint16_t sourceBuffLen = sizeof(get_cfg_value)-1; /* exclude null terminator from length */
+ char searchStringBuff[] = "wifi_wpa_psk_text = ";
+ uint16_t stringBuffLen = sizeof(searchStringBuff)-1; /* exclude null terminator from length */
+ char *res = search_buffer((char *)&get_cfg_value, sourceBuffLen, searchStringBuff, stringBuffLen);
+
+ pStr = (char *) (strstr((const char *)res,"= "));
+ if(pStr != NULL)
+ {
+ strcat( string, (pStr + 2));
+ /* Remove colon,\r,\n,OK strings */
+ memcpy(string, Delete_Colon(string) , 32);
+ }
+
+ return status;
+}
+
+/**
+* @brief Read_WiFi_Mode
+* Read Wi-Fi mode 0: idle,1 =STA,2 =IBSS,3 =MiniAP
+* @param string : return wifi mode type
+* @retval return status of AT cmd request
+*/
+WiFi_Status_t Read_WiFi_Mode(char *string)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ char *mode = "wifi_mode";
+ char *pStr;
+
+ /* AT+S.GCFG=wifi_mode */
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,mode);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+
+ pStr = (char *) strstr((const char *)&get_cfg_value,"wifi_mode = ");
+ if(pStr != NULL)
+ {
+ string[0] = *(pStr + 12) ;
+ }
+
+ return status ;
+}
+
+/**
+* @brief Write_WiFi_SSID
+* Store SSID in flash memory of WiFi module
+* @param string : pointer of SSID
+* @retval return status of AT cmd request
+*/
+WiFi_Status_t Write_WiFi_SSID(char *string)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ Reset_AT_CMD_Buffer();
+
+ /* AT+S.SSIDTXT=abcd <ExampleSSID> //set SSID */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_SSID,string);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+
+ /* AT&W :Save the settings on the flash memory */
+ Reset_AT_CMD_Buffer();
+ Save_Current_Setting();
+
+ return status;
+
+}
+
+
+/**
+* @brief Write_WiFi_SecKey
+* Store security key in flash memory of WiFi module
+* @param string : pointer of security key
+* @retval return status of AT cmd request
+*/
+WiFi_Status_t Write_WiFi_SecKey(char *string)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ Reset_AT_CMD_Buffer();
+
+ /* AT+S.SCFG=wifi_wpa_psk_text,helloworld : set password */
+ sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.SCFG=wifi_wpa_psk_text,%s\r",string);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+
+ /* AT&W :Save the settings on the flash memory */
+ Reset_AT_CMD_Buffer();
+ Save_Current_Setting();
+
+ return status;
+}
+
+
+
+/**
+* @brief PrintErrorMsg
+* Print error message on UART terminal
+* @param None
+* @retval None
+*/
+void PrintErrorMsg (void)
+{
+ Print_Msg("error in AT cmd",sizeof("error in AT cmd"));
+}
+
+/**
+ * @brief Print_Msg
+ * Print messages on UART terminal
+ * @param msgBuff : Contains data that need to be print
+ * @param length : leghth of the data
+ * @retval None
+ */
+void Print_Msg(char * msgBuff,uint8_t length)
+{
+
+}
+
+/**
+* @brief Error_Handler
+* This function is executed in case of error occurrence.
+* @param None
+* @retval None
+*/
+void Error_Handler(void)
+{
+ /* Turn LED2 on */
+ //BSP_LED_On(LED2);
+ //The following while(1) is commented as it prevents standby functionality
+ /*while(1)
+ {
+ //Error if LED2 is slowly blinking (1 sec. period)
+ BSP_LED_Toggle(LED2);
+ HAL_Delay(1000);
+ } */
+ Receive_Data();
+}
+
+
+/**
+* @brief Start_DeepSleep_Timer
+* start the deep sleep timer.
+* @param None
+* @retval void
+*/
+void Start_DeepSleep_Timer(void)
+{
+ status_flag.Deep_Sleep_Timer = WIFI_TRUE;
+ sleep_count = 0;
+}
+
+/**
+* @brief Stop_DeepSleep_Timer
+* stop the deep sleep timer.
+* @param None
+* @retval void
+*/
+void Stop_DeepSleep_Timer()
+{
+ status_flag.Deep_Sleep_Timer = WIFI_FALSE;
+ sleep_count = 0;
+}
+
+#if 0
+/**
+* @brief configure_to_exti
+* Configured the USART Rx pin to EXTI pin to capture standby wakeup interrupt
+* @param None
+* @retval None
+*/
+void configure_to_exti()
+{
+ /*configure the pin*/
+
+ HAL_NVIC_DisableIRQ(USARTx_IRQn);//Disable UART IRQ
+
+ /* USART_RX Pin as EXTI IRQ*/
+ GPIO_InitTypeDef GPIO_InitStruct;
+ GPIO_InitStruct.Pin = WiFi_USART_RX_PIN;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+#if defined (USE_STM32L0XX_NUCLEO) || (USE_STM32F4XX_NUCLEO)
+ GPIO_InitStruct.Alternate = 0;
+#endif
+ HAL_GPIO_Init(WiFi_USART_RX_GPIO_PORT, &GPIO_InitStruct);
+
+ /* Configure the NVIC for EXTI */
+ HAL_NVIC_SetPriority(USARTx_EXTI_IRQn, 3, 0);
+ HAL_NVIC_EnableIRQ(USARTx_EXTI_IRQn);
+}
+#endif
+
+/**
+* @brief WiFi_switch_to_command_mode
+* switch to command mode from data mode
+* @param None
+* @retval None
+*/
+void WiFi_switch_to_command_mode(void)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ /* AT+S.*/
+ Reset_AT_CMD_Buffer();
+
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_DATA_TO_CMD_MODE); //Notice the lower case
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ //nothing to do
+ }
+}
+
+
+/**
+* @brief WiFi_switch_to_data_mode
+* switch to data mode from command mode
+* @param None
+* @retval None
+*/
+void WiFi_switch_to_data_mode(void)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ /* AT+S.*/
+ Reset_AT_CMD_Buffer();
+
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_CMD_TO_DATA_MODE); //Notice the upper case
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ //nothing to do
+ }
+
+}
+
+
+/**
+* @brief Attention_Cmd
+* Attention command
+* @param None
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t Attention_Cmd()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_ATTENTION);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+}
+
+
+/**
+* @brief SET_Power_State
+* SET power mode of wifi module
+* @param state : power mode of wi-fi module i.e active,sleep,standby,powersave
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t SET_Power_State(WiFi_Power_State_t state)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+#if DEBUG_PRINT
+ printf("\r\n >>Soft Reset Wi-Fi module\r\n");
+#endif
+
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_POWER_STATE,state);
+// WiFi_Module_State = Process_Event;
+// WiFi_WIND_State.WiFiReset = WIFI_FALSE;
+ WiFi_WIND_State.WiFiHWStarted = WIFI_FALSE;
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status != WiFi_MODULE_SUCCESS)
+ return status;
+ memset((void*)&WiFi_WIND_State,0x00,sizeof(WiFi_WIND_State)); /*reset the WIND State?*/
+ /* AT+CFUN=1 //Soft reset */
+ while(WiFi_WIND_State.WiFiHWStarted != WIFI_TRUE)
+ {
+ asm("NOP");
+ }
+ return status;
+}
+
+
+/**
+* @brief Display_Help_Text
+* this function will print a list of all commands supported with a brief help text for each cmd
+* @param None
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t Display_Help_Text()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_HELP_TEXT);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+}
+
+/**
+* @brief WiFi_Get_IP_address
+* Get the ip address
+* @param ip_addr : pointer to ip address
+* @retval status : status of AT cmd request
+*/
+
+WiFi_Status_t WiFi_Get_IP_Address(uint8_t *ip_addr)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ int cfg_value_length, i;
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_STATUS_VALUE,"ip_ipaddr");
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ cfg_value_length = strlen((const char*)get_cfg_value);
+
+ //Optimise the following loop??
+ for(i=7; i<=16; i++)//0th index is always ' ' which we ignore
+ if(get_cfg_value[i] == '\r')//find the first '\r'
+ {
+ get_cfg_value[i] = '\0'; //Terminate the string by NULL
+ break;
+ }
+
+ /* copy user pointer to get_cfg_value */
+ memcpy(ip_addr,&get_cfg_value[1],i);//IP address will have max lenght fixed at 16 bytes (null terminated included).
+ memset(get_cfg_value, 0x00,cfg_value_length);
+ }
+ return status;
+}
+
+/**
+* @brief WiFi_Get_MAC_address
+* Get the MAC address
+* @param ip_addr : pointer to MAC address
+* @retval status : status of AT cmd request
+*/
+
+WiFi_Status_t WiFi_Get_MAC_Address(uint8_t *mac_addr)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ int cfg_value_length;
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,"nv_wifi_macaddr");
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ cfg_value_length = strlen((const char*)get_cfg_value);
+ get_cfg_value[18] = '\0';//Terminate by NULL
+ /* copy user pointer to get_cfg_value */
+ memcpy(mac_addr,&get_cfg_value[1],18);//IP address will have max lenght fixed at 18 bytes.
+ memset(get_cfg_value, 0x00,cfg_value_length);
+ }
+ return status;
+}
+
+/**
+* @brief GET_Configuration_Value
+* Get a wifi configuration value from the module
+* @param sVar_name : Name of the config variable
+* aValue : value of config variable to be returned to user
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t GET_Configuration_Value(char* sVar_name,uint32_t *aValue)
+{
+ int cfg_value_length;
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,sVar_name);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ cfg_value_length = strlen((const char*)get_cfg_value);
+ memcpy(aValue,get_cfg_value,cfg_value_length); //copy user pointer to get_cfg_value
+ memset(get_cfg_value, 0x00,cfg_value_length);
+ }
+ return status;
+}
+
+/**
+* @brief SET_Configuration_Addr
+* Get a wifi configuration address from the module
+* @param sVar_name : Name of the config variable
+* addr : value of config address to be returned to user
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t SET_Configuration_Addr(char* sVar_name,char* addr)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_CONFIGURATION_ADDRESS,sVar_name,addr);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+}
+
+/**
+* @brief SET_Configuration_Value
+* SET the value of configuration variable
+* @param sVar_name : Name of the config variable
+* aValue : value of config variable
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t SET_Configuration_Value(char* sVar_name,uint32_t aValue)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ Reset_AT_CMD_Buffer();
+
+ /* AT : send AT command */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_CONFIGURATION_VALUE,sVar_name,(int)aValue);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+}
+
+/**
+* @brief SET_SSID
+* SET SSID in flash memory of Wi-Fi module
+* @param ssid : pointer of SSID
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t SET_SSID(char* ssid)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ Reset_AT_CMD_Buffer();
+
+ /* AT+S.SSIDTXT=abcd <ExampleSSID> */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_SSID,ssid);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+}
+
+
+/**
+* @brief SET_WiFi_SecKey
+* SET wifi security key
+* @param seckey : pointer of security key
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t SET_WiFi_SecKey(char* seckey)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ Reset_AT_CMD_Buffer();
+
+ /* AT+S.SCFG=wifi_wpa_psk_text,helloworld : set password */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_SEC_KEY,seckey);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+}
+
+
+/**
+* @brief Restore_Default_Setting
+* Restore the factory default values of the configuration variables
+* and writes them to non volatile storage
+* @param None
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t Restore_Default_Setting()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ //Reset_AT_CMD_Buffer();
+
+ /* AT&F: restore default setting */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_RESTORE_DEFAULT_SETTING);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+
+}
+
+/**
+* @brief Save_Current_Setting
+* Store the current RAM-based setting to non-volatile storage
+* @param None
+* @retval WiFi_Status_t : status of AT cmd Request
+*/
+WiFi_Status_t Save_Current_Setting()
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ Reset_AT_CMD_Buffer();
+
+ /* AT&W :Save the settings on the flash memory */
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SAVE_CURRENT_SETTING);
+
+ status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
+ if(status == WiFi_MODULE_SUCCESS)
+ {
+ status = USART_Receive_AT_Resp(Process_Event);
+ }
+ return status;
+}
+
+
+/**
+* @brief ResetBuffer
+* Reset receive data/indication msg buffer
+* @param None
+* @retval None
+*/
+void ResetBuffer()
+{
+
+}
+
+
+/**
+* @brief config_init_value
+* initalize config values before reset
+* @param sVar_name : Name of the config variable
+* aValue : value of config variable
+* @retval None
+*/
+WiFi_Status_t config_init_value(char* sVar_name,uint8_t aValue)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_CONFIGURATION_VALUE,sVar_name,aValue);
+ /*if(HAL_UART_Transmit(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, strlen((char*)WiFi_AT_Cmd_Buff),1000)!= HAL_OK)
+ {
+ Error_Handler();
+ return WiFi_HAL_UART_ERROR;
+ }*/
+
+ status = WaitForResponse(AT_RESP_LEN_OK);
+ return status;
+}
+
+/**
+* @brief config_init_addr
+* initalize config strings/addresses before reset
+* @param sVar_name : Name of the config variable
+* addr : value of config address to be returned to user
+* @retval None
+*/
+WiFi_Status_t config_init_addr(char* sVar_name,char* addr)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+ Reset_AT_CMD_Buffer();
+ sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_CONFIGURATION_ADDRESS,sVar_name,addr);
+ /*if(HAL_UART_Transmit(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, strlen((char*)WiFi_AT_Cmd_Buff),1000)!= HAL_OK)
+ {
+ Error_Handler();
+ return WiFi_HAL_UART_ERROR;
+ }*/
+
+ status = WaitForResponse(AT_RESP_LEN_OK);
+ return status;
+
+}
+
+
+/**
+* @brief WaitForResponse
+* Wait for OK response
+* @param alength length of the data to be received
+* @retval None
+*/
+WiFi_Status_t WaitForResponse(uint16_t alength)
+{
+ WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+
+ if(alength <= RxBufferSize)
+ {
+ /*if(HAL_UART_Receive(&UartWiFiHandle, (uint8_t *)USART_RxBuffer, alength,5000)!= HAL_OK)
+ {
+ Error_Handler();
+ return WiFi_HAL_UART_ERROR;
+ }*/
+
+ if(((strstr((const char *)&USART_RxBuffer,"OK"))) == NULL)
+ {
+ return WiFi_AT_CMD_RESP_ERROR;
+ }
+
+ }
+
+ return status;
+}
+/**** Wi-Fi indication call back *************/
+__weak void ind_wifi_warning(WiFi_Status_t warning_code)
+{
+}
+
+__weak void ind_wifi_error(WiFi_Status_t error_code)
+{
+}
+
+__weak void ind_wifi_connection_error(WiFi_Status_t status_code)
+{
+}
+
+__weak void ind_wifi_connected(void)
+{
+}
+
+__weak void ind_wifi_ap_ready(void)
+{
+}
+
+__weak void ind_wifi_ap_client_joined(uint8_t * client_mac_address)
+{
+}
+
+__weak void ind_wifi_ap_client_left(uint8_t * client_mac_address)
+{
+}
+
+__weak void ind_wifi_on(void)
+{
+}
+
+__weak void ind_wifi_packet_lost(WiFi_Status_t status_code)
+{
+}
+
+__weak void ind_wifi_gpio_changed(void)
+{
+}
+
+__weak void ind_wifi_socket_data_received(uint8_t socket_id, uint8_t * data_ptr, uint32_t message_size, uint32_t chunk_size)
+{
+}
+
+__weak void ind_wifi_socket_client_remote_server_closed(uint8_t * socketID)
+{
+}
+
+__weak void ind_wifi_socket_server_data_lost(void)
+{
+}
+
+__weak void ind_socket_server_client_joined(void)
+{
+}
+
+__weak void ind_socket_server_client_left(void)
+{
+}
+
+__weak void ind_wifi_http_data_available(uint8_t * data_ptr,uint32_t message_size)
+{
+}
+
+__weak void ind_wifi_file_data_available(uint8_t * data_ptr)
+{
+}
+__weak void ind_wifi_resuming(void)
+{
+}
+
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Apr 08 12:07:17 2016 +0000
@@ -0,0 +1,89 @@
+#include "mbed.h"
+#include "SPWFInterface.h"
+#include "TCPSocket.h"
+
+//------------------------------------
+// Hyperterminal configuration
+// 9600 bauds, 8-bit data, no parity
+//------------------------------------
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+DigitalOut myled(LED1);
+
+SpwfSAInterface *spwf;
+TCPSocket *tcp_;
+
+int main() {
+ int32_t err;
+ char * ssid = "STM";
+ char * seckey = "STMdemoPWD";
+ char * hostname = "192.168.1.5";
+ char * data = "Hello World!\r\n";
+ uint32_t len = strlen(data);
+
+ pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
+
+ spwf = createSPWFInstance();
+ tcp_ = new TCPSocket(spwf);
+
+ err = spwf->init();
+ if(err!=0)
+ {
+ pc.printf("\r\n[APP] error initializing.\r\n");
+ return -1;
+ }
+
+ pc.printf("\r\n[APP] connecting to AP\r\n");
+
+ err = spwf->connect(ssid, seckey, NS_SECURITY_WPA);
+ if(err!=0)
+ {
+ pc.printf("\r\n[APP] error connecting to AP.\r\n");
+ return -1;
+ }
+
+ pc.printf("\r\n[APP] now connected\r\n");
+
+ const char *ip = spwf->getIPAddress();
+ const char *mac = spwf->getMACAddress();
+
+ pc.printf("\r\n[APP] IP Address is: %s\r\n", (ip) ? ip : "No IP");
+ pc.printf("\r\n[APP] MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
+
+ pc.printf("\r\n[APP] opening socket\r\n");
+
+ err = tcp_->open((const char *)hostname, 32000);
+ //err = tcp_->open("time-d.nist.gov", 37);
+
+ if(err==0)
+ {
+ pc.printf("\r\n[APP] socket open OK\r\n");
+ pc.printf("\r\n[APP] hostname resolved to: %s\r\n", tcp_->getIPAddress());
+
+ err = tcp_->send(data, len);
+
+ if(err == 0)
+ pc.printf("\r\n[APP] socket send OK\r\n");
+ else
+ pc.printf("\r\n[APP] socket send error\r\n");
+
+ char received[4];
+ int32_t size = 0;
+ pc.printf("\r\n[APP] waiting for data recv\r\n");
+ size = tcp_->recv(received, sizeof(received));
+ if(size==-1)
+ pc.printf("\r\n[APP] Receive error.");
+ else
+ pc.printf("\r\n[APP] Received: %ld bytes, 0x%02x 0x%02x 0x%02x 0x%02x\r\n", size, received[0], received[1], received[2], received[3]);
+ }
+ else
+ pc.printf("\r\n[APP] socket open Error\r\n");
+
+ while(1) {
+ wait(1);
+ //pc.printf("This program runs since %d seconds.\n", i++);
+ myled = !myled;
+ }
+}
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src-hwflw.lib Fri Apr 08 12:07:17 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/mridup/code/mbed-src-hwflw/#1b0c4e3233d7