Port from Avnet's Internet Of Things full WiGo demo: SmartConfig - WebServer - Exosite - Android sensor Fusion App

Dependencies:   NVIC_set_all_priorities mbed cc3000_hostdriver_mbedsocket TEMT6200 TSI Wi-Go_eCompass_Lib_V3 WiGo_BattCharger

Wi-Go Reference Design Overview


For additional information on Wi-Go, please visit http://www.em.avnet.com/wi-go
For additional information on Freescale eCompass, please visit
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=E-Compass
Ported from Avnet's Wi-Go KEIL code.
Special thanks to Jim Carver from Avnet for providing the Wi-Go board and for his assistance.


Multiple Wi-Fi applications are provided within the latest version of Wi-Go software:

  • SmartConfig App for auto-setup of Wi-Go network parameters.
  • WebServer display of live sensor data.
  • Exosite portal sensor data feed by Wi-Go.
  • Freescale's Sensor Fusion App data feed by Wi-Go.

Wi-Go is intended for "untethered" portable operation (using it's high-capacity Lithium-Polymer battery). The serial terminal text interface is only required for initial setup, thereafter selection of an application from those available is via finger position on the Touch Slider during the initial 6 second startup period.

Running the Wi-Go Demo Suite

Warning

The on-board Firmware must be updated to mbed enable a Wi-Go system.
Goto the Component page to get the FirmwareUpdate tool (scroll down to the FirmwareUpdate topic).

MAG3110 sensor and eCompass Calibration!

As with the other sensor applications, the eCompass function requires quality calibration data to achieve best accuracy.
For the first 15 seconds after power-up it is recommended that "Figure 8" movements with Wi-Go be done in a smooth, repetitive pattern. Don't touch the slider pad during calibration.

Startup
The RGB LED blinks in a GREEN-ORANGE sequence to inform the user the module is waiting for input.
The RGB LED color designates which of the following Apps to launch.

RGB LED ColorApplication to Launch
OrangeErase all wireless profiles
PurpleSmartConfig
BlueWebServer
RedExosite Data Client
GreenAndroid Server

Swipe your index finger across the slider pad, the RGB LED color will change at approximately 20% intervals.
Removing your finger latches the last color displayed. After about 3 seconds, the selected app will start.
Another app can be selected when the slider pad is touched again within the 3 seconds timeout.

After launch of Exosite or Android Server Apps, the eCompass function then controls the RGB LED.
(not in WebServer mode where RGB LEDs are manually controlled by the User).

RGB LED ColorDirection Indication
BlueNear to North
GreenNorth
RedEast / West
PurpleSouth

__Note!__ The D1, D2 and D3 User LEDs on Wi-Go adhere to the following convention for the different Apps

User LED#Description of function controlling the LED
D1is the board heartbeat, derived from the timer interrupt
D2indicates network activity as follows:
Web Server Wi-Go webpage is being served.
Exosite Client Wi-Go is sending data.
Android App Wi-Go is sending data
D3WLAN Network is Connected

Detail of Wi-Go Applications

App #1: SmartConfig
See TI's pages on how to use the SmartConfig tool:

  • Preferred method : Configuration using the SmartConfig tool
  • SmartConfig download: Smart Config and Home Automation
    • iOS app : available at Apple app store.
    • Android app : download and install the Android SmartConfig Application on a PC.
      This file contains the source code as well as the compiled APK file.
      The APK file is stored in ti\CC3000AndroidApp\SmartConfigCC3X\bin.

App #2: WebServer display of live sensor data
__Note!__
When using the WebServer for the first time on a Wi-Fi network you will need to determine the IP address that's assigned to Wi-Go by the DHCP Server. To do this, it is recommended you use one of the following two methods:

  • While Wi-Go is initially tethered to a laptop via USB, launch of the WebServer Application and note the IP address that is reported on the terminal screen immediately after selection of this App.
  • Alternatively, use a 3rd party LAN SCAN type tool to view Wi-Go's IP address.
    eg. FING, - available for free download from Google Play or iTunes App Stores…

Wi-Go's WebServer Application is selected as follows:

  • Press RESET, followed by the eCompass Calibration (mentioned at the top of this page).
    Then use index finger on slider to select the WebServer App (RGB LED = BLUE).
    At end of the 3 second selection period the WebServer App shall launch.
  • If you are tethered to a laptop and have a terminal open the Wi-Fi network connection confirmation will be seen, eg.

'*** Wi-Go board DHCP assigned IP Address = 192.168.43.102
  • Once you have noted Wi-Go's reported IP address, the USB cable may be disconnected and Wi-Go then used as intended, running on it's own battery power.
  • Use an Internet Browser on SmartPhone/Tablet/Laptop (connected to same Hot-Spot/Wireless Router subnet), to now connect to the noted Wi-Go IP address and view the WebServer output: /media/uploads/frankvnk/wi-go_webserver.png
  • the Webserver sensor data is auto-updated every 2 seconds a manual refresh (F5 on laptop).
  • In the event of an error, press refresh to regenerate the screen.
  • Use the mouse (or touch-screen) to exercise the RGB LED output.

App #3: Exosite Data Client
Wi-Go's sensor data gets transmitted via Wi-Fi to a cloud-based Exosite portal where the sensor measurements are displayed graphically on a "dashboard". Users can create unique customized dashboards using drag and drop GUI widgets from the library provided on the Exosite website.
__Note!__ For the Exosite application a "live" connection to the Internet is required !!!

  • Press RESET, followed by the eCompass Calibration (mentioned at the top of this page).
    Then use index finger on slider to select the Exosite Client App (RGB LED = RED)
  • On launching this App, note Wi-Go's MAC address displayed on your terminal
    (if not running a terminal use FING or other WLAN Scan tool to determine Wi-Go's MAC address) /media/uploads/frankvnk/mac_address.png
  • Using your computer's internet browser, go to avnet.exosite.com and sign-up for a free Avnet Trial Exosite Account: /media/uploads/frankvnk/avnet_trial_exosite.png
  • On the next screen, click on the Sign-Up Now button in the displayed Avnet Trial account option.
  • Complete the Account Info and Contact Info then click on Create Account (make sure to use a valid email address!).
  • Check for new incoming email from avnet.exosite.com to the address you provided and click on the link in this email to activate your new Exosite account.
  • Once activated, login using the email address and password that you chose in your registration. Your Exosite Portal and Dashboard should now display. The first time you log-in to your new account, the default Home dashboard will be displayed, pre-configured with two widgets. On the left is the Welcome widget for tips and information. On the right is the Device List widget.
    Dashboards are configurable, so at any time this default dashboard can be changed, widgets deleted and added (Clicking the upside-down triangle icon in a widget's Title bar will allow you to edit it).
  • Before going further with the Dashboard, you need to connect your Wi-Go device to your Exosite account. Do this by going to the left sidebar and selecting Devices followed by selecting the +Add Device link (on right of screen). /media/uploads/frankvnk/add_device.png
  • In the Setup screens that follow, enter the following
Select a supported deviceWi-Go
Enter device MAC Addressnn:nn:nn:nn:nn:nn [your Wi-Go's MAC address including colons]
Enter device Name[choose a descriptive name]
Enter device Location[description of your location]
  • Once completed, under Devices the name chosen for the added Wi-Go device should now be listed.
  • Click on this new Wi-Go device to examine (and edit if necessary) it's Device Information screen.
    /media/uploads/frankvnk/device_information.png
  • Click the CLOSE button to exit the Device Information screen.
  • On your Wi-Go kit now press RESET, followed by the eCompass Calibration (mentioned at the top of this page)
    and again select the Exosite Client App (RGB LED = RED) using your index finger.
  • Refresh your browser (press F5) a couple've times until the Active indicator changes to On (Green).
    /media/uploads/frankvnk/active_indicator.png
  • From the left sidebar click on Home and click on the recently named Wi-Go device which is located under the Device List.
    This will bring-up a default dashboard display similar to what's shown below.
    (Dashboards are typically accessed via the Dashboards menu entry). Check the dashboard is updating with live data by moving your Wi-Go Kit through different orientations.
    /media/uploads/frankvnk/dashboard.png
  • To create a custom dashboard, select Dashboards from the sidebar menu, followed by +Add Dashboard (on right side of Your Dashboards title bar). After completion of the initial configuration screen you will then be able to add Widgets to display the various Wi-Go data sources as well as pictures and text to support your application.
  • More guidance on the creation, editing and sharing of custom dashboards is available under the Exosite support pages

App #4: Android Sensor Fusion App

  • Press RESET, followed by the eCompass Calibration (mentioned at the top of this page)
    , then use index finger on slider to select the Android App (RGB LED = GREEN)
  • Freescale's ''Xtrinsic Sensor Fusion Toolbox'" will run on Android 3.0 or above phone or tablet. Free to download from Google Play, type Sensor fusion in the search box to find it. freescale.sensors.sfusion /media/uploads/frankvnk/sensor_fusion_toolbox.png
  • The Freescale App is well documented. To access the built-in documentation, press the NAV button at top of screen followed by Documentation from the scroll-down menu:
    /media/uploads/frankvnk/sensor_fusion_doc.png
  • Freescale's sensors site provides additional resources such as this overview: free-android-app-teaches-sensor-fusion-basics
  • Go to the Options Menu and select Preferences… /media/uploads/frankvnk/sensor_fusion_preferences.png
  • The following items need to be taken care of:
Enter WiGo's IP address
Enter the SSID (of the Hot-Spot or Wireless Access Point used by Wi-Go)
  • Press Save and Exit!
    /media/uploads/frankvnk/sensor_fusion_save_and_exit.png
  • Exit the Application completely then re-launch the Sensor Fusion Application.
  • Select the ''Source/Algorithm'" menu and change the data source to Wi-Go mag/accel /media/uploads/frankvnk/sensor_fusion_wigo_mag_accel.png
  • The Android App should now be displaying a 3-D image of Wi-Go that you can rotate and flip-over by moving the Wi-Go board accordingly…
  • Use NAV > Device View to display if this view does not come-up by default. /media/uploads/frankvnk/sensor_fusion_nav_device_view.png
  • A Serial Terminal connection is not necessary but if you happen to have one open you should see the following messages as Wi-Go connects to the Android App:
    "Server waiting for connection" followed by
    "connected, transmit buffer size= 96", and then
    "input = 0123456789"
    at which time Wi-Go starts streaming data to the Android App.
Committer:
frankvnk
Date:
Wed Oct 23 12:01:30 2013 +0000
Revision:
1:99bfc8d68fd3
Webserver functional using ProcessWlanInterrupt flag instead of NVIC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frankvnk 1:99bfc8d68fd3 1 /*****************************************************************************
frankvnk 1:99bfc8d68fd3 2 *
frankvnk 1:99bfc8d68fd3 3 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to
frankvnk 1:99bfc8d68fd3 4 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and
frankvnk 1:99bfc8d68fd3 5 * provided help.
frankvnk 1:99bfc8d68fd3 6 *
frankvnk 1:99bfc8d68fd3 7 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus
frankvnk 1:99bfc8d68fd3 8 * read the following copyright:
frankvnk 1:99bfc8d68fd3 9 *
frankvnk 1:99bfc8d68fd3 10 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
frankvnk 1:99bfc8d68fd3 11 *
frankvnk 1:99bfc8d68fd3 12 * Redistribution and use in source and binary forms, with or without
frankvnk 1:99bfc8d68fd3 13 * modification, are permitted provided that the following conditions
frankvnk 1:99bfc8d68fd3 14 * are met:
frankvnk 1:99bfc8d68fd3 15 *
frankvnk 1:99bfc8d68fd3 16 * Redistributions of source code must retain the above copyright
frankvnk 1:99bfc8d68fd3 17 * notice, this list of conditions and the following disclaimer.
frankvnk 1:99bfc8d68fd3 18 *
frankvnk 1:99bfc8d68fd3 19 * Redistributions in binary form must reproduce the above copyright
frankvnk 1:99bfc8d68fd3 20 * notice, this list of conditions and the following disclaimer in the
frankvnk 1:99bfc8d68fd3 21 * documentation and/or other materials provided with the
frankvnk 1:99bfc8d68fd3 22 * distribution.
frankvnk 1:99bfc8d68fd3 23 *
frankvnk 1:99bfc8d68fd3 24 * Neither the name of Texas Instruments Incorporated nor the names of
frankvnk 1:99bfc8d68fd3 25 * its contributors may be used to endorse or promote products derived
frankvnk 1:99bfc8d68fd3 26 * from this software without specific prior written permission.
frankvnk 1:99bfc8d68fd3 27 *
frankvnk 1:99bfc8d68fd3 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
frankvnk 1:99bfc8d68fd3 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
frankvnk 1:99bfc8d68fd3 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
frankvnk 1:99bfc8d68fd3 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
frankvnk 1:99bfc8d68fd3 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
frankvnk 1:99bfc8d68fd3 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
frankvnk 1:99bfc8d68fd3 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
frankvnk 1:99bfc8d68fd3 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
frankvnk 1:99bfc8d68fd3 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
frankvnk 1:99bfc8d68fd3 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
frankvnk 1:99bfc8d68fd3 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
frankvnk 1:99bfc8d68fd3 39 *
frankvnk 1:99bfc8d68fd3 40 *****************************************************************************/
frankvnk 1:99bfc8d68fd3 41 #include "cc3000.h"
frankvnk 1:99bfc8d68fd3 42 #include "cc3000_event.h"
frankvnk 1:99bfc8d68fd3 43 #include "cc3000_netapp.h"
frankvnk 1:99bfc8d68fd3 44
frankvnk 1:99bfc8d68fd3 45 namespace mbed_cc3000 {
frankvnk 1:99bfc8d68fd3 46
frankvnk 1:99bfc8d68fd3 47 #if (CC3000_DEBUG_HCI_RX == 1)
frankvnk 1:99bfc8d68fd3 48 const char *HCI_EVENT_STR[] =
frankvnk 1:99bfc8d68fd3 49 {
frankvnk 1:99bfc8d68fd3 50 "Socket",
frankvnk 1:99bfc8d68fd3 51 "Bind",
frankvnk 1:99bfc8d68fd3 52 "Send",
frankvnk 1:99bfc8d68fd3 53 "Recv",
frankvnk 1:99bfc8d68fd3 54 "Accept",
frankvnk 1:99bfc8d68fd3 55 "Listen",
frankvnk 1:99bfc8d68fd3 56 "Connect",
frankvnk 1:99bfc8d68fd3 57 "BSD Select",
frankvnk 1:99bfc8d68fd3 58 "Set Socket Options",
frankvnk 1:99bfc8d68fd3 59 "Get Socket Options",
frankvnk 1:99bfc8d68fd3 60 "Close Socket",
frankvnk 1:99bfc8d68fd3 61 "Unknown",
frankvnk 1:99bfc8d68fd3 62 "Recv From",
frankvnk 1:99bfc8d68fd3 63 "Write",
frankvnk 1:99bfc8d68fd3 64 "Send To",
frankvnk 1:99bfc8d68fd3 65 "Get Hostname",
frankvnk 1:99bfc8d68fd3 66 "mDNS Advertise"
frankvnk 1:99bfc8d68fd3 67 };
frankvnk 1:99bfc8d68fd3 68
frankvnk 1:99bfc8d68fd3 69 const char *HCI_NETAPP_STR[] =
frankvnk 1:99bfc8d68fd3 70 {
frankvnk 1:99bfc8d68fd3 71 "DHCP",
frankvnk 1:99bfc8d68fd3 72 "Ping Sent",
frankvnk 1:99bfc8d68fd3 73 "Ping Report",
frankvnk 1:99bfc8d68fd3 74 "Ping Stop",
frankvnk 1:99bfc8d68fd3 75 "IP Config",
frankvnk 1:99bfc8d68fd3 76 "ARP Flush",
frankvnk 1:99bfc8d68fd3 77 "Unknown",
frankvnk 1:99bfc8d68fd3 78 "Set Debug level",
frankvnk 1:99bfc8d68fd3 79 "Set Timers"
frankvnk 1:99bfc8d68fd3 80 };
frankvnk 1:99bfc8d68fd3 81
frankvnk 1:99bfc8d68fd3 82 // from 0-7
frankvnk 1:99bfc8d68fd3 83 const char *HCI_MISC_STR[] =
frankvnk 1:99bfc8d68fd3 84 {
frankvnk 1:99bfc8d68fd3 85 "BASE - Error?",
frankvnk 1:99bfc8d68fd3 86 "Connecting",
frankvnk 1:99bfc8d68fd3 87 "Disconnect",
frankvnk 1:99bfc8d68fd3 88 "Scan Param",
frankvnk 1:99bfc8d68fd3 89 "Connect Policy",
frankvnk 1:99bfc8d68fd3 90 "Add Profile",
frankvnk 1:99bfc8d68fd3 91 "Del Profile",
frankvnk 1:99bfc8d68fd3 92 "Get Scan Res",
frankvnk 1:99bfc8d68fd3 93 "Event Mask",
frankvnk 1:99bfc8d68fd3 94 "Status Req",
frankvnk 1:99bfc8d68fd3 95 "Config Start",
frankvnk 1:99bfc8d68fd3 96 "Config Stop",
frankvnk 1:99bfc8d68fd3 97 "Config Set Prefix",
frankvnk 1:99bfc8d68fd3 98 "Config Patch",
frankvnk 1:99bfc8d68fd3 99 };
frankvnk 1:99bfc8d68fd3 100 #endif
frankvnk 1:99bfc8d68fd3 101
frankvnk 1:99bfc8d68fd3 102 cc3000_event::cc3000_event(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_spi &spi, cc3000 &cc3000)
frankvnk 1:99bfc8d68fd3 103 : socket_active_status(SOCKET_STATUS_INIT_VAL), _simple_link(simplelink), _hci(hci), _spi(spi), _cc3000(cc3000) {
frankvnk 1:99bfc8d68fd3 104
frankvnk 1:99bfc8d68fd3 105 }
frankvnk 1:99bfc8d68fd3 106
frankvnk 1:99bfc8d68fd3 107 cc3000_event::~cc3000_event() {
frankvnk 1:99bfc8d68fd3 108
frankvnk 1:99bfc8d68fd3 109 }
frankvnk 1:99bfc8d68fd3 110
frankvnk 1:99bfc8d68fd3 111 /* TODO removed buffer, set it in init */
frankvnk 1:99bfc8d68fd3 112 void cc3000_event::received_handler(uint8_t *buffer) {
frankvnk 1:99bfc8d68fd3 113 _simple_link.set_data_received_flag(1);
frankvnk 1:99bfc8d68fd3 114 _simple_link.set_received_data(buffer);
frankvnk 1:99bfc8d68fd3 115
frankvnk 1:99bfc8d68fd3 116 hci_unsolicited_event_handler();
frankvnk 1:99bfc8d68fd3 117 }
frankvnk 1:99bfc8d68fd3 118
frankvnk 1:99bfc8d68fd3 119 void cc3000_event::hci_unsol_handle_patch_request(uint8_t *event_hdr) {
frankvnk 1:99bfc8d68fd3 120 uint8_t *params = (uint8_t *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
frankvnk 1:99bfc8d68fd3 121 uint32_t length = 0;
frankvnk 1:99bfc8d68fd3 122 uint8_t *patch;
frankvnk 1:99bfc8d68fd3 123
frankvnk 1:99bfc8d68fd3 124 switch (*params)
frankvnk 1:99bfc8d68fd3 125 {
frankvnk 1:99bfc8d68fd3 126 case HCI_EVENT_PATCHES_DRV_REQ:
frankvnk 1:99bfc8d68fd3 127 {
frankvnk 1:99bfc8d68fd3 128 tDriverPatches func_pointer = (tDriverPatches)_simple_link.get_func_pointer(DRIVER_PATCHES);
frankvnk 1:99bfc8d68fd3 129 if (func_pointer)
frankvnk 1:99bfc8d68fd3 130 {
frankvnk 1:99bfc8d68fd3 131 patch = func_pointer(&length);
frankvnk 1:99bfc8d68fd3 132 if (patch)
frankvnk 1:99bfc8d68fd3 133 {
frankvnk 1:99bfc8d68fd3 134 _hci.patch_send(HCI_EVENT_PATCHES_DRV_REQ, _simple_link.get_transmit_buffer(), patch, length);
frankvnk 1:99bfc8d68fd3 135 return;
frankvnk 1:99bfc8d68fd3 136 }
frankvnk 1:99bfc8d68fd3 137 }
frankvnk 1:99bfc8d68fd3 138
frankvnk 1:99bfc8d68fd3 139 // Send 0 length Patches response event
frankvnk 1:99bfc8d68fd3 140 _hci.patch_send(HCI_EVENT_PATCHES_DRV_REQ, _simple_link.get_transmit_buffer(), 0, 0);
frankvnk 1:99bfc8d68fd3 141 break;
frankvnk 1:99bfc8d68fd3 142 }
frankvnk 1:99bfc8d68fd3 143 case HCI_EVENT_PATCHES_FW_REQ:
frankvnk 1:99bfc8d68fd3 144 {
frankvnk 1:99bfc8d68fd3 145 tFWPatches func_pointer = (tFWPatches)_simple_link.get_func_pointer(FW_PATCHES);
frankvnk 1:99bfc8d68fd3 146 if (func_pointer)
frankvnk 1:99bfc8d68fd3 147 {
frankvnk 1:99bfc8d68fd3 148 patch = func_pointer(&length);
frankvnk 1:99bfc8d68fd3 149 // Build and send a patch
frankvnk 1:99bfc8d68fd3 150 if (patch)
frankvnk 1:99bfc8d68fd3 151 {
frankvnk 1:99bfc8d68fd3 152 _hci.patch_send(HCI_EVENT_PATCHES_FW_REQ, _simple_link.get_transmit_buffer(), patch, length);
frankvnk 1:99bfc8d68fd3 153 return;
frankvnk 1:99bfc8d68fd3 154 }
frankvnk 1:99bfc8d68fd3 155 }
frankvnk 1:99bfc8d68fd3 156 // Send 0 length Patches response event
frankvnk 1:99bfc8d68fd3 157 _hci.patch_send(HCI_EVENT_PATCHES_FW_REQ, _simple_link.get_transmit_buffer(), 0, 0);
frankvnk 1:99bfc8d68fd3 158 break;
frankvnk 1:99bfc8d68fd3 159 }
frankvnk 1:99bfc8d68fd3 160 case HCI_EVENT_PATCHES_BOOTLOAD_REQ:
frankvnk 1:99bfc8d68fd3 161 {
frankvnk 1:99bfc8d68fd3 162 tBootLoaderPatches func_pointer = (tBootLoaderPatches)_simple_link.get_func_pointer(BOOTLOADER_PATCHES);
frankvnk 1:99bfc8d68fd3 163 if (func_pointer)
frankvnk 1:99bfc8d68fd3 164 {
frankvnk 1:99bfc8d68fd3 165 patch = func_pointer(&length);
frankvnk 1:99bfc8d68fd3 166 if (patch)
frankvnk 1:99bfc8d68fd3 167 {
frankvnk 1:99bfc8d68fd3 168 _hci.patch_send(HCI_EVENT_PATCHES_BOOTLOAD_REQ, _simple_link.get_transmit_buffer(), patch, length);
frankvnk 1:99bfc8d68fd3 169 return;
frankvnk 1:99bfc8d68fd3 170 }
frankvnk 1:99bfc8d68fd3 171 }
frankvnk 1:99bfc8d68fd3 172 // Send 0 length Patches response event
frankvnk 1:99bfc8d68fd3 173 _hci.patch_send(HCI_EVENT_PATCHES_BOOTLOAD_REQ, _simple_link.get_transmit_buffer(), 0, 0);
frankvnk 1:99bfc8d68fd3 174 break;
frankvnk 1:99bfc8d68fd3 175 }
frankvnk 1:99bfc8d68fd3 176 }
frankvnk 1:99bfc8d68fd3 177 }
frankvnk 1:99bfc8d68fd3 178
frankvnk 1:99bfc8d68fd3 179 static void hci_event_debug_print(uint16_t hciEventNo)
frankvnk 1:99bfc8d68fd3 180 {
frankvnk 1:99bfc8d68fd3 181 #if (CC3000_DEBUG_HCI_RX == 1)
frankvnk 1:99bfc8d68fd3 182 if ((hciEventNo > HCI_CMND_SOCKET_BASE) && ( hciEventNo <= HCI_CMND_MDNS_ADVERTISE))
frankvnk 1:99bfc8d68fd3 183 {
frankvnk 1:99bfc8d68fd3 184 DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_EVENT_STR[hciEventNo-HCI_CMND_SOCKET]);
frankvnk 1:99bfc8d68fd3 185 }
frankvnk 1:99bfc8d68fd3 186 else if ((hciEventNo > HCI_CMND_NETAPP_BASE) && ( hciEventNo <= HCI_NETAPP_SET_TIMERS))
frankvnk 1:99bfc8d68fd3 187 {
frankvnk 1:99bfc8d68fd3 188 DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_NETAPP_STR[hciEventNo-HCI_NETAPP_DHCP]);
frankvnk 1:99bfc8d68fd3 189 }
frankvnk 1:99bfc8d68fd3 190 else if (hciEventNo < HCI_CMND_WLAN_CONFIGURE_PATCH+1)
frankvnk 1:99bfc8d68fd3 191 {
frankvnk 1:99bfc8d68fd3 192 DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_MISC_STR[hciEventNo]);
frankvnk 1:99bfc8d68fd3 193 }
frankvnk 1:99bfc8d68fd3 194 else
frankvnk 1:99bfc8d68fd3 195 {
frankvnk 1:99bfc8d68fd3 196 DBG_HCI("Event Received : 0x%04X", hciEventNo);
frankvnk 1:99bfc8d68fd3 197 }
frankvnk 1:99bfc8d68fd3 198 #endif
frankvnk 1:99bfc8d68fd3 199 }
frankvnk 1:99bfc8d68fd3 200
frankvnk 1:99bfc8d68fd3 201 uint8_t *cc3000_event::hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen) {
frankvnk 1:99bfc8d68fd3 202 uint8_t *received_data, argument_size;
frankvnk 1:99bfc8d68fd3 203 uint16_t length;
frankvnk 1:99bfc8d68fd3 204 uint8_t *pucReceivedParams;
frankvnk 1:99bfc8d68fd3 205 uint16_t received_op_code = 0;
frankvnk 1:99bfc8d68fd3 206 uint32_t return_value;
frankvnk 1:99bfc8d68fd3 207 uint8_t * RecvParams;
frankvnk 1:99bfc8d68fd3 208 uint8_t *RetParams;
frankvnk 1:99bfc8d68fd3 209
frankvnk 1:99bfc8d68fd3 210 while (1)
frankvnk 1:99bfc8d68fd3 211 {
frankvnk 1:99bfc8d68fd3 212 if (_simple_link.get_data_received_flag() != 0)
frankvnk 1:99bfc8d68fd3 213 {
frankvnk 1:99bfc8d68fd3 214 received_data = _simple_link.get_received_data();
frankvnk 1:99bfc8d68fd3 215 if (*received_data == HCI_TYPE_EVNT)
frankvnk 1:99bfc8d68fd3 216 {
frankvnk 1:99bfc8d68fd3 217 // Event Received
frankvnk 1:99bfc8d68fd3 218 STREAM_TO_UINT16((uint8_t *)received_data, HCI_EVENT_OPCODE_OFFSET,received_op_code);
frankvnk 1:99bfc8d68fd3 219 pucReceivedParams = received_data + HCI_EVENT_HEADER_SIZE;
frankvnk 1:99bfc8d68fd3 220 RecvParams = pucReceivedParams;
frankvnk 1:99bfc8d68fd3 221 RetParams = (uint8_t *)ret_param;
frankvnk 1:99bfc8d68fd3 222
frankvnk 1:99bfc8d68fd3 223 // unsolicited event received - finish handling
frankvnk 1:99bfc8d68fd3 224 if (hci_unsol_event_handler((uint8_t *)received_data) == 0)
frankvnk 1:99bfc8d68fd3 225 {
frankvnk 1:99bfc8d68fd3 226 STREAM_TO_UINT8(received_data, HCI_DATA_LENGTH_OFFSET, length);
frankvnk 1:99bfc8d68fd3 227
frankvnk 1:99bfc8d68fd3 228 hci_event_debug_print( received_op_code );
frankvnk 1:99bfc8d68fd3 229
frankvnk 1:99bfc8d68fd3 230 switch(received_op_code)
frankvnk 1:99bfc8d68fd3 231 {
frankvnk 1:99bfc8d68fd3 232 case HCI_CMND_READ_BUFFER_SIZE:
frankvnk 1:99bfc8d68fd3 233 {
frankvnk 1:99bfc8d68fd3 234 uint16_t temp = _simple_link.get_number_free_buffers();
frankvnk 1:99bfc8d68fd3 235 STREAM_TO_UINT8((uint8_t *)pucReceivedParams, 0, temp);
frankvnk 1:99bfc8d68fd3 236 _simple_link.set_number_free_buffers(temp);
frankvnk 1:99bfc8d68fd3 237
frankvnk 1:99bfc8d68fd3 238 temp = _simple_link.get_buffer_length();
frankvnk 1:99bfc8d68fd3 239 STREAM_TO_UINT16((uint8_t *)pucReceivedParams, 1, temp);
frankvnk 1:99bfc8d68fd3 240 _simple_link.set_buffer_length(temp);
frankvnk 1:99bfc8d68fd3 241 }
frankvnk 1:99bfc8d68fd3 242 break;
frankvnk 1:99bfc8d68fd3 243
frankvnk 1:99bfc8d68fd3 244 case HCI_CMND_WLAN_CONFIGURE_PATCH:
frankvnk 1:99bfc8d68fd3 245 case HCI_NETAPP_DHCP:
frankvnk 1:99bfc8d68fd3 246 case HCI_NETAPP_PING_SEND:
frankvnk 1:99bfc8d68fd3 247 case HCI_NETAPP_PING_STOP:
frankvnk 1:99bfc8d68fd3 248 case HCI_NETAPP_ARP_FLUSH:
frankvnk 1:99bfc8d68fd3 249 case HCI_NETAPP_SET_DEBUG_LEVEL:
frankvnk 1:99bfc8d68fd3 250 case HCI_NETAPP_SET_TIMERS:
frankvnk 1:99bfc8d68fd3 251 case HCI_EVNT_NVMEM_READ:
frankvnk 1:99bfc8d68fd3 252 case HCI_EVNT_NVMEM_CREATE_ENTRY:
frankvnk 1:99bfc8d68fd3 253 case HCI_CMND_NVMEM_WRITE_PATCH:
frankvnk 1:99bfc8d68fd3 254 case HCI_NETAPP_PING_REPORT:
frankvnk 1:99bfc8d68fd3 255 case HCI_EVNT_MDNS_ADVERTISE:
frankvnk 1:99bfc8d68fd3 256
frankvnk 1:99bfc8d68fd3 257 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET, *(uint8_t *)ret_param);
frankvnk 1:99bfc8d68fd3 258 break;
frankvnk 1:99bfc8d68fd3 259
frankvnk 1:99bfc8d68fd3 260 case HCI_CMND_SETSOCKOPT:
frankvnk 1:99bfc8d68fd3 261 case HCI_CMND_WLAN_CONNECT:
frankvnk 1:99bfc8d68fd3 262 case HCI_CMND_WLAN_IOCTL_STATUSGET:
frankvnk 1:99bfc8d68fd3 263 case HCI_EVNT_WLAN_IOCTL_ADD_PROFILE:
frankvnk 1:99bfc8d68fd3 264 case HCI_CMND_WLAN_IOCTL_DEL_PROFILE:
frankvnk 1:99bfc8d68fd3 265 case HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY:
frankvnk 1:99bfc8d68fd3 266 case HCI_CMND_WLAN_IOCTL_SET_SCANPARAM:
frankvnk 1:99bfc8d68fd3 267 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START:
frankvnk 1:99bfc8d68fd3 268 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP:
frankvnk 1:99bfc8d68fd3 269 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX:
frankvnk 1:99bfc8d68fd3 270 case HCI_CMND_EVENT_MASK:
frankvnk 1:99bfc8d68fd3 271 case HCI_EVNT_WLAN_DISCONNECT:
frankvnk 1:99bfc8d68fd3 272 case HCI_EVNT_SOCKET:
frankvnk 1:99bfc8d68fd3 273 case HCI_EVNT_BIND:
frankvnk 1:99bfc8d68fd3 274 case HCI_CMND_LISTEN:
frankvnk 1:99bfc8d68fd3 275 case HCI_EVNT_CLOSE_SOCKET:
frankvnk 1:99bfc8d68fd3 276 case HCI_EVNT_CONNECT:
frankvnk 1:99bfc8d68fd3 277 case HCI_EVNT_NVMEM_WRITE:
frankvnk 1:99bfc8d68fd3 278
frankvnk 1:99bfc8d68fd3 279 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,0, *(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 280 break;
frankvnk 1:99bfc8d68fd3 281
frankvnk 1:99bfc8d68fd3 282 case HCI_EVNT_READ_SP_VERSION:
frankvnk 1:99bfc8d68fd3 283
frankvnk 1:99bfc8d68fd3 284 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET, *(uint8_t *)ret_param);
frankvnk 1:99bfc8d68fd3 285 ret_param = ((uint8_t *)ret_param) + 1;
frankvnk 1:99bfc8d68fd3 286 STREAM_TO_UINT32((uint8_t *)pucReceivedParams, 0, return_value);
frankvnk 1:99bfc8d68fd3 287 UINT32_TO_STREAM((uint8_t *)ret_param, return_value);
frankvnk 1:99bfc8d68fd3 288 break;
frankvnk 1:99bfc8d68fd3 289
frankvnk 1:99bfc8d68fd3 290 case HCI_EVNT_BSD_GETHOSTBYNAME:
frankvnk 1:99bfc8d68fd3 291
frankvnk 1:99bfc8d68fd3 292 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_HOST_BY_NAME_RETVAL_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 293 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 294 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_HOST_BY_NAME_ADDR_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 295 break;
frankvnk 1:99bfc8d68fd3 296
frankvnk 1:99bfc8d68fd3 297 case HCI_EVNT_ACCEPT:
frankvnk 1:99bfc8d68fd3 298 {
frankvnk 1:99bfc8d68fd3 299 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,ACCEPT_SD_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 300 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 301 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,ACCEPT_RETURN_STATUS_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 302 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 303
frankvnk 1:99bfc8d68fd3 304 //This argument returns in network order
frankvnk 1:99bfc8d68fd3 305 memcpy((uint8_t *)ret_param, pucReceivedParams + ACCEPT_ADDRESS__OFFSET, sizeof(sockaddr));
frankvnk 1:99bfc8d68fd3 306 break;
frankvnk 1:99bfc8d68fd3 307 }
frankvnk 1:99bfc8d68fd3 308
frankvnk 1:99bfc8d68fd3 309 case HCI_EVNT_RECV:
frankvnk 1:99bfc8d68fd3 310 case HCI_EVNT_RECVFROM:
frankvnk 1:99bfc8d68fd3 311 {
frankvnk 1:99bfc8d68fd3 312 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 313 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 314 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 315 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 316 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE__FLAGS__OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 317
frankvnk 1:99bfc8d68fd3 318 if(((tBsdReadReturnParams *)ret_param)->iNumberOfBytes == ERROR_SOCKET_INACTIVE)
frankvnk 1:99bfc8d68fd3 319 {
frankvnk 1:99bfc8d68fd3 320 set_socket_active_status(((tBsdReadReturnParams *)ret_param)->iSocketDescriptor,SOCKET_STATUS_INACTIVE);
frankvnk 1:99bfc8d68fd3 321 }
frankvnk 1:99bfc8d68fd3 322 break;
frankvnk 1:99bfc8d68fd3 323 }
frankvnk 1:99bfc8d68fd3 324
frankvnk 1:99bfc8d68fd3 325 case HCI_EVNT_SEND:
frankvnk 1:99bfc8d68fd3 326 case HCI_EVNT_SENDTO:
frankvnk 1:99bfc8d68fd3 327 {
frankvnk 1:99bfc8d68fd3 328 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 329 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 330 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 331 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 332
frankvnk 1:99bfc8d68fd3 333 break;
frankvnk 1:99bfc8d68fd3 334 }
frankvnk 1:99bfc8d68fd3 335
frankvnk 1:99bfc8d68fd3 336 case HCI_EVNT_SELECT:
frankvnk 1:99bfc8d68fd3 337 {
frankvnk 1:99bfc8d68fd3 338 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_STATUS_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 339 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 340 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_READFD_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 341 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 342 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_WRITEFD_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 343 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 344 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_EXFD_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 345 break;
frankvnk 1:99bfc8d68fd3 346 }
frankvnk 1:99bfc8d68fd3 347
frankvnk 1:99bfc8d68fd3 348 case HCI_CMND_GETSOCKOPT:
frankvnk 1:99bfc8d68fd3 349
frankvnk 1:99bfc8d68fd3 350 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET,((tBsdGetSockOptReturnParams *)ret_param)->iStatus);
frankvnk 1:99bfc8d68fd3 351 //This argument returns in network order
frankvnk 1:99bfc8d68fd3 352 memcpy((uint8_t *)ret_param, pucReceivedParams, 4);
frankvnk 1:99bfc8d68fd3 353 break;
frankvnk 1:99bfc8d68fd3 354
frankvnk 1:99bfc8d68fd3 355 case HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS:
frankvnk 1:99bfc8d68fd3 356
frankvnk 1:99bfc8d68fd3 357 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_TABlE_COUNT_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 358 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 359 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_SCANRESULT_STATUS_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 360 ret_param = ((uint8_t *)ret_param) + 4;
frankvnk 1:99bfc8d68fd3 361 STREAM_TO_UINT16((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_ISVALID_TO_SSIDLEN_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 362 ret_param = ((uint8_t *)ret_param) + 2;
frankvnk 1:99bfc8d68fd3 363 STREAM_TO_UINT16((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_FRAME_TIME_OFFSET,*(uint32_t *)ret_param);
frankvnk 1:99bfc8d68fd3 364 ret_param = ((uint8_t *)ret_param) + 2;
frankvnk 1:99bfc8d68fd3 365 memcpy((uint8_t *)ret_param, (uint8_t *)(pucReceivedParams + GET_SCAN_RESULTS_FRAME_TIME_OFFSET + 2), GET_SCAN_RESULTS_SSID_MAC_LENGTH);
frankvnk 1:99bfc8d68fd3 366 break;
frankvnk 1:99bfc8d68fd3 367
frankvnk 1:99bfc8d68fd3 368 case HCI_CMND_SIMPLE_LINK_START:
frankvnk 1:99bfc8d68fd3 369 break;
frankvnk 1:99bfc8d68fd3 370
frankvnk 1:99bfc8d68fd3 371 case HCI_NETAPP_IPCONFIG:
frankvnk 1:99bfc8d68fd3 372
frankvnk 1:99bfc8d68fd3 373 //Read IP address
frankvnk 1:99bfc8d68fd3 374 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 375 RecvParams += 4;
frankvnk 1:99bfc8d68fd3 376
frankvnk 1:99bfc8d68fd3 377 //Read subnet
frankvnk 1:99bfc8d68fd3 378 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 379 RecvParams += 4;
frankvnk 1:99bfc8d68fd3 380
frankvnk 1:99bfc8d68fd3 381 //Read default GW
frankvnk 1:99bfc8d68fd3 382 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 383 RecvParams += 4;
frankvnk 1:99bfc8d68fd3 384
frankvnk 1:99bfc8d68fd3 385 //Read DHCP server
frankvnk 1:99bfc8d68fd3 386 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 387 RecvParams += 4;
frankvnk 1:99bfc8d68fd3 388
frankvnk 1:99bfc8d68fd3 389 //Read DNS server
frankvnk 1:99bfc8d68fd3 390 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 391 RecvParams += 4;
frankvnk 1:99bfc8d68fd3 392
frankvnk 1:99bfc8d68fd3 393 //Read Mac address
frankvnk 1:99bfc8d68fd3 394 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_MAC_LENGTH);
frankvnk 1:99bfc8d68fd3 395 RecvParams += 6;
frankvnk 1:99bfc8d68fd3 396
frankvnk 1:99bfc8d68fd3 397 //Read SSID
frankvnk 1:99bfc8d68fd3 398 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_SSID_LENGTH);
frankvnk 1:99bfc8d68fd3 399 break;
frankvnk 1:99bfc8d68fd3 400
frankvnk 1:99bfc8d68fd3 401 default :
frankvnk 1:99bfc8d68fd3 402 DBG_HCI("UNKNOWN Event Received : 0x%04X ", received_op_code);
frankvnk 1:99bfc8d68fd3 403 break;
frankvnk 1:99bfc8d68fd3 404 }
frankvnk 1:99bfc8d68fd3 405
frankvnk 1:99bfc8d68fd3 406 }
frankvnk 1:99bfc8d68fd3 407 if (received_op_code == _simple_link.get_op_code())
frankvnk 1:99bfc8d68fd3 408 {
frankvnk 1:99bfc8d68fd3 409 _simple_link.set_op_code(0);
frankvnk 1:99bfc8d68fd3 410 }
frankvnk 1:99bfc8d68fd3 411 }
frankvnk 1:99bfc8d68fd3 412 else
frankvnk 1:99bfc8d68fd3 413 {
frankvnk 1:99bfc8d68fd3 414 pucReceivedParams = received_data;
frankvnk 1:99bfc8d68fd3 415 STREAM_TO_UINT8((uint8_t *)received_data, HCI_PACKET_ARGSIZE_OFFSET, argument_size);
frankvnk 1:99bfc8d68fd3 416
frankvnk 1:99bfc8d68fd3 417 STREAM_TO_UINT16((uint8_t *)received_data, HCI_PACKET_LENGTH_OFFSET, length);
frankvnk 1:99bfc8d68fd3 418
frankvnk 1:99bfc8d68fd3 419 // Data received: note that the only case where from and from length
frankvnk 1:99bfc8d68fd3 420 // are not null is in recv from, so fill the args accordingly
frankvnk 1:99bfc8d68fd3 421 if (from)
frankvnk 1:99bfc8d68fd3 422 {
frankvnk 1:99bfc8d68fd3 423 STREAM_TO_UINT32((uint8_t *)(received_data + HCI_DATA_HEADER_SIZE), BSD_RECV_FROM_FROMLEN_OFFSET, *(uint32_t *)fromlen);
frankvnk 1:99bfc8d68fd3 424 memcpy(from, (received_data + HCI_DATA_HEADER_SIZE + BSD_RECV_FROM_FROM_OFFSET) ,*fromlen);
frankvnk 1:99bfc8d68fd3 425 }
frankvnk 1:99bfc8d68fd3 426
frankvnk 1:99bfc8d68fd3 427 memcpy(ret_param, pucReceivedParams + HCI_DATA_HEADER_SIZE + argument_size, length - argument_size);
frankvnk 1:99bfc8d68fd3 428
frankvnk 1:99bfc8d68fd3 429 _simple_link.set_pending_data(0);
frankvnk 1:99bfc8d68fd3 430 }
frankvnk 1:99bfc8d68fd3 431
frankvnk 1:99bfc8d68fd3 432 _simple_link.set_data_received_flag(0);
frankvnk 1:99bfc8d68fd3 433
frankvnk 1:99bfc8d68fd3 434 //tWlanInterruptEnable func_pointer = (tWlanInterruptEnable)_simple_link.get_func_pointer(WLAN_INTERRUPT_ENABLE);
frankvnk 1:99bfc8d68fd3 435 //func_pointer();
frankvnk 1:99bfc8d68fd3 436 _spi.wlan_irq_enable();
frankvnk 1:99bfc8d68fd3 437
frankvnk 1:99bfc8d68fd3 438 // Since we are going to TX - we need to handle this event after the ResumeSPi since we need interrupts
frankvnk 1:99bfc8d68fd3 439 if ((*received_data == HCI_TYPE_EVNT) && (received_op_code == HCI_EVNT_PATCHES_REQ))
frankvnk 1:99bfc8d68fd3 440 {
frankvnk 1:99bfc8d68fd3 441 hci_unsol_handle_patch_request((uint8_t *)received_data);
frankvnk 1:99bfc8d68fd3 442 }
frankvnk 1:99bfc8d68fd3 443 if ((_simple_link.get_op_code() == 0) && (_simple_link.get_pending_data() == 0))
frankvnk 1:99bfc8d68fd3 444 {
frankvnk 1:99bfc8d68fd3 445 return NULL;
frankvnk 1:99bfc8d68fd3 446 }
frankvnk 1:99bfc8d68fd3 447 }
frankvnk 1:99bfc8d68fd3 448 }
frankvnk 1:99bfc8d68fd3 449 }
frankvnk 1:99bfc8d68fd3 450
frankvnk 1:99bfc8d68fd3 451 int32_t cc3000_event::hci_unsol_event_handler(uint8_t *event_hdr) {
frankvnk 1:99bfc8d68fd3 452 uint8_t *data = NULL;
frankvnk 1:99bfc8d68fd3 453 int32_t event_type;
frankvnk 1:99bfc8d68fd3 454 uint32_t number_of_released_packets;
frankvnk 1:99bfc8d68fd3 455 uint32_t number_of_sent_packets;
frankvnk 1:99bfc8d68fd3 456
frankvnk 1:99bfc8d68fd3 457 STREAM_TO_UINT16(event_hdr, HCI_EVENT_OPCODE_OFFSET,event_type);
frankvnk 1:99bfc8d68fd3 458
frankvnk 1:99bfc8d68fd3 459 if (event_type & HCI_EVNT_UNSOL_BASE) {
frankvnk 1:99bfc8d68fd3 460 switch(event_type) {
frankvnk 1:99bfc8d68fd3 461 case HCI_EVNT_DATA_UNSOL_FREE_BUFF:
frankvnk 1:99bfc8d68fd3 462 {
frankvnk 1:99bfc8d68fd3 463 hci_event_unsol_flowcontrol_handler(event_hdr);
frankvnk 1:99bfc8d68fd3 464
frankvnk 1:99bfc8d68fd3 465 number_of_released_packets = _simple_link.get_released_packets();
frankvnk 1:99bfc8d68fd3 466 number_of_sent_packets = _simple_link.get_sent_packets();
frankvnk 1:99bfc8d68fd3 467
frankvnk 1:99bfc8d68fd3 468 if (number_of_released_packets == number_of_sent_packets)
frankvnk 1:99bfc8d68fd3 469 {
frankvnk 1:99bfc8d68fd3 470 if (_simple_link.get_tx_complete_signal())
frankvnk 1:99bfc8d68fd3 471 {
frankvnk 1:99bfc8d68fd3 472 //tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
frankvnk 1:99bfc8d68fd3 473 _cc3000.usync_callback(HCI_EVENT_CC3000_CAN_SHUT_DOWN, NULL, 0);
frankvnk 1:99bfc8d68fd3 474 }
frankvnk 1:99bfc8d68fd3 475 }
frankvnk 1:99bfc8d68fd3 476 return 1;
frankvnk 1:99bfc8d68fd3 477 }
frankvnk 1:99bfc8d68fd3 478 }
frankvnk 1:99bfc8d68fd3 479 }
frankvnk 1:99bfc8d68fd3 480
frankvnk 1:99bfc8d68fd3 481 if (event_type & HCI_EVNT_WLAN_UNSOL_BASE) {
frankvnk 1:99bfc8d68fd3 482 switch(event_type) {
frankvnk 1:99bfc8d68fd3 483 case HCI_EVNT_WLAN_KEEPALIVE:
frankvnk 1:99bfc8d68fd3 484 case HCI_EVNT_WLAN_UNSOL_CONNECT:
frankvnk 1:99bfc8d68fd3 485 case HCI_EVNT_WLAN_UNSOL_DISCONNECT:
frankvnk 1:99bfc8d68fd3 486 case HCI_EVNT_WLAN_UNSOL_INIT:
frankvnk 1:99bfc8d68fd3 487 case HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE:
frankvnk 1:99bfc8d68fd3 488 // {
frankvnk 1:99bfc8d68fd3 489 // tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
frankvnk 1:99bfc8d68fd3 490 // if( func_pointer )
frankvnk 1:99bfc8d68fd3 491 // {
frankvnk 1:99bfc8d68fd3 492 // func_pointer(event_type, 0, 0);
frankvnk 1:99bfc8d68fd3 493 // }
frankvnk 1:99bfc8d68fd3 494 _cc3000.usync_callback(event_type, 0, 0);
frankvnk 1:99bfc8d68fd3 495 break;
frankvnk 1:99bfc8d68fd3 496 // }
frankvnk 1:99bfc8d68fd3 497 case HCI_EVNT_WLAN_UNSOL_DHCP:
frankvnk 1:99bfc8d68fd3 498 {
frankvnk 1:99bfc8d68fd3 499 uint8_t params[NETAPP_IPCONFIG_MAC_OFFSET + 1]; // extra byte is for the status
frankvnk 1:99bfc8d68fd3 500 uint8_t *recParams = params;
frankvnk 1:99bfc8d68fd3 501 data = (uint8_t *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
frankvnk 1:99bfc8d68fd3 502
frankvnk 1:99bfc8d68fd3 503 //Read IP address
frankvnk 1:99bfc8d68fd3 504 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 505 data += 4;
frankvnk 1:99bfc8d68fd3 506 //Read subnet
frankvnk 1:99bfc8d68fd3 507 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 508 data += 4;
frankvnk 1:99bfc8d68fd3 509 //Read default GW
frankvnk 1:99bfc8d68fd3 510 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 511 data += 4;
frankvnk 1:99bfc8d68fd3 512 //Read DHCP server
frankvnk 1:99bfc8d68fd3 513 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 514 data += 4;
frankvnk 1:99bfc8d68fd3 515 //Read DNS server
frankvnk 1:99bfc8d68fd3 516 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
frankvnk 1:99bfc8d68fd3 517 // read the status
frankvnk 1:99bfc8d68fd3 518 STREAM_TO_UINT8(event_hdr, HCI_EVENT_STATUS_OFFSET, *recParams);
frankvnk 1:99bfc8d68fd3 519
frankvnk 1:99bfc8d68fd3 520 // tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
frankvnk 1:99bfc8d68fd3 521 // if( func_pointer )
frankvnk 1:99bfc8d68fd3 522 // {
frankvnk 1:99bfc8d68fd3 523 _cc3000.usync_callback(event_type, (uint8_t *)params, sizeof(params));
frankvnk 1:99bfc8d68fd3 524 // }
frankvnk 1:99bfc8d68fd3 525 break;
frankvnk 1:99bfc8d68fd3 526 }
frankvnk 1:99bfc8d68fd3 527 case HCI_EVNT_WLAN_ASYNC_PING_REPORT:
frankvnk 1:99bfc8d68fd3 528 {
frankvnk 1:99bfc8d68fd3 529 netapp_pingreport_args_t params;
frankvnk 1:99bfc8d68fd3 530 data = (uint8_t *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
frankvnk 1:99bfc8d68fd3 531 STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_SENT_OFFSET, params.packets_sent);
frankvnk 1:99bfc8d68fd3 532 STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_RCVD_OFFSET, params.packets_received);
frankvnk 1:99bfc8d68fd3 533 STREAM_TO_UINT32(data, NETAPP_PING_MIN_RTT_OFFSET, params.min_round_time);
frankvnk 1:99bfc8d68fd3 534 STREAM_TO_UINT32(data, NETAPP_PING_MAX_RTT_OFFSET, params.max_round_time);
frankvnk 1:99bfc8d68fd3 535 STREAM_TO_UINT32(data, NETAPP_PING_AVG_RTT_OFFSET, params.avg_round_time);
frankvnk 1:99bfc8d68fd3 536
frankvnk 1:99bfc8d68fd3 537 // tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
frankvnk 1:99bfc8d68fd3 538 // if (func_pointer)
frankvnk 1:99bfc8d68fd3 539 // {
frankvnk 1:99bfc8d68fd3 540 _cc3000.usync_callback(event_type, (uint8_t *)&params, sizeof(params));
frankvnk 1:99bfc8d68fd3 541 // }
frankvnk 1:99bfc8d68fd3 542 break;
frankvnk 1:99bfc8d68fd3 543 }
frankvnk 1:99bfc8d68fd3 544 case HCI_EVNT_BSD_TCP_CLOSE_WAIT:
frankvnk 1:99bfc8d68fd3 545 {
frankvnk 1:99bfc8d68fd3 546 // tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
frankvnk 1:99bfc8d68fd3 547 // if (func_pointer)
frankvnk 1:99bfc8d68fd3 548 // {
frankvnk 1:99bfc8d68fd3 549 _cc3000.usync_callback(event_type, NULL, 0);
frankvnk 1:99bfc8d68fd3 550 // }
frankvnk 1:99bfc8d68fd3 551 break;
frankvnk 1:99bfc8d68fd3 552 }
frankvnk 1:99bfc8d68fd3 553
frankvnk 1:99bfc8d68fd3 554 //'default' case which means "event not supported"
frankvnk 1:99bfc8d68fd3 555 default:
frankvnk 1:99bfc8d68fd3 556 return (0);
frankvnk 1:99bfc8d68fd3 557 }
frankvnk 1:99bfc8d68fd3 558 return(1);
frankvnk 1:99bfc8d68fd3 559 }
frankvnk 1:99bfc8d68fd3 560
frankvnk 1:99bfc8d68fd3 561 if ((event_type == HCI_EVNT_SEND) || (event_type == HCI_EVNT_SENDTO) || (event_type == HCI_EVNT_WRITE)) {
frankvnk 1:99bfc8d68fd3 562 uint8_t *pArg;
frankvnk 1:99bfc8d68fd3 563 int32_t status;
frankvnk 1:99bfc8d68fd3 564 pArg = M_BSD_RESP_PARAMS_OFFSET(event_hdr);
frankvnk 1:99bfc8d68fd3 565 STREAM_TO_UINT32(pArg, BSD_RSP_PARAMS_STATUS_OFFSET,status);
frankvnk 1:99bfc8d68fd3 566 if (ERROR_SOCKET_INACTIVE == status) {
frankvnk 1:99bfc8d68fd3 567 // The only synchronous event that can come from SL device in form of
frankvnk 1:99bfc8d68fd3 568 // command complete is "Command Complete" on data sent, in case SL device
frankvnk 1:99bfc8d68fd3 569 // was unable to transmit
frankvnk 1:99bfc8d68fd3 570 int32_t transmit_error = _simple_link.get_transmit_error();
frankvnk 1:99bfc8d68fd3 571 STREAM_TO_UINT8(event_hdr, HCI_EVENT_STATUS_OFFSET, transmit_error);
frankvnk 1:99bfc8d68fd3 572 _simple_link.set_transmit_error(transmit_error);
frankvnk 1:99bfc8d68fd3 573 update_socket_active_status(M_BSD_RESP_PARAMS_OFFSET(event_hdr));
frankvnk 1:99bfc8d68fd3 574 return (1);
frankvnk 1:99bfc8d68fd3 575 }
frankvnk 1:99bfc8d68fd3 576 else {
frankvnk 1:99bfc8d68fd3 577 return (0);
frankvnk 1:99bfc8d68fd3 578 }
frankvnk 1:99bfc8d68fd3 579 }
frankvnk 1:99bfc8d68fd3 580 return(0);
frankvnk 1:99bfc8d68fd3 581 }
frankvnk 1:99bfc8d68fd3 582
frankvnk 1:99bfc8d68fd3 583 int32_t cc3000_event::hci_unsolicited_event_handler(void) {
frankvnk 1:99bfc8d68fd3 584 uint32_t res = 0;
frankvnk 1:99bfc8d68fd3 585 uint8_t *received_data;
frankvnk 1:99bfc8d68fd3 586
frankvnk 1:99bfc8d68fd3 587 if (_simple_link.get_data_received_flag() != 0) {
frankvnk 1:99bfc8d68fd3 588 received_data = (_simple_link.get_received_data());
frankvnk 1:99bfc8d68fd3 589
frankvnk 1:99bfc8d68fd3 590 if (*received_data == HCI_TYPE_EVNT) {
frankvnk 1:99bfc8d68fd3 591 // unsolicited event received - finish handling
frankvnk 1:99bfc8d68fd3 592 if (hci_unsol_event_handler((uint8_t *)received_data) == 1) {
frankvnk 1:99bfc8d68fd3 593 // An unsolicited event was received:
frankvnk 1:99bfc8d68fd3 594 // release the buffer and clean the event received
frankvnk 1:99bfc8d68fd3 595 _simple_link.set_data_received_flag(0);
frankvnk 1:99bfc8d68fd3 596
frankvnk 1:99bfc8d68fd3 597 res = 1;
frankvnk 1:99bfc8d68fd3 598 _spi.wlan_irq_enable();
frankvnk 1:99bfc8d68fd3 599 }
frankvnk 1:99bfc8d68fd3 600 }
frankvnk 1:99bfc8d68fd3 601 }
frankvnk 1:99bfc8d68fd3 602 return res;
frankvnk 1:99bfc8d68fd3 603 }
frankvnk 1:99bfc8d68fd3 604
frankvnk 1:99bfc8d68fd3 605 void cc3000_event::set_socket_active_status(int32_t sd, int32_t status) {
frankvnk 1:99bfc8d68fd3 606 if (M_IS_VALID_SD(sd) && M_IS_VALID_STATUS(status))
frankvnk 1:99bfc8d68fd3 607 {
frankvnk 1:99bfc8d68fd3 608 socket_active_status &= ~(1 << sd); /* clean socket's mask */
frankvnk 1:99bfc8d68fd3 609 socket_active_status |= (status << sd); /* set new socket's mask */
frankvnk 1:99bfc8d68fd3 610 }
frankvnk 1:99bfc8d68fd3 611 }
frankvnk 1:99bfc8d68fd3 612
frankvnk 1:99bfc8d68fd3 613 int32_t cc3000_event::hci_event_unsol_flowcontrol_handler(uint8_t *event) {
frankvnk 1:99bfc8d68fd3 614 int32_t temp, value;
frankvnk 1:99bfc8d68fd3 615 uint16_t i;
frankvnk 1:99bfc8d68fd3 616 uint16_t pusNumberOfHandles=0;
frankvnk 1:99bfc8d68fd3 617 uint8_t *pReadPayload;
frankvnk 1:99bfc8d68fd3 618
frankvnk 1:99bfc8d68fd3 619 STREAM_TO_UINT16((uint8_t *)event,HCI_EVENT_HEADER_SIZE,pusNumberOfHandles);
frankvnk 1:99bfc8d68fd3 620 pReadPayload = ((uint8_t *)event + HCI_EVENT_HEADER_SIZE + sizeof(pusNumberOfHandles));
frankvnk 1:99bfc8d68fd3 621 temp = 0;
frankvnk 1:99bfc8d68fd3 622
frankvnk 1:99bfc8d68fd3 623 for(i = 0; i < pusNumberOfHandles; i++) {
frankvnk 1:99bfc8d68fd3 624 STREAM_TO_UINT16(pReadPayload, FLOW_CONTROL_EVENT_FREE_BUFFS_OFFSET, value);
frankvnk 1:99bfc8d68fd3 625 temp += value;
frankvnk 1:99bfc8d68fd3 626 pReadPayload += FLOW_CONTROL_EVENT_SIZE;
frankvnk 1:99bfc8d68fd3 627 }
frankvnk 1:99bfc8d68fd3 628
frankvnk 1:99bfc8d68fd3 629 _simple_link.set_number_free_buffers(_simple_link.get_number_free_buffers() + temp);
frankvnk 1:99bfc8d68fd3 630 _simple_link.set_number_of_released_packets(_simple_link.get_released_packets() + temp);
frankvnk 1:99bfc8d68fd3 631
frankvnk 1:99bfc8d68fd3 632 return(ESUCCESS);
frankvnk 1:99bfc8d68fd3 633 }
frankvnk 1:99bfc8d68fd3 634
frankvnk 1:99bfc8d68fd3 635 int32_t cc3000_event::get_socket_active_status(int32_t sd) {
frankvnk 1:99bfc8d68fd3 636 if(M_IS_VALID_SD(sd)) {
frankvnk 1:99bfc8d68fd3 637 return (socket_active_status & (1 << sd)) ? SOCKET_STATUS_INACTIVE : SOCKET_STATUS_ACTIVE;
frankvnk 1:99bfc8d68fd3 638 } else {
frankvnk 1:99bfc8d68fd3 639 return SOCKET_STATUS_INACTIVE;
frankvnk 1:99bfc8d68fd3 640 }
frankvnk 1:99bfc8d68fd3 641 }
frankvnk 1:99bfc8d68fd3 642
frankvnk 1:99bfc8d68fd3 643 void cc3000_event::update_socket_active_status(uint8_t *resp_params) {
frankvnk 1:99bfc8d68fd3 644 int32_t status, sd;
frankvnk 1:99bfc8d68fd3 645
frankvnk 1:99bfc8d68fd3 646 STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_SOCKET_OFFSET,sd);
frankvnk 1:99bfc8d68fd3 647 STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_STATUS_OFFSET,status);
frankvnk 1:99bfc8d68fd3 648
frankvnk 1:99bfc8d68fd3 649 if(ERROR_SOCKET_INACTIVE == status) {
frankvnk 1:99bfc8d68fd3 650 set_socket_active_status(sd, SOCKET_STATUS_INACTIVE);
frankvnk 1:99bfc8d68fd3 651 }
frankvnk 1:99bfc8d68fd3 652 }
frankvnk 1:99bfc8d68fd3 653
frankvnk 1:99bfc8d68fd3 654 void cc3000_event::simplelink_wait_event(uint16_t op_code, void *ret_param) {
frankvnk 1:99bfc8d68fd3 655 // In the blocking implementation the control to caller will be returned only
frankvnk 1:99bfc8d68fd3 656 // after the end of current transaction
frankvnk 1:99bfc8d68fd3 657 _simple_link.set_op_code(op_code);
frankvnk 1:99bfc8d68fd3 658 hci_event_handler(ret_param, 0, 0);
frankvnk 1:99bfc8d68fd3 659 }
frankvnk 1:99bfc8d68fd3 660
frankvnk 1:99bfc8d68fd3 661 void cc3000_event::simplelink_wait_data(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen) {
frankvnk 1:99bfc8d68fd3 662 // In the blocking implementation the control to caller will be returned only
frankvnk 1:99bfc8d68fd3 663 // after the end of current transaction, i.e. only after data will be received
frankvnk 1:99bfc8d68fd3 664 _simple_link.set_pending_data(1);
frankvnk 1:99bfc8d68fd3 665 hci_event_handler(pBuf, from, fromlen);
frankvnk 1:99bfc8d68fd3 666 }
frankvnk 1:99bfc8d68fd3 667
frankvnk 1:99bfc8d68fd3 668
frankvnk 1:99bfc8d68fd3 669 } /* end of cc3000 namespace */