Driver for CC3000 Wi-Fi module

Dependencies:   NVIC_set_all_priorities

Dependents:   CC3000_Simple_Socket Wi-Go_IOT_Demo

Information

The current code has been reworked to a full object oriented application and contains an mbed socket compatible API.

CC3000 Wi-Fi module library

Info

This is the low level driver for TI's SimpleLink CC3000 device.
Port from Avnet's Wi-Go KEIL code (based on TI's CC3000 code).
Special thanks to Jim Carver from Avnet for providing the Wi-Go board and for his assistance.

Differences with TI's original code

The code functionality stays exactly the same.
In order to make it easier to use the code, following changes were made :

  • Addition of a tool to shift all IRQ priorities to a lower level since it is very important to keep the SPI handler at the highest system priority, the WLAN interrupt the second highest and all other system interrupts at a lower priority, so their handlers can be preempted by the CC3000 interrupts.
  • Addition of low level I/O controls and conditional compiler controls in cc3000_common.h.
  • CC3000 initialisation, pin declarations, SPI and WLAN irq priorities are set in Init_HostDriver , we need to call this function at the start of the main function.
  • The SPI and HCI code are joined into one file.
  • The include list has been rearranged - Only #include "wlan.h" is needed in the user API.
  • Part of the CC3000's user eeprom memory is used to store additional info (52 bytes in NVMEM_USER_FILE_1):
# bytesDescriptionInfo
1First time config parameterUseful when connecting
2Firmware updater versionused with the Firmware update tool
2Service Pack versionused with the Firmware update tool
3Driver Versionused with the Firmware update tool
3Firmware Versionused with the Firmware update tool
1CIK validation (Client Interface Key)
40CIK data (Client Interface Key)used with the exosite

Using the Library

A user API is needed to access the CC3000 functions.
Examples:

Using the library with other processors

cc3000_common.cpp loads the irq tool for all targets:
All current mbed targets are supported by this library.

#include "NVIC_set_all_priorities.h"


All low level settings that need to change are available in cc3000_common.h

//*****************************************************************************
//              PIN CONTROLS & COMPILE CONTROLS
//*****************************************************************************
// Compiler control
#define CC3000_UNENCRYPTED_SMART_CONFIG   // No encryption
//#define CC3000_TINY_DRIVER                // Driver for small memory model CPUs

//Interrupt controls
#define NVIC_ALL_IRQ        NVIC_set_all_irq_priorities(3);         // Set ALL interrupt priorities to level 3
#define NVIC_SPI_IRQ        NVIC_SetPriority(SPI0_IRQn, 0x0);       // Wi-Fi SPI interrupt must be higher priority than SysTick
#define NVIC_PORT_IRQ       NVIC_SetPriority(PORTA_IRQn, 0x1);
#define NVIC_SYSTICK_IRQ    NVIC_SetPriority(SysTick_IRQn, 0x2);    // SysTick set to lower priority than Wi-Fi SPI bus interrupt
//#define NVIC_ADC_IRQ        NVIC_SetPriority(ADC0_IRQn, 0x3);       // ADC is the lowest of all

// Wlan controls
#define WLAN_ISF_PCR        PORTA->PCR[16]
#define WLAN_ISF_ISFR       PORTA->ISFR
#define WLAN_ISF_MASK       (1<<16)

#define WLAN_ASSERT_CS      wlan_cs = 0;   //CS : active low
#define WLAN_DEASSERT_CS    wlan_cs = 1;

#define WLAN_ASSERT_EN      wlan_en = 1;   //EN : active high
#define WLAN_DEASSERT_EN    wlan_en = 0;

#define WLAN_READ_IRQ       wlan_int

#define WLAN_ENABLE_IRQ     wlan_int.fall(&WLAN_IRQHandler);
#define WLAN_DISABLE_IRQ    wlan_int.fall(NULL);

#define WLAN_IRQ_PIN_CREATE         InterruptIn wlan_int (PTA16);
#define WLAN_EN_PIN_CREATE          DigitalOut  wlan_en  (PTA13);
#define WLAN_CS_PIN_CREATE          DigitalOut  wlan_cs  (PTD0);
#define WLAN_SPI_PORT_CREATE        SPI wlan(PTD2, PTD3, PTC5); // mosi, miso, sclk

#define WLAN_SPI_PORT_INIT          wlan.format(8,1);
#define WLAN_SPI_SET_FREQ           wlan.frequency(12000000);
#define WLAN_SPI_SET_IRQ_HANDLER    wlan_int.fall(&WLAN_IRQHandler);

#define WLAN_SPI_WRITE              wlan.write(*data++);
#define WLAN_SPI_READ               wlan.write(0x03);          // !! DO NOT MODIFY the 0x03 parameter (CC3000 will not respond).

API documentation

Due to a little problem with the links on the mbed site, the API documentation is not directly accessible (will be solved in a next release).
Currently, it is only accessible by adding modules.html to the API doc link: http://mbed.org/users/frankvnk/code/CC3000_Hostdriver/docs/tip/modules.html

Files at this revision

API Documentation at this revision

Comitter:
frankvnk
Date:
Mon Jul 15 14:19:46 2013 +0000
Parent:
3:3818c9c7b14e
Child:
5:854f9b13a0f9
Commit message:
Full clean up (comments, Doxygen, code)

Changed in this revision

CC3000_spi.cpp Show annotated file Show diff for this revision Revisions of this file
CC3000_spi.h Show annotated file Show diff for this revision Revisions of this file
GlobalAssigns.h Show annotated file Show diff for this revision Revisions of this file
cc3000.cpp Show annotated file Show diff for this revision Revisions of this file
cc3000.h Show annotated file Show diff for this revision Revisions of this file
cc3000_common.cpp Show annotated file Show diff for this revision Revisions of this file
cc3000_common.h Show annotated file Show diff for this revision Revisions of this file
evnt_handler.cpp Show annotated file Show diff for this revision Revisions of this file
evnt_handler.h Show annotated file Show diff for this revision Revisions of this file
hci.cpp Show annotated file Show diff for this revision Revisions of this file
hci.h Show annotated file Show diff for this revision Revisions of this file
netapp.cpp Show annotated file Show diff for this revision Revisions of this file
netapp.h Show annotated file Show diff for this revision Revisions of this file
nvmem.cpp Show annotated file Show diff for this revision Revisions of this file
nvmem.h Show annotated file Show diff for this revision Revisions of this file
security.cpp Show annotated file Show diff for this revision Revisions of this file
security.h Show annotated file Show diff for this revision Revisions of this file
socket.cpp Show annotated file Show diff for this revision Revisions of this file
socket.h Show annotated file Show diff for this revision Revisions of this file
wlan.cpp Show annotated file Show diff for this revision Revisions of this file
wlan.h Show annotated file Show diff for this revision Revisions of this file
--- a/CC3000_spi.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/CC3000_spi.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -41,12 +41,6 @@
 *
 *****************************************************************************/
 
-//*****************************************************************************
-//
-//! \addtogroup link_buff_api
-//! @{
-//
-//*****************************************************************************
 #include "CC3000_spi.h"
 
 tSpiInformation sSpiInformation;
@@ -58,17 +52,6 @@
 char spi_buffer[CC3000_RX_BUFFER_SIZE];
 unsigned char wlan_tx_buffer[CC3000_TX_BUFFER_SIZE];
 
-//*****************************************************************************
-//
-//!  SpiClose
-//!
-//!  \param  none
-//!
-//!  \return none
-//!
-//!  \brief  Close the SPI interface
-//
-//*****************************************************************************
 void SpiClose(void)
 {
    if (sSpiInformation.pRxPacket)
@@ -78,21 +61,10 @@
     tSLInformation.WlanInterruptDisable();
 }
 
-//*****************************************************************************
-//
-//!  SpiOpen
-//!
-//!  \param  pointer to RX handle
-//!
-//!  \return none
-//!
-//!  \brief  Open the SPI interface
-//
-//*****************************************************************************
+
 void SpiOpen(gcSpiHandleRx pfRxHandler)
 {
    sSpiInformation.ulSpiState = eSPI_STATE_POWERUP;
-
    sSpiInformation.SPIRxHandler = pfRxHandler;
    sSpiInformation.usTxPacketLength = 0;
    sSpiInformation.pTxPacket = NULL;
@@ -103,21 +75,10 @@
    tSLInformation.WlanInterruptEnable();
 }
 
-//*****************************************************************************
-//
-//! First SPI write after powerup (delay needed between SPI header and body)
-//!
-//!  \param  pointer to write buffer
-//!  \param  buffer length
-//!
-//!  \return none
-//!
-//!  \brief  ...
-//
-//*****************************************************************************
+
 long SpiFirstWrite(unsigned char *ucBuf, unsigned short usLength)
 {
-    wlan_cs = 0;
+    WLAN_ASSERT_CS;
     wait_us(50);
 
     // SPI writes first 4 bytes of data
@@ -129,29 +90,16 @@
     // From this point on - operate in a regular way
     sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
 
-    wlan_cs = 1;
+    WLAN_DEASSERT_CS;
 
     return(0);
 }
 
-//*****************************************************************************
-//
-//! SPI Write function
-//!
-//!  \param  pointer to write buffer
-//!  \param  buffer length
-//!
-//!  \return 0
-//!
-//!  \brief  ...
-//
-//*****************************************************************************
+
 long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength)
 {
    unsigned char ucPad = 0;
-   //
-   // Figure out the total length of the packet in order to figure out if there is padding or not
-   //
+   // check the total length of the packet in order to figure out if padding is necessary
    if(!(usLength & 0x0001))
    {
       ucPad++;
@@ -185,9 +133,7 @@
    }
    else
    {
-
-//printf("SPIW\n");
-      // We need to prevent here race that can occur in case 2 back to back packets are sent to the
+      // Prevent occurence of a race condition when 2 back to back packets are sent to the
       // device, so the state will move to IDLE and once again to not IDLE due to IRQ
       tSLInformation.WlanInterruptDisable();
 
@@ -198,113 +144,56 @@
       sSpiInformation.usTxPacketLength = usLength;
 
       // Assert the CS line and wait until the IRQ line is active, then initialize the write operation
-      wlan_cs = 0;
+      WLAN_ASSERT_CS;
 
       tSLInformation.WlanInterruptEnable();
 
       // check for a missing interrupt between the CS assertion and interrupt enable
       if (tSLInformation.ReadWlanInterruptPin() == 0)
       {
-//printf("IRQ-MISSED\n");
           SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength);
           sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
-          wlan_cs = 1;
+          WLAN_DEASSERT_CS;
       }
    }
 
-   // Due to the fact that we are currently implementing a blocking situation, wait until the transaction ends
-
+   // Wait until the transaction ends
    while (sSpiInformation.ulSpiState != eSPI_STATE_IDLE);
-//printf("SPIW-E\n");
    return(0);
 }
 
 
-
-
-//*****************************************************************************
-//
-//! Low level SPI write
-//!
-//!  \param  pointer to data buffer
-//!  \param  number of bytes
-//!
-//!  \return none
-//!
-//!  \brief  ...
-//
-//*****************************************************************************
 void SpiWriteDataSynchronous(unsigned char *data, unsigned short size)
 {
-// -----------------------------  printf("W %02i : ",size);
    for (; size > 0 ; size--)
    {
-//printf("%02X ",*data);
-       wlan.write(*data++);
+        WLAN_SPI_WRITE;
    }
-//printf("\n");
 }
 
-//*****************************************************************************
-//
-//! Low level SPI read
-//!
-//!  \param  pointer to data buffer
-//!  \param  number of bytes
-//!
-//!  \return none
-//!
-//!  \brief  ...
-//
-//*****************************************************************************
+
 void SpiReadDataSynchronous(unsigned char *data, unsigned short size)
 {
    long i = 0;
-// -----------------------------  printf("R %02i : ",size);
    for (i = 0; i < size; i++)
    {
-      data[i] = wlan.write(READ);
-//printf("%02X ",data[i]);
+      data[i] = WLAN_SPI_READ;
    }
-//printf("\n");
 }
 
-//*****************************************************************************
-//
-//! Read 5 SPI header bytes and 5 Event Data bytes
-//!
-//!  \param  none
-//!
-//!  \return none
-//!
-//!  \brief  ...
-//
-//*****************************************************************************
+
 void SpiReadHeader(void)
 {
    SpiReadDataSynchronous(sSpiInformation.pRxPacket, 10);
 }
 
 
-//*****************************************************************************
-//
-//! Process the received SPI Header and in accordance with it - continue reading the packet
-//!
-//!  \param  None
-//!
-//!  \return 0
-//!
-//!  \brief  ...
-//
-//*****************************************************************************
 long SpiReadDataCont(void)
 {
    long data_to_recv;
    unsigned char *evnt_buff, type;
 
-   //
-   //determine what type of packet we have
-   //
+   //determine the packet type
    evnt_buff =  sSpiInformation.pRxPacket;
    data_to_recv = 0;
    STREAM_TO_UINT8((char *)(evnt_buff + SPI_HEADER_SIZE), HCI_PACKET_TYPE_OFFSET, type);
@@ -328,18 +217,12 @@
         }
         case HCI_TYPE_EVNT:
         {
-         //
          // Calculate the rest length of the data
-         //
             STREAM_TO_UINT8((char *)(evnt_buff + SPI_HEADER_SIZE), HCI_EVENT_LENGTH_OFFSET, data_to_recv);
          data_to_recv -= 1;
-
-         //
          // Add padding byte if needed
-         //
          if ((HEADERS_SIZE_EVNT + data_to_recv) & 1)
          {
-
                data_to_recv++;
          }
 
@@ -352,63 +235,15 @@
             break;
         }
     }
-
     return (0);
 }
 
 
-//*****************************************************************************
-//
-//! Pause SPI IRQ handling
-//!
-//!  \param  none
-//!
-//!  \return none
-//!
-//!  \brief  ... 
-//
-//*****************************************************************************
-void SpiPauseSpi(void)
-{
-   tSLInformation.WlanInterruptDisable();
-}
-
-
-//*****************************************************************************
-//
-//! Resume SPI IRQ handling
-//!
-//!  \param  none
-//!
-//!  \return none
-//!
-//!  \brief  .....
-//
-//*****************************************************************************
-void SpiResumeSpi(void)
-{
-   tSLInformation.WlanInterruptEnable();
-}
-
-//*****************************************************************************
-//
-//! Trigger RX processing
-//!
-//!  \param  SpiTriggerRxProcessing
-//!
-//!  \return none
-//!
-//!  \brief  The function triggers a user provided callback for
-//
-//*****************************************************************************
 void SpiTriggerRxProcessing(void)
 {
-   //
    // Trigger Rx processing
-   //
-   SpiPauseSpi();
-   wlan_cs = 1;
-
+   tSLInformation.WlanInterruptDisable();
+   WLAN_DEASSERT_CS;
    // The magic number resides at the end of the TX/RX buffer (1 byte after the allocated size)
    // If the magic number is overwitten - buffer overrun occurred - we will be stuck here forever!
    if (sSpiInformation.pRxPacket[CC3000_RX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER)
@@ -416,70 +251,36 @@
       printf("\nERROR: RX Buffer Overrun\n");
       while (1);
    }
-
    sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
    sSpiInformation.SPIRxHandler(sSpiInformation.pRxPacket + SPI_HEADER_SIZE);
 }
 
-//*****************************************************************************
-//
-//!  SPI interrupt Handler
-//!
-//!  \param  none
-//!
-//!  \return none
-//!
-//!  \brief  GPIO A interrupt handler. When the external WLAN device is
-//!          ready to interact with Host CPU it generates an interrupt signal.
-//!          The host CPU asserts CS to acknowledge the IRQ
-//
-//*****************************************************************************
+
 void WLAN_IRQHandler(void)
 {
-   // Clear pending interrupt
-//    NVIC_ClearPendingIRQ(PORTA_IRQn);
-//    WLAN_ISF_PCR  |= PORT_PCR_ISF_MASK;
-//    WLAN_ISF_ISFR |= WLAN_ISF_MASK;
-
-//IRQ_cnt++;
-//printf("I");
    if (sSpiInformation.ulSpiState == eSPI_STATE_POWERUP)
    {
-// -----------------------------  printf("IRQPU\n");
       // Inform HCI Layer that IRQ occured after powerup
       sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED;
    }
    else if (sSpiInformation.ulSpiState == eSPI_STATE_IDLE)
    {
-// -----------------------------  printf("IRQID\n");
       sSpiInformation.ulSpiState = eSPI_STATE_READ_IRQ;
       /* IRQ line goes low - acknowledge it */
-      wlan_cs = 0;
+      WLAN_ASSERT_CS;
       SpiReadHeader();
       sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT;
       SSIContReadOperation();
    }
    else if (sSpiInformation.ulSpiState == eSPI_STATE_WRITE_IRQ)
    {
-// -----------------------------  printf("IRQWI\n");
       SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength);
       sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
-      wlan_cs = 1;
+      WLAN_DEASSERT_CS;
    }
-// -----------------------------  printf("IRQ-E\n");
 }
 
-//*****************************************************************************
-//
-//! SSIContReadOperation
-//!
-//!  \param  none
-//!
-//!  \return none
-//!
-//!  \brief  ....
-//
-//*****************************************************************************
+
 void SSIContReadOperation(void)
 {
    // The header was read - continue with the payload read
@@ -490,13 +291,6 @@
    }
 }
 
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
 
 
 
-
--- a/CC3000_spi.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/CC3000_spi.h	Mon Jul 15 14:19:46 2013 +0000
@@ -37,23 +37,13 @@
 #ifndef __SPI_H__
 #define __SPI_H__
 
-//#include <stdlib.h>
-//#include <stdio.h>
-//#include "mbed.h"
 #include "GlobalAssigns.h"
 #include "hci.h"
-//#include "evnt_handler.h"
 
 /** CC3000 SPI library
 *
 */
 
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -100,10 +90,57 @@
 }tSpiInformation;
 
 extern unsigned char wlan_tx_buffer[];
+
+/**
+* First SPI write after powerup (delay needed between SPI header and body)
+* @param  pointer to write buffer
+* @param  buffer length
+* @return none
+*/
+long SpiFirstWrite(unsigned char *ucBuf, unsigned short usLength);
+
+/**
+* Low level SPI write
+* @param  pointer to data buffer
+* @param  number of bytes
+* @return none
+*/
 void SpiWriteDataSynchronous(unsigned char *data, unsigned short size);
-void SpiWriteAsync(const unsigned char *data, unsigned short size);
-void SpiPauseSpi(void);
-void SpiResumeSpi(void);
+
+/**
+* Low level SPI read
+* @param  pointer to data buffer
+* @param  number of bytes
+* @return none
+*/
+void SpiReadDataSynchronous(unsigned char *data, unsigned short size);
+
+/**
+* Read 5 SPI header bytes and 5 Event Data bytes
+* @param  none
+* @return none
+*/
+void SpiReadHeader(void);
+
+/**
+* Process the received SPI Header and in accordance with it - continue reading the packet
+* @param  None
+* @return 0
+*/
+long SpiReadDataCont(void);
+
+/**
+* Trigger RX processing
+* @param  SpiTriggerRxProcessing
+* @return none
+*/
+void SpiTriggerRxProcessing(void);
+
+/**
+* SSIContReadOperation
+* @param  none
+* @return none
+*/
 void SSIContReadOperation(void);
 
 //*****************************************************************************
@@ -111,15 +148,37 @@
 // Prototypes for the APIs.
 //
 //*****************************************************************************
+/**
+* Open the SPI interface
+* @param  pointer to RX handle
+* @return none
+*/
 extern void SpiOpen(gcSpiHandleRx pfRxHandler);
+
+/**
+* Close the SPI interface
+* @param  none
+* @return none
+*/
 extern void SpiClose(void);
+
+/**
+* SPI Write function
+* @param  pointer to write buffer
+* @param  buffer length
+* @return 0
+*/
 extern long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength);
-extern void SpiResumeSpi(void);
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
+
+/**
+* SPI interrupt Handler
+* The external WLAN device asserts the IRQ line when data is ready.
+* The host CPU needs to acknowledges the IRQ by asserting CS.
+* @param  none
+* @return none
+*/
+extern void WLAN_IRQHandler(void);
+
 #ifdef  __cplusplus
 }
 #endif // __cplusplus
@@ -127,3 +186,4 @@
 #endif
 
 
+
--- a/GlobalAssigns.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/GlobalAssigns.h	Mon Jul 15 14:19:46 2013 +0000
@@ -8,28 +8,37 @@
 //#define CC3000_TINY_DRIVER                // Driver for small memory model CPUs
 #define PATCHPROGRAMMER_ENABLE            // !!!Only enable this when you want to upload new firmware 
 
-// Wlan IRQ pin controls - used in WLAN_IRQHandler in CC3000_spi.cpp
-#define WLAN_ISF_PCR    PORTA->PCR[16]
-#define WLAN_ISF_ISFR   PORTA->ISFR
-#define WLAN_ISF_MASK   (1<<16)
+// Wlan controls
+#define WLAN_ISF_PCR        PORTA->PCR[16]
+#define WLAN_ISF_ISFR       PORTA->ISFR
+#define WLAN_ISF_MASK       (1<<16)
+
+#define WLAN_ASSERT_CS      wlan_cs = 0;   //CS : active low
+#define WLAN_DEASSERT_CS    wlan_cs = 1;
+
+#define WLAN_ASSERT_EN      wlan_en = 1;   //EN : active high
+#define WLAN_DEASSERT_EN    wlan_en = 0;
+
+#define WLAN_READ_IRQ       wlan_int
 
-// SPI control pins
-#define PIN_MOSI        PTD2
-#define PIN_MISO        PTD3
-#define PIN_SCLK        PTC5
+#define WLAN_ENABLE_IRQ     NVIC_EnableIRQ(PORTA_IRQn);
+#define WLAN_DISABLE_IRQ    NVIC_DisableIRQ(PORTA_IRQn);
 
-// CC3000 control pins
-#define PIN_WLAN_INT    PTA16
-#define PIN_WLAN_EN     PTA13
-#define PIN_WLAN_CS     PTD0
+#define WLAN_IRQ_PIN_CREATE         InterruptIn wlan_int (PTA16);
+#define WLAN_EN_PIN_CREATE          DigitalOut  wlan_en  (PTA13);
+#define WLAN_CS_PIN_CREATE          DigitalOut  wlan_cs  (PTD0);
+#define WLAN_SPI_PORT_CREATE        SPI wlan(PTD2, PTD3, PTC5); // mosi, miso, sclk
+
+#define WLAN_SPI_PORT_INIT          wlan.format(8,1);
+#define WLAN_SPI_SET_FREQ           wlan.frequency(12000000);
+#define WLAN_SPI_SET_IRQ_HANDLER    wlan_int.fall(&WLAN_IRQHandler);
+
+#define WLAN_SPI_WRITE              wlan.write(*data++);
+#define WLAN_SPI_READ               wlan.write(READ);
 
 extern DigitalOut  wlan_en;
 extern DigitalOut  wlan_cs;
 extern InterruptIn wlan_int;
-extern void WLAN_IRQHandler(void);
 extern SPI wlan;
-//extern int IRQ_cnt;
 
 #endif 
-
-
--- a/cc3000.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/cc3000.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -35,20 +35,17 @@
 
 #include "cc3000.h"
 
-InterruptIn wlan_int (PIN_WLAN_INT);
-DigitalOut  wlan_en  (PIN_WLAN_EN);
-DigitalOut  wlan_cs  (PIN_WLAN_CS);
-SPI wlan(PIN_MOSI, PIN_MISO, PIN_SCLK); // mosi, miso, sclk
+WLAN_IRQ_PIN_CREATE;
+WLAN_EN_PIN_CREATE;
+WLAN_CS_PIN_CREATE;
+WLAN_SPI_PORT_CREATE;
 
-//extern int ueh_enable;
-//
 // Smart Config Prefix
-//
 char aucCC3000_prefix[] = {'T', 'T', 'T'};
 
 long ulSocket;
 
-/** \brief Indicates whether the Smart Config Process has finished */
+// Indicates whether the Smart Config Process has finished
 unsigned long ulSmartConfigFinished;
 
 unsigned char pucIP_Addr[4];
@@ -68,9 +65,8 @@
 char debugi = 0;
 // First Time Config Prefix - Texas Instruments
 // NOTE: the actual value of the prefix may change
-// if the Prefix Change process is performed
+//       if the Prefix Change process is performed
 //const char aucCC3000_prefix[3] = {'T', 'T', 'T'};
-
 char cc3000state = CC3000_UNINIT;
 
 extern char OkToDoShutDown = 0;
@@ -80,20 +76,7 @@
 #else // ---------------------------------------------------------- PATCHPROGRAMMER_ENABLE end
 #endif  // -------------------------------------------------------- NON-PATCHPROGRAMMER_ENABLE end
 
-//*****************************************************************************
-//
-//! sendDriverPatch
-//!
-//! @param  pointer to the length
-//!
-//! @return none
-//!
-//! @brief  The function returns a pointer to the driver patch: since there is 
-//!         no patch (the patches are taken from the EEPROM and not from the 
-//!         host - it returns 0
-//!                
-//
-//*****************************************************************************
+
 char *sendDriverPatch(unsigned long *Length)
 {
     *Length = 0;
@@ -101,38 +84,12 @@
 }
 
 
-//*****************************************************************************
-//
-//! sendBootLoaderPatch
-//!
-//! @param  pointer to the length
-//!
-//! @return none
-//!
-//! @brief  The function returns a pointer to the bootloader patch: since there  
-//!         is no patch (the patches are taken from the EEPROM and not from the 
-//!         host - it returns 0
-//
-//*****************************************************************************
 char *sendBootLoaderPatch(unsigned long *Length)
 {
     *Length = 0;
     return NULL;
 }
 
-//*****************************************************************************
-//
-//! sendWLFWPatch
-//!
-//! @param  pointer to the length
-//!
-//! @return none
-//!
-//! @brief  The function returns a pointer to the firmware patch: since there is 
-//!         no patch (the patches are taken from the EEPROM and not from the 
-//!         host - it returns 0
-//
-//*****************************************************************************
 
 char *sendWLFWPatch(unsigned long *Length)
 {
@@ -140,42 +97,15 @@
     return NULL;
 }
 
-//*****************************************************************************
-//
-//! CC3000_UsynchCallback
-//!
-//! @param  lEventType  Event type
-//! @param  data
-//! @param  length
-//!
-//! @return none
-//!
-//! @brief  The function handles asynchronous events that come from CC3000  
-//!             device and operates a LED4 to have an on-board indication
-//
-//*****************************************************************************
 
 void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length)
 {
-    
 }
 
-//*****************************************************************************
-//
-//! initDriver
-//!
-//!  @param  cRequestPatch 0 to load with EEPROM patches and 1 to load with no patches
-//!
-//!  @return none
-//!
-//!  @brief  The function initializes a CC3000 device and triggers it to start 
-//           operation
-//
-//*****************************************************************************
+
 int initDriver(unsigned short cRequestPatch)
 {
     // WLAN On API Implementation
-//ueh_enable = 0;
     wlan_init( CC3000_UsynchCallback,
                sendWLFWPatch,
                sendDriverPatch,
@@ -185,10 +115,8 @@
                WlanInterruptDisable,
                WriteWlanPin);
     wait_us(450);
-//printf("\nWlan init done\n");    
     // Trigger a WLAN device
     wlan_start(cRequestPatch);
-//if(cRequestPatch == 0)  printf("\nWlan start done\n");    
     wlan_smart_config_set_prefix(aucCC3000_prefix);
 //    wlan_ioctl_set_connection_policy(0, 0, 0);  
 //    wlan_ioctl_del_profile(255);
@@ -198,36 +126,10 @@
                         HCI_EVNT_WLAN_UNSOL_INIT|
                         HCI_EVNT_WLAN_ASYNC_PING_REPORT);
     
-    // Check unsolicited events
-//    hci_unsolicited_event_handler();
-//ueh_enable = 1;
     return(0);
 }
 
 
-//*****************************************************************************
-//
-//! fat_read_content
-//!
-//! @param[out] is_allocated  array of is_allocated in FAT table:\n
-//!                         an allocated entry implies the address and length of the file are valid.
-//!                           0: not allocated; 1: allocated.
-//! @param[out] is_valid  array of is_valid in FAT table:\n
-//!                         a valid entry implies the content of the file is relevant.
-//!                           0: not valid; 1: valid.
-//! @param[out] write_protected  array of write_protected in FAT table:\n
-//!                         a write protected entry implies it is not possible to write into this entry.
-//!                           0: not protected; 1: protected.
-//! @param[out] file_address  array of file address in FAT table:\n
-//!                         this is the absolute address of the file in the EEPROM.
-//! @param[out] file_length  array of file length in FAT table:\n
-//!                         this is the upper limit of the file size in the EEPROM.
-//!
-//! @return on succes 0, error otherwise
-//!
-//! @brief  parse the FAT table from eeprom 
-//
-//*****************************************************************************
 unsigned char fat_read_content(unsigned char *is_allocated,
                                unsigned char *is_valid,
                                unsigned char *write_protected,
@@ -259,20 +161,7 @@
     return ucStatus;
 }
 
-//*****************************************************************************
-//
-//! fat_write_content
-//!
-//! @param[in] file_address  array of file address in FAT table:\n
-//!                         this is the absolute address of the file in the EEPROM.
-//! @param[in] file_length  array of file length in FAT table:\n
-//!                         this is the upper limit of the file size in the EEPROM.
-//!
-//! @return on succes 0, error otherwise
-//!
-//! @brief  parse the FAT table from eeprom 
-//
-//*****************************************************************************
+
 unsigned char fat_write_content(unsigned short const *file_address, unsigned short const *file_length)
 {
     unsigned short  index = 0;
@@ -309,118 +198,50 @@
     return ucStatus;
 }
 
-//*****************************************************************************
-//
-//! Init_HostDriver
-//!
-//! \param  none
-//!
-//! \return none
-//!
-//! \brief  Set basic controls and parameters for the HostDriver
-//
-//*****************************************************************************
+
 void Init_HostDriver(void)
 {
-    //Set Port A IRQ priority to a higher state
-//    NVIC_DisableIRQ(PORTA_IRQn); //__disable_irq();
-//    NVIC_SetPriority(PORTA_IRQn, 0);
-    //Ensure PTA4 pin (NMI input) is configured for GPIO output function and not NMI
-//    PORTA->PCR[4]  = PORT_PCR_MUX(1);    // GPIO is alt1 function for PTA4 pin
-//    PORTA->PCR[4] |= PORT_PCR_IRQC(0);   // Disable interrupts on PTA4 pin
-//    NVIC_EnableIRQ(PORTA_IRQn); //__enable_irq();
-
     // Clear pending interrupt
     WLAN_ISF_PCR  |= PORT_PCR_ISF_MASK;
     WLAN_ISF_ISFR |= WLAN_ISF_MASK;
     //Initial state for wlan module : EN = 0 (disabled) and CS = 1 (not selected).
-    wlan_en = 0;
-    wlan_cs = 1;
-
-    wlan.format(8,1);
-    wlan.frequency(12000000);
-    wlan_int.fall(&WLAN_IRQHandler);
-//    NVIC_DisableIRQ(PORTA_IRQn);
-
-}
-
-//*****************************************************************************
-//
-//! ReadWlanInterruptPin
-//!
-//! \param  none
-//!
-//! \return none
-//!
-//! \brief  return wlan interrup pin
-//
-//*****************************************************************************
-long ReadWlanInterruptPin(void)
-{
-    return (wlan_int);
-}
+    WLAN_DEASSERT_EN;
+    WLAN_DEASSERT_CS;
 
-//*****************************************************************************
-//
-//! Enable waln IrQ pin
-//!
-//! \param  none
-//!
-//! \return none
-//!
-//! \brief  Nonr
-//
-//*****************************************************************************
-void WlanInterruptEnable()
-{
-//printf("IE\n");
-//   wlan_int.fall(&WLAN_IRQHandler);
-//   wlan_int.mode(PullUp);
-    NVIC_EnableIRQ(PORTA_IRQn);
-}
-
-//*****************************************************************************
-//
-//! Disable waln IrQ pin
-//!
-//! \param  none
-//!
-//! \return none
-//!
-//! \brief  Nonr
-//
-//*****************************************************************************
-void WlanInterruptDisable()
-{
-NVIC_DisableIRQ(PORTA_IRQn);
-//    NVIC_ClearPendingIRQ(PORTA_IRQn);
-//    wlan_int.fall(NULL);
-   // Clear pending interrupt
-//   WLAN_ISF_PCR  |= PORT_PCR_ISF_MASK;
-//   WLAN_ISF_ISFR |= WLAN_ISF_MASK;
+    WLAN_SPI_PORT_INIT;
+    WLAN_SPI_SET_FREQ;
+    WLAN_SPI_SET_IRQ_HANDLER;
 }
 
 
-//*****************************************************************************
-//
-//! WriteWlanPin
-//!
-//! \param  new val
-//!
-//! \return none
-//!
-//! \brief  void
-//
-//*****************************************************************************
+long ReadWlanInterruptPin(void)
+{
+    return (WLAN_READ_IRQ);
+}
+
+
+void WlanInterruptEnable()
+{
+    WLAN_ENABLE_IRQ;
+}
+
+
+void WlanInterruptDisable()
+{
+    WLAN_DISABLE_IRQ;
+}
+
+
 void WriteWlanPin( unsigned char val )
 {
     if (val)
     {
-            wlan_en = 1;
+            WLAN_ASSERT_EN;
     }
     else
     {
-            wlan_en = 0;
+            WLAN_DEASSERT_EN;
     }
 }
 
+
--- a/cc3000.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/cc3000.h	Mon Jul 15 14:19:46 2013 +0000
@@ -36,7 +36,6 @@
 #ifndef CC3000_H
 #define CC3000_H
 
-//#include "mbed.h"
 #include "GlobalAssigns.h"
 #include "wlan.h"
 #include "evnt_handler.h"    // callback function declaration
@@ -47,7 +46,6 @@
 #include "cc3000_common.h"
 #include "CC3000_spi.h"
 #include "hci.h"
-//#include "cc3000.h"
 
 /** CC3000 Functions
 *
@@ -62,18 +60,17 @@
 
 #define FIRST_TIME_CONFIG_SET 0xAA
 
-#ifdef PATCHPROGRAMMER_ENABLE // ---------------------------------- PatchpProgrammer code
-
-    #define BIT0      0x1
-    #define BIT1      0x2
-    #define BIT2      0x4
-    #define BIT3      0x8
-    #define BIT4      0x10
-    #define BIT5      0x20
-    #define BIT6      0x40
-    #define BIT7      0x80
+#define BIT0      0x1
+#define BIT1      0x2
+#define BIT2      0x4
+#define BIT3      0x8
+#define BIT4      0x10
+#define BIT5      0x20
+#define BIT6      0x40
+#define BIT7      0x80
 
 
+#ifdef PATCHPROGRAMMER_ENABLE // ---------------------------------- PatchpProgrammer code
 #else // ---------------------------------------------------------- PATCHPROGRAMMER_ENABLE end
 #endif  // -------------------------------------------------------- NON-PATCHPROGRAMMER_ENABLE end
 
@@ -89,33 +86,122 @@
     CC3000_CLIENT_CONNECTED = 0x20  // CC3000 Client Connected to Server
 };
 
+/**
+*  Returns a pointer to the driver patch: since there is no patch, it returns 0
+*  (the patches are taken from the EEPROM and not from the host)
+*  @param  pointer to the length
+*  @return NULL
+*/ 
+char *sendDriverPatch(unsigned long *Length);
+
+/**
+* Returns a pointer to the bootloader patch: since there is no patch, it returns 0 
+* (the patches are taken from the EEPROM and not from the host)
+* @param  pointer to the length
+* @return NULL
+*/
+char *sendBootLoaderPatch(unsigned long *Length);
+
+/**
+* Returns a pointer to the firmware patch: since there is no patch, it returns 0
+* (the patches are taken from the EEPROM and not from the host)
+* @param  pointer to the length
+* @return NULL
+*/
+char *sendWLFWPatch(unsigned long *Length);
+
+/**
+* Handle asynchronous events from CC3000 device
+* @param  lEventType  Event type
+* @param  data
+* @param  length
+* @return none
+*/
+void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length);
+
+/**
+* Read Wlan Interrupt pin
+* @param  none
+* @return wlan interrup pin level
+*/
+long ReadWlanInterruptPin(void);
+
+/**
+* Enable waln IrQ pin
+* @param  none
+* @return none
+*/
+void WlanInterruptEnable(void);
+
+/**
+* Disable waln IrQ pin
+* @param  none
+* @return none
+*/
+void WlanInterruptDisable(void);
+
+/**
+* WriteWlanPin
+* @param  val (1: enable - 0: disable)
+* @return none
+*/
+void WriteWlanPin( unsigned char val );
+
+/**
+* Initialize a CC3000 device and triggers it to start operation
+* @param  cRequestPatch : 0 to load with EEPROM patches and 1 to load with no patches
+* @return none
+*/
+int initDriver(unsigned short cRequestPatch);
+
+/**
+* parse the FAT table from eeprom 
+* @param[out] is_allocated      array of is_allocated in FAT table (0: not allocated - 1: allocated).
+*                               an allocated entry implies the address and length of the file are valid.
+* @param[out] is_valid          array of is_valid in FAT table (0: not valid - 1: valid).
+*                               a valid entry implies the content of the file is relevant.
+* @param[out] write_protected   array of write_protected in FAT table (0: not allocated - 1: allocated).
+*                               a write protected entry implies it is not possible to write into this entry.
+* @param[out] file_address      array of file address in FAT table.
+*                               this is the absolute address of the file in the EEPROM.
+* @param[out] file_length       array of file length in FAT table.
+*                               this is the upper limit of the file size in the EEPROM.
+* @return 0 on succes, error otherwise
+*/
+unsigned char fat_read_content(unsigned char *is_allocated,
+                               unsigned char *is_valid,
+                               unsigned char *write_protected,
+                               unsigned short *file_address,
+                               unsigned short *file_length);
+
+/**
+* Parse the FAT table from eeprom 
+* @param[in] file_address  array of file address in FAT table.
+*                          this is the absolute address of the file in the EEPROM.
+* @param[in] file_length   array of file length in FAT table.
+*                          this is the upper limit of the file size in the EEPROM.
+* @return 0 on succes, error otherwise
+*/
+unsigned char fat_write_content(unsigned short const *file_address, unsigned short const *file_length);
+
+/**
+* Set basic controls and parameters for the HostDriver
+* @param  none
+* @return none
+*/
+extern void Init_HostDriver(void);
+
+
 int ConnectUsingSSID(char * ssidName);
 void SetupIPAddress (unsigned char ub, unsigned char mub, unsigned char mlb,unsigned char lb);
 void setupLocalSocket(void);
 void ConnectToServer(void);
 void ConnectToServer(void);
-
-char *sendDriverPatch(unsigned long *Length);
-char *sendBootLoaderPatch(unsigned long *Length);
-char *sendWLFWPatch(unsigned long *Length);
-long ReadWlanInterruptPin(void);
-void WlanInterruptEnable(void);
-void WlanInterruptDisable(void);
-void WriteWlanPin( unsigned char val );
-void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length);
 void unsolicicted_events_timer_init(void);
 void unsolicicted_events_timer_disable(void);
-int initDriver(unsigned short cRequestPatch);
 void StartFirstTimeConfig(void);
 void closeLocalSocket(void);
 void disconnectAll(void);
-unsigned char fat_read_content(unsigned char *is_allocated,
-                               unsigned char *is_valid,
-                               unsigned char *write_protected,
-                               unsigned short *file_address,
-                               unsigned short *file_length);
-unsigned char fat_write_content(unsigned short const *file_address, unsigned short const *file_length);
-
 char isFTCSet(void);
 void setFTCFlag(void);
 
@@ -129,8 +215,6 @@
 
 tNetappIpconfigRetArgs * getCC3000Info(void);
 
-//extern void SysTick_Handler(void);
-//extern int ueh_enable;
-extern void Init_HostDriver(void);
 
 #endif
+
--- a/cc3000_common.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/cc3000_common.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -32,55 +32,24 @@
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/
-//*****************************************************************************
-//
-//! \addtogroup common_api
-//! @{
-//
-//*****************************************************************************
-/******************************************************************************
- *
- * Include files
- *
- *****************************************************************************/
+
 #include "cc3000_common.h"
 #include "socket.h"
 #include "wlan.h"
 #include "evnt_handler.h"
 
-//*****************************************************************************
-//
-//!  __error__
-//!
-//!  @param  pcFilename - file name, where error occurred
-//!  @param  ulLine     - line number, where error occurred
-//!
-//!  @return none
-//!
-//!  @brief stub function for ASSERT macro
-//
-//*****************************************************************************
+/**
+* stub function for ASSERT macro
+* @param  pcFilename - file name, where error occurred
+* @param  ulLine     - line number, where error occurred
+* @return none
+*/
 void __error__(char *pcFilename, unsigned long ulLine)
 {
     //TODO: create function
 }
 
 
-
-//*****************************************************************************
-//
-//!  UINT32_TO_STREAM_f
-//!
-//!  @param  p       pointer to the new stream
-//!  @param  u32     pointer to the 32 bit
-//!
-//!  @return         pointer to the new stream
-//!
-//!  @brief          This function is used for copying 32 bit to stream
-//!                  while converting to little endian format.
-//
-//*****************************************************************************
-
 unsigned char* UINT32_TO_STREAM_f (unsigned char *p, unsigned long u32)
 {
     *(p)++ = (unsigned char)(u32);
@@ -90,19 +59,6 @@
     return p;
 }
 
-//*****************************************************************************
-//
-//!  UINT16_TO_STREAM_f
-//!
-//!  @param  p       pointer to the new stream
-//!  @param  u32     pointer to the 16 bit
-//!
-//!  @return         pointer to the new stream
-//!
-//!  @brief          This function is used for copying 16 bit to stream
-//!                  while converting to little endian format.
-//
-//*****************************************************************************
 
 unsigned char* UINT16_TO_STREAM_f (unsigned char *p, unsigned short u16)
 {
@@ -111,19 +67,6 @@
     return p;
 }
 
-//*****************************************************************************
-//
-//!  STREAM_TO_UINT16_f
-//!
-//!  @param  p          pointer to the stream
-//!  @param  offset     offset in the stream
-//!
-//!  @return            pointer to the new 16 bit
-//!
-//!  @brief             This function is used for copying received stream to
-//!                     16 bit in little endian format.
-//
-//*****************************************************************************
 
 unsigned short STREAM_TO_UINT16_f(char* p, unsigned short offset)
 {
@@ -131,19 +74,6 @@
                (*(p + offset + 1)) << 8) + (unsigned short)(*(p + offset)));
 }
 
-//*****************************************************************************
-//
-//!  STREAM_TO_UINT32_f
-//!
-//!  @param  p          pointer to the stream
-//!  @param  offset     offset in the stream
-//!
-//!  @return               pointer to the new 32 bit
-//!
-//!  @brief               This function is used for copying received stream to
-//!                       32 bit in little endian format.
-//
-//*****************************************************************************
 
 unsigned long STREAM_TO_UINT32_f(char* p, unsigned short offset)
 {
@@ -153,15 +83,3 @@
                (*(p + offset + 1)) << 8) + (unsigned long)(*(p + offset)));
 }
 
-
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
-
-
-
-
--- a/cc3000_common.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/cc3000_common.h	Mon Jul 15 14:19:46 2013 +0000
@@ -35,21 +35,12 @@
 #ifndef __COMMON_H__
 #define __COMMON_H__
 
-//******************************************************************************
-// Include files
-//******************************************************************************
-//#include "mbed.h"
 #include <errno.h>
 
 /** CC3000 Host driver - common
 *
 */
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -116,7 +107,7 @@
  
   The 1 is used for the overrun detection */ 
 
-#define  CC3000_MINIMAL_TX_SIZE      (118 + 1) 
+#define CC3000_MINIMAL_TX_SIZE      (118 + 1) 
 #define CC3000_MAXIMAL_TX_SIZE      (1519 + 1)
 
 //TX and RX buffer size - allow to receive and transmit maximum data at lengh 8.
@@ -151,24 +142,17 @@
 
 struct timeval 
 {
-    long         tv_sec;                  /* seconds */
-    long         tv_usec;                 /* microseconds */
+    long tv_sec;       /* seconds */
+    long tv_usec;      /* microseconds */
 };
 
 typedef char *(*tFWPatches)(unsigned long *usLength);
-
 typedef char *(*tDriverPatches)(unsigned long *usLength);
-
 typedef char *(*tBootLoaderPatches)(unsigned long *usLength);
-
 typedef void (*tWlanCB)(long event_type, char * data, unsigned char length );
-
 typedef long (*tWlanReadInteruptPin)(void);
-
 typedef void (*tWlanInterruptEnable)(void);
-
 typedef void (*tWlanInterruptDisable)(void);
-
 typedef void (*tWriteWlanPin)(unsigned char val);
 
 typedef struct
@@ -202,103 +186,53 @@
 // Prototypes for the APIs.
 //*****************************************************************************
 
-
-
-//*****************************************************************************
-//
-//!  SimpleLinkWaitEvent
-//!
-//!  @param  usOpcode      command operation code
-//!  @param  pRetParams    command return parameters
-//!
-//!  @return               none
-//!
-//!  @brief                Wait for event, pass it to the hci_event_handler and
-//!                        update the event opcode in a global variable.
-//
-//*****************************************************************************
-
+/**
+* Wait for event, pass it to the hci_event_handler and update the event opcode in a global variable.
+* @param  usOpcode      command operation code
+* @param  pRetParams    command return parameters
+* @return               none
+*/
 extern void SimpleLinkWaitEvent(unsigned short usOpcode, void *pRetParams);
 
-//*****************************************************************************
-//
-//!  SimpleLinkWaitData
-//!
-//!  @param  pBuf       data buffer
-//!  @param  from       from information
-//!  @param  fromlen    from information length
-//!
-//!  @return            none
-//!
-//!  @brief             Wait for data, pass it to the hci_event_handler and
-//!                     update in a global variable that there is data to read.
-//
-//*****************************************************************************
-
+/**
+* Wait for data, pass it to the hci_event_handler and update in a global variable that there is data to read.
+* @param  pBuf       data buffer
+* @param  from       from information
+* @param  fromlen    from information length
+* @return            none
+*/
 extern void SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, unsigned char *fromlen);
 
-//*****************************************************************************
-//
-//!  UINT32_TO_STREAM_f
-//!
-//!  \param  p       pointer to the new stream
-//!  \param  u32     pointer to the 32 bit
-//!
-//!  \return         pointer to the new stream
-//!
-//!  \brief          This function is used for copying 32 bit to stream
-//!                  while converting to little endian format.
-//
-//*****************************************************************************
-
+/**
+* Copy 32 bit to stream while converting to little endian format.
+* @param  p       pointer to the new stream
+* @param  u32     pointer to the 32 bit
+* @return         pointer to the new stream
+*/
 extern unsigned char* UINT32_TO_STREAM_f (unsigned char *p, unsigned long u32);
 
-//*****************************************************************************
-//
-//!  UINT16_TO_STREAM_f
-//!
-//!  \param  p       pointer to the new stream
-//!  \param  u32     pointer to the 16 bit
-//!
-//!  \return         pointer to the new stream
-//!
-//!  \brief         This function is used for copying 16 bit to stream 
-//!                 while converting to little endian format.
-//
-//*****************************************************************************
-
+/**
+* Copy 16 bit to stream while converting to little endian format.
+* @param  p       pointer to the new stream
+* @param  u32     pointer to the 16 bit
+* @return         pointer to the new stream
+*/
 extern unsigned char* UINT16_TO_STREAM_f (unsigned char *p, unsigned short u16);
 
-//*****************************************************************************
-//
-//!  STREAM_TO_UINT16_f
-//!
-//!  \param  p          pointer to the stream
-//!  \param  offset     offset in the stream
-//!
-//!  \return            pointer to the new 16 bit
-//!
-//!  \brief             This function is used for copying received stream to 
-//!                     16 bit in little endian format.
-//
-//*****************************************************************************
-
+/**
+* Copy received stream to 16 bit in little endian format.
+* @param  p          pointer to the stream
+* @param  offset     offset in the stream
+* @return            pointer to the new 16 bit
+*/
 extern unsigned short STREAM_TO_UINT16_f(char* p, unsigned short offset);
 
-//*****************************************************************************
-//
-//!  STREAM_TO_UINT32_f
-//!
-//!  \param  p          pointer to the stream
-//!  \param  offset     offset in the stream
-//!
-//!  \return            pointer to the new 32 bit
-//!
-//!  \brief             This function is used for copying received stream to
-//!                     32 bit in little endian format.
-//
-//*****************************************************************************
-
+/**
+* Copy received stream to 32 bit in little endian format.
+* @param  p          pointer to the stream
+* @param  offset     offset in the stream
+* @return            pointer to the new 32 bit
+*/
 extern unsigned long STREAM_TO_UINT32_f(char* p, unsigned short offset);
 
 
@@ -307,30 +241,22 @@
 //*****************************************************************************
 
 
-//This macro is used for copying 8 bit to stream while converting to little endian format.
+//Copy 8 bit to stream while converting to little endian format.
 #define UINT8_TO_STREAM(_p, _val)    {*(_p)++ = (_val);}
-//This macro is used for copying 16 bit to stream while converting to little endian format.
+//Copy 16 bit to stream while converting to little endian format.
 #define UINT16_TO_STREAM(_p, _u16)    (UINT16_TO_STREAM_f(_p, _u16))
-//This macro is used for copying 32 bit to stream while converting to little endian format.
+//Copy 32 bit to stream while converting to little endian format.
 #define UINT32_TO_STREAM(_p, _u32)    (UINT32_TO_STREAM_f(_p, _u32))
-//This macro is used for copying a specified value length bits (l) to stream while converting to little endian format.
+//Copy a specified value length bits (l) to stream while converting to little endian format.
 #define ARRAY_TO_STREAM(p, a, l)     {register short _i; for (_i = 0; _i < l; _i++) *(p)++ = ((unsigned char *) a)[_i];}
-//This macro is used for copying received stream to 8 bit in little endian format.
+//Copy received stream to 8 bit in little endian format.
 #define STREAM_TO_UINT8(_p, _offset, _u8)    {_u8 = (unsigned char)(*(_p + _offset));}
-//This macro is used for copying received stream to 16 bit in little endian format.
+//Copy received stream to 16 bit in little endian format.
 #define STREAM_TO_UINT16(_p, _offset, _u16)    {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
-//This macro is used for copying received stream to 32 bit in little endian format.
+//Copy received stream to 32 bit in little endian format.
 #define STREAM_TO_UINT32(_p, _offset, _u32)    {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
 #define STREAM_TO_STREAM(p, a, l)     {register short _i; for (_i = 0; _i < l; _i++) *(a)++= ((unsigned char *) p)[_i];}
 
-
-
-
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
 #ifdef  __cplusplus
 }
 #endif // __cplusplus
--- a/evnt_handler.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/evnt_handler.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -32,103 +32,22 @@
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/
-//*****************************************************************************
-//
-//! \addtogroup evnt_handler_api
-//! @{
-//
-//******************************************************************************
-
-//******************************************************************************
-//                  INCLUDE FILES
-//******************************************************************************
 
 #include "evnt_handler.h"
 
 //*****************************************************************************
-//                  COMMON DEFINES
-//*****************************************************************************
-
-#define FLOW_CONTROL_EVENT_HANDLE_OFFSET        (0)
-#define FLOW_CONTROL_EVENT_BLOCK_MODE_OFFSET    (1)
-#define FLOW_CONTROL_EVENT_FREE_BUFFS_OFFSET    (2)
-#define FLOW_CONTROL_EVENT_SIZE                 (4)
-
-#define BSD_RSP_PARAMS_SOCKET_OFFSET            (0)
-#define BSD_RSP_PARAMS_STATUS_OFFSET            (4)
-
-#define GET_HOST_BY_NAME_RETVAL_OFFSET          (0)
-#define GET_HOST_BY_NAME_ADDR_OFFSET            (4)
-
-#define ACCEPT_SD_OFFSET                        (0)
-#define ACCEPT_RETURN_STATUS_OFFSET             (4)
-#define ACCEPT_ADDRESS__OFFSET                  (8)
-
-#define SL_RECEIVE_SD_OFFSET                    (0)
-#define SL_RECEIVE_NUM_BYTES_OFFSET             (4)
-#define SL_RECEIVE__FLAGS__OFFSET               (8)
-
-
-#define SELECT_STATUS_OFFSET                    (0)
-#define SELECT_READFD_OFFSET                    (4)
-#define SELECT_WRITEFD_OFFSET                   (8)
-#define SELECT_EXFD_OFFSET                      (12)
-
-
-#define NETAPP_IPCONFIG_IP_OFFSET               (0)
-#define NETAPP_IPCONFIG_SUBNET_OFFSET           (4)
-#define NETAPP_IPCONFIG_GW_OFFSET               (8)
-#define NETAPP_IPCONFIG_DHCP_OFFSET             (12)
-#define NETAPP_IPCONFIG_DNS_OFFSET              (16)
-#define NETAPP_IPCONFIG_MAC_OFFSET              (20)
-#define NETAPP_IPCONFIG_SSID_OFFSET             (26)
-
-#define NETAPP_IPCONFIG_IP_LENGTH               (4)
-#define NETAPP_IPCONFIG_MAC_LENGTH              (6)
-#define NETAPP_IPCONFIG_SSID_LENGTH             (32)
-
-
-#define NETAPP_PING_PACKETS_SENT_OFFSET         (0)
-#define NETAPP_PING_PACKETS_RCVD_OFFSET         (4)
-#define NETAPP_PING_MIN_RTT_OFFSET              (8)
-#define NETAPP_PING_MAX_RTT_OFFSET              (12)
-#define NETAPP_PING_AVG_RTT_OFFSET              (16)
-
-#define GET_SCAN_RESULTS_TABlE_COUNT_OFFSET              (0)
-#define GET_SCAN_RESULTS_SCANRESULT_STATUS_OFFSET        (4)
-#define GET_SCAN_RESULTS_ISVALID_TO_SSIDLEN_OFFSET       (8)
-#define GET_SCAN_RESULTS_FRAME_TIME_OFFSET               (10)
-#define GET_SCAN_RESULTS_SSID_MAC_LENGTH                 (38)
-
-
-
-//*****************************************************************************
 //                  GLOBAL VARAIABLES
 //*****************************************************************************
-
 unsigned long socket_active_status = SOCKET_STATUS_INIT_VAL; 
 
 
 //*****************************************************************************
 //            Prototypes for the static functions
 //*****************************************************************************
-
 static long hci_event_unsol_flowcontrol_handler(char *pEvent);
-
 static void update_socket_active_status(char *resp_params);
 
 
-//*****************************************************************************
-//
-//!  hci_unsol_handle_patch_request
-//!
-//!  @param  event_hdr  event header
-//!
-//!  @return none
-//!
-//!  @brief   Handle unsolicited event from type patch request
-//
-//*****************************************************************************
 void hci_unsol_handle_patch_request(char *event_hdr)
 {
     char *params = (char *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
@@ -144,14 +63,12 @@
             
             if (patch)
             {
-// -----------------------------  printf("HCI_EVENT_PATCHES_DRV_REQ\n");
                 hci_patch_send(HCI_EVENT_PATCHES_DRV_REQ, tSLInformation.pucTxCommandBuffer, patch, ucLength);
                 return;
             }
         }
         
         // Send 0 length Patches response event
-// -----------------------------  printf("HCI_EVENT_PATCHES_DRV_REQ - NULL\n");
         hci_patch_send(HCI_EVENT_PATCHES_DRV_REQ, tSLInformation.pucTxCommandBuffer, 0, 0);
         break;
         
@@ -164,25 +81,19 @@
             // Build and send a patch
             if (patch)
             {
-// -----------------------------  printf("HCI_EVENT_PATCHES_FW_REQ\n");
                 hci_patch_send(HCI_EVENT_PATCHES_FW_REQ, tSLInformation.pucTxCommandBuffer, patch, ucLength);
                 return;
             }
         }
         
         // Send 0 length Patches response event
-// -----------------------------  printf("HCI_EVENT_PATCHES_FW_REQ - NULL\n");
-//printf("HEPFR  %04X\n",HCI_EVENT_PATCHES_FW_REQ);
-//printf("pucTCB %04X\n",*tSLInformation.pucTxCommandBuffer);
         hci_patch_send(HCI_EVENT_PATCHES_FW_REQ, tSLInformation.pucTxCommandBuffer, 0, 0);
-//printf("HEPFR-E\n");
         break;
         
     case HCI_EVENT_PATCHES_BOOTLOAD_REQ:
         
         if (tSLInformation.sBootLoaderPatches)
         {
-// -----------------------------  printf("HCI_EVENT_PATCHES_BOOTLOAD_REQ\n");
             patch = tSLInformation.sBootLoaderPatches(&ucLength);
             if (patch)
             {
@@ -192,30 +103,12 @@
         }
         
         // Send 0 length Patches response event
-// -----------------------------  printf("HCI_EVENT_PATCHES_BOOTLOAD_REQ - NULL\n");
         hci_patch_send(HCI_EVENT_PATCHES_BOOTLOAD_REQ, tSLInformation.pucTxCommandBuffer, 0, 0);
         break;
     }
 }
 
 
-
-//*****************************************************************************
-//
-//!  hci_event_handler
-//!
-//!  @param  pRetParams     incoming data buffer
-//!  @param  from           from information (in case of data received)
-//!  @param  fromlen        from information length (in case of data received)
-//!
-//!  @return         none
-//!
-//!  @brief          Parse the incoming events packets and issues corresponding
-//!                  event handler from global array of handlers pointers
-//
-//*****************************************************************************
-
-    
 unsigned char *hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen)
 {
     unsigned char *pucReceivedData, ucArgsize;
@@ -225,27 +118,20 @@
     unsigned long retValue32;
     unsigned char * RecvParams;
     unsigned char *RetParams;
-//    unsigned long tout_cnt = 0;
     while (1)
     {
         if (tSLInformation.usEventOrDataReceived != 0)
         {                
             pucReceivedData = (tSLInformation.pucReceivedData);
-// -----------------------------  if((*((char *)(pucReceivedData) + HCI_EVENT_HEADER_SIZE)) == HCI_EVENT_PATCHES_FW_REQ)
-// -----------------------------  printf("%02X\n",tSLInformation.usEventOrDataReceived);
-// -----------------------------  printf("pucReceivedData : %04X\n",*pucReceivedData);
-
             if (*pucReceivedData == HCI_TYPE_EVNT)
             {
                 // Event Received
-//printf("STREAM - usReceivedEventOpcode : %04X\n",usReceivedEventOpcode);
                 STREAM_TO_UINT16((char *)pucReceivedData, HCI_EVENT_OPCODE_OFFSET,usReceivedEventOpcode);
                 pucReceivedParams = pucReceivedData + HCI_EVENT_HEADER_SIZE;        
-//printf("STREAM - usReceivedEventOpcode : %04X\n",usReceivedEventOpcode);
                 RecvParams = pucReceivedParams;
                 RetParams = (unsigned char *)pRetParams;
                 
-                // In case unsolicited event received - here the handling finished
+                // unsolicited event received - finish handling
                 if (hci_unsol_event_handler((char *)pucReceivedData) == 0)
                 {
                     STREAM_TO_UINT8(pucReceivedData, HCI_DATA_LENGTH_OFFSET, usLength);
@@ -417,9 +303,6 @@
     
                     }
                 }
-// -----------------------------  printf("  REO : %04X\n",usReceivedEventOpcode);
-// -----------------------------  printf("RxREO : %04X\n",tSLInformation.usRxEventOpcode);
-                
                 if (usReceivedEventOpcode == tSLInformation.usRxEventOpcode)
                 {
                     tSLInformation.usRxEventOpcode = 0;
@@ -447,83 +330,22 @@
         
             tSLInformation.usEventOrDataReceived = 0;
             
-            SpiResumeSpi();
+            tSLInformation.WlanInterruptEnable();
             
             // Since we are going to TX - we need to handle this event after the ResumeSPi since we need interrupts
             if ((*pucReceivedData == HCI_TYPE_EVNT) && (usReceivedEventOpcode == HCI_EVNT_PATCHES_REQ))
             {
-// -----------------------------  printf("HUHPR\n");
-
                 hci_unsol_handle_patch_request((char *)pucReceivedData);
-//int we = wlan_en;
-//int wc = wlan_cs;
-//int wi = tSLInformation.ReadWlanInterruptPin(); //wlan_int
-//printf("%02X %02X %02X\n",we, wc, wi);
-//printf("%02X %02X \n",tSLInformation.usRxEventOpcode,tSLInformation.usRxDataPending);
             }
-//if((*((char *)(pucReceivedData) + HCI_EVENT_HEADER_SIZE)) == HCI_EVENT_PATCHES_FW_REQ)
-//printf("%02X\n",tSLInformation.usEventOrDataReceived);
-//printf("%02X %02X\n",tSLInformation.usRxEventOpcode,tSLInformation.usRxDataPending);
-//Re-enable printf in IRQ
-//tSLInformation.usEventOrDataReceived is at least once = 1 for all previous calls, why not for HCI_EVENT_PATCHES_FW_REQ?
-//compare with original code (uVision - add printfs in evnt_handler and try to find out where/how tSLInformation.usEventOrDataReceived is modified)
-//call hci_unsolicited_event_handler in hci_unsol_handle_patch_request??
-//try no-systick modifs in Jim's V3.1??
-//Is the latest original TI code working??
             if ((tSLInformation.usRxEventOpcode == 0) && (tSLInformation.usRxDataPending == 0))
             {
-// -----------------------------  printf("EXIT\n");
                 return NULL;
             }    
-/*
-//Check if interrupts are still active :
-//When we enable this code, an interrupt is detected - read back = R 10 : 02 00 FF 00 00 00 00 00 00 00
-//                                                     should be = R 10 : 02 00 00 00 05 04 00 40 01 00
-//Perhaps the last write (HCI_EVENT_PATCHES_FW_REQ) was incorrect?
-if(((*((char *)(pucReceivedData) + HCI_EVENT_HEADER_SIZE)) == HCI_EVENT_PATCHES_FW_REQ) && (wlan_cs == 1))
-{
-wlan_cs = 0;
-}*/
         }
-
-//if(*((char *)(pucReceivedData) + HCI_EVENT_HEADER_SIZE) == HCI_EVENT_PATCHES_FW_REQ) && ()
-/*tout_cnt++;
-if(((*((char *)(pucReceivedData) + HCI_EVENT_HEADER_SIZE)) == HCI_EVENT_PATCHES_FW_REQ) && (tout_cnt > 25000000))
-{
-    printf("ERROR\n");
-    int we = wlan_en;
-    int wc = wlan_cs;
-    int wi = tSLInformation.ReadWlanInterruptPin(); //wlan_int
-    printf("tSLInformation.usRxEventOpcode : %04X\n",tSLInformation.usRxEventOpcode);
-    printf("tSLInformation.usRxDataPending : %u\n",tSLInformation.usRxDataPending);
-    printf("WLAN int pin : %u\n",wi);
-    printf("WLAN en  pin : %u\n",we);
-    printf("WLAN cs  pin : %u\n",wc);
-    printf("*(pucReceivedData + HCI_EVENT_HEADER_SIZE) : %04X\n",*(pucReceivedData + HCI_EVENT_HEADER_SIZE));
-    printf("usReceivedEventOpcode : %04X\n",usReceivedEventOpcode);
-    printf("pucReceivedData : %04X\n",*pucReceivedData);
-    printf("HCI_EVENT_HEADER_SIZE    : %02X\n",HCI_EVENT_HEADER_SIZE);
-    printf("HCI_EVENT_PATCHES_FW_REQ : %02X\n",HCI_EVENT_PATCHES_FW_REQ);
-    printf("HCI_TYPE_EVNT            : %02X\n",HCI_TYPE_EVNT);
-    printf("HCI_EVNT_PATCHES_REQ     : %02X\n\n",HCI_EVNT_PATCHES_REQ);
-    while(1){}
-}*/
-//printf(".");
     }
 }
 
-//*****************************************************************************
-//
-//!  hci_unsol_event_handler
-//!
-//!  @param  event_hdr   event header
-//!
-//!  @return             1 if event supported and handled
-//!                      0 if event is not supported
-//!
-//!  @brief              Handle unsolicited events
-//
-//*****************************************************************************
+
 long hci_unsol_event_handler(char *event_hdr)
 {
     char * data = NULL;
@@ -648,23 +470,11 @@
     return(0);
 }
 
-//*****************************************************************************
-//
-//!  hci_unsolicited_event_handler
-//!
-//!  @param None
-//!
-//!  @return         ESUCCESS if successful, EFAIL if an error occurred
-//!
-//!  @brief          Parse the incoming unsolicited event packets and issues 
-//!                  corresponding event handler.
-//
-//*****************************************************************************
+
 long hci_unsolicited_event_handler(void)
 {
-    unsigned long   res = 0;
+    unsigned long res = 0;
     unsigned char *pucReceivedData;
-// -----------------------------  printf("UEH\n");    
     if (tSLInformation.usEventOrDataReceived != 0)
     {
         pucReceivedData = (tSLInformation.pucReceivedData);
@@ -672,34 +482,23 @@
         if (*pucReceivedData == HCI_TYPE_EVNT)
         {            
             
-            // In case unsolicited event received - here the handling finished
+            // unsolicited event received - finish handling
             if (hci_unsol_event_handler((char *)pucReceivedData) == 1)
             {
                 
-                // There was an unsolicited event received - we can release the buffer
-                // and clean the event received 
+                // An unsolicited event was received:
+                // release the buffer and clean the event received 
                 tSLInformation.usEventOrDataReceived = 0;
                 
                 res = 1;
-                SpiResumeSpi();
+                tSLInformation.WlanInterruptEnable();
             }
         }
     }
     return res;
 }
 
-//*****************************************************************************
-//
-//!  set_socket_active_status
-//!
-//!  @param Sd
-//!     @param Status
-//!  @return         none
-//!
-//!  @brief          Check if the socket ID and status are valid and set 
-//!                  accordingly  the global socket status
-//
-//*****************************************************************************
+
 void set_socket_active_status(long Sd, long Status)
 {
     if(M_IS_VALID_SD(Sd) && M_IS_VALID_STATUS(Status))
@@ -710,19 +509,6 @@
 }
 
 
-//*****************************************************************************
-//
-//!  hci_event_unsol_flowcontrol_handler
-//!
-//!  @param  pEvent  pointer to the string contains parameters for IPERF
-//!  @return         ESUCCESS if successful, EFAIL if an error occurred
-//!
-//!  @brief  Called in case unsolicited event from type
-//!          HCI_EVNT_DATA_UNSOL_FREE_BUFF has received.
-//!                   Keep track on the number of packets transmitted and update the
-//!                     number of free buffer in the SL device.
-//
-//*****************************************************************************
 long hci_event_unsol_flowcontrol_handler(char *pEvent)
 {
     
@@ -748,16 +534,6 @@
     return(ESUCCESS);
 }
 
-//*****************************************************************************
-//
-//!  get_socket_active_status
-//!
-//!  @param  Sd  Socket IS
-//!  @return     Current status of the socket.   
-//!
-//!  @brief  Retrieve socket status
-//
-//*****************************************************************************
 
 long get_socket_active_status(long Sd)
 {
@@ -768,16 +544,7 @@
     return SOCKET_STATUS_INACTIVE;
 }
 
-//*****************************************************************************
-//
-//!  update_socket_active_status
-//!
-//!  @param  resp_params  Socket IS
-//!  @return     Current status of the socket.   
-//!
-//!  @brief  Retrieve socket status
-//
-//*****************************************************************************
+
 void update_socket_active_status(char *resp_params)
 {
     long status, sd;
@@ -792,48 +559,16 @@
 }
 
 
-//*****************************************************************************
-//
-//!  SimpleLinkWaitEvent
-//!
-//!  @param  usOpcode      command operation code
-//!  @param  pRetParams    command return parameters
-//!
-//!  @return               none
-//!
-//!  @brief                Wait for event, pass it to the hci_event_handler and
-//!                        update the event opcode in a global variable.
-//
-//*****************************************************************************
-
 void SimpleLinkWaitEvent(unsigned short usOpcode, void *pRetParams)
 {
-//printf("SLWE-I\n");
     // In the blocking implementation the control to caller will be returned only 
     // after the end of current transaction
     tSLInformation.usRxEventOpcode = usOpcode;
     hci_event_handler(pRetParams, 0, 0);
-//printf("SLWE-E\n");
 }
 
-//*****************************************************************************
-//
-//!  SimpleLinkWaitData
-//!
-//!  @param  pBuf       data buffer
-//!  @param  from       from information
-//!  @param  fromlen    from information length
-//!
-//!  @return               none
-//!
-//!  @brief                Wait for data, pass it to the hci_event_handler
-//!                        and update in a global variable that there is 
-//!                           data to read.
-//
-//*****************************************************************************
 
-void 
-SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, unsigned char *fromlen)
+void SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, unsigned char *fromlen)
 {
     // In the blocking implementation the control to caller will be returned only 
     // after the end of current transaction, i.e. only after data will be received
@@ -841,13 +576,3 @@
     hci_event_handler(pBuf, from, fromlen);
 }
 
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
-
-
-
-
--- a/evnt_handler.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/evnt_handler.h	Mon Jul 15 14:19:46 2013 +0000
@@ -35,7 +35,6 @@
 #ifndef __EVENT_HANDLER_H__
 #define __EVENT_HANDLER_H__
 
-//#include "mbed.h"
 #include "cc3000_common.h"
 #include "hci.h"
 #include "wlan.h"
@@ -46,66 +45,104 @@
 /** CC3000 Host driver - event handler
 *
 */
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
 //*****************************************************************************
+//                  COMMON DEFINES
+//*****************************************************************************
+
+#define FLOW_CONTROL_EVENT_HANDLE_OFFSET        (0)
+#define FLOW_CONTROL_EVENT_BLOCK_MODE_OFFSET    (1)
+#define FLOW_CONTROL_EVENT_FREE_BUFFS_OFFSET    (2)
+#define FLOW_CONTROL_EVENT_SIZE                 (4)
+
+#define BSD_RSP_PARAMS_SOCKET_OFFSET            (0)
+#define BSD_RSP_PARAMS_STATUS_OFFSET            (4)
+
+#define GET_HOST_BY_NAME_RETVAL_OFFSET          (0)
+#define GET_HOST_BY_NAME_ADDR_OFFSET            (4)
+
+#define ACCEPT_SD_OFFSET                        (0)
+#define ACCEPT_RETURN_STATUS_OFFSET             (4)
+#define ACCEPT_ADDRESS__OFFSET                  (8)
+
+#define SL_RECEIVE_SD_OFFSET                    (0)
+#define SL_RECEIVE_NUM_BYTES_OFFSET             (4)
+#define SL_RECEIVE__FLAGS__OFFSET               (8)
+
+
+#define SELECT_STATUS_OFFSET                    (0)
+#define SELECT_READFD_OFFSET                    (4)
+#define SELECT_WRITEFD_OFFSET                   (8)
+#define SELECT_EXFD_OFFSET                      (12)
+
+
+#define NETAPP_IPCONFIG_IP_OFFSET               (0)
+#define NETAPP_IPCONFIG_SUBNET_OFFSET           (4)
+#define NETAPP_IPCONFIG_GW_OFFSET               (8)
+#define NETAPP_IPCONFIG_DHCP_OFFSET             (12)
+#define NETAPP_IPCONFIG_DNS_OFFSET              (16)
+#define NETAPP_IPCONFIG_MAC_OFFSET              (20)
+#define NETAPP_IPCONFIG_SSID_OFFSET             (26)
+
+#define NETAPP_IPCONFIG_IP_LENGTH               (4)
+#define NETAPP_IPCONFIG_MAC_LENGTH              (6)
+#define NETAPP_IPCONFIG_SSID_LENGTH             (32)
+
+
+#define NETAPP_PING_PACKETS_SENT_OFFSET         (0)
+#define NETAPP_PING_PACKETS_RCVD_OFFSET         (4)
+#define NETAPP_PING_MIN_RTT_OFFSET              (8)
+#define NETAPP_PING_MAX_RTT_OFFSET              (12)
+#define NETAPP_PING_AVG_RTT_OFFSET              (16)
+
+#define GET_SCAN_RESULTS_TABlE_COUNT_OFFSET              (0)
+#define GET_SCAN_RESULTS_SCANRESULT_STATUS_OFFSET        (4)
+#define GET_SCAN_RESULTS_ISVALID_TO_SSIDLEN_OFFSET       (8)
+#define GET_SCAN_RESULTS_FRAME_TIME_OFFSET               (10)
+#define GET_SCAN_RESULTS_SSID_MAC_LENGTH                 (38)
+
+//*****************************************************************************
 //
 // Prototypes for the APIs.
 //
 //*****************************************************************************
 
-//*****************************************************************************
-//
-//!  hci_event_handler
-//!
-//!  @param  pRetParams     incoming data buffer
-//!  @param  from           from information (in case of data received)
-//!  @param  fromlen        from information length (in case of data received)
-//!
-//!  @return         none
-//!
-//!  @brief          Parse the incoming events packets and issues corresponding
-//!                  event handler from global array of handlers pointers
-//
-//*****************************************************************************
+/** Handle unsolicited event from type patch request
+* @param  event_hdr  event header
+* @return none
+*/
+void hci_unsol_handle_patch_request(char *event_hdr);
+
+
+/**
+* Parse the incoming event packets and issue corresponding event handler from global array of handlers pointers
+* @param  pRetParams     incoming data buffer
+* @param  from           from information (in case of data received)
+* @param  fromlen        from information length (in case of data received)
+* @return                none
+*/    
 extern unsigned char *hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen);
 
-//*****************************************************************************
-//
-//!  hci_unsol_event_handler
-//!
-//!  @param  event_hdr   event header
-//!
-//!  @return             1 if event supported and handled
-//!                      0 if event is not supported
-//!
-//!  @brief              Handle unsolicited events
-//
-//*****************************************************************************
+/**
+* Handle unsolicited events
+* @param  event_hdr   event header
+* @return             1 if event supported and handled
+* @return             0 if event is not supported
+*/
 extern long hci_unsol_event_handler(char *event_hdr);
 
-//*****************************************************************************
-//
-//!  hci_unsolicited_event_handler
-//!
-//!  @param None
-//!
-//!  @return         ESUCCESS if successful, EFAIL if an error occurred
-//!
-//!  @brief          Parse the incoming unsolicited event packets and issues 
-//!                  corresponding event handler.
-//
-//*****************************************************************************
+/**
+* Parse the incoming unsolicited event packets and start corresponding event handler.
+* @param   None
+* @return  ESUCCESS if successful, EFAIL if an error occurred
+*/
 extern long hci_unsolicited_event_handler(void);
 
+
 #define M_BSD_RESP_PARAMS_OFFSET(hci_event_hdr)((char *)(hci_event_hdr) + HCI_EVENT_HEADER_SIZE)
 
 #define SOCKET_STATUS_ACTIVE       0
@@ -118,9 +155,54 @@
 
 extern unsigned long socket_active_status;
 
+/**
+* Check if the socket ID and status are valid and set the global socket status accordingly.
+* @param   Sd
+* @param   Status
+* @return  none
+*/
 extern void set_socket_active_status(long Sd, long Status);
+
+/**
+* Keep track on the number of packets transmitted and update the number of free buffer in the SL device.
+* Called when unsolicited event = HCI_EVNT_DATA_UNSOL_FREE_BUFF has received.
+* @param  pEvent  pointer to the string contains parameters for IPERF
+* @return         ESUCCESS if successful, EFAIL if an error occurred
+*/
+long hci_event_unsol_flowcontrol_handler(char *pEvent);
+
+/**
+* Get the socket status
+* @param  Sd  Socket IS
+* @return     Current status of the socket.   
+*/
 extern long get_socket_active_status(long Sd);
 
+/**
+* Update the socket status
+* @param      resp_params  Socket IS
+* @return     Current status of the socket.   
+*/
+void update_socket_active_status(char *resp_params);
+
+/**
+* Wait for event, pass it to the hci_event_handler and update the event opcode in a global variable.
+* @param  usOpcode      command operation code
+* @param  pRetParams    command return parameters
+* @return               none
+*/
+void SimpleLinkWaitEvent(unsigned short usOpcode, void *pRetParams);
+
+/**
+* Wait for data, pass it to the hci_event_handler and set the data available flag 
+* @param  pBuf       data buffer
+* @param  from       from information
+* @param  fromlen    from information length
+* @return            none
+*/
+void SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, unsigned char *fromlen);
+
+
 typedef struct _bsd_accept_return_t
 {
     long             iSocketDescriptor;
@@ -134,7 +216,7 @@
 {
     long             iSocketDescriptor;
     long             iNumberOfBytes;
-    unsigned long     uiFlags;
+    unsigned long    uiFlags;
 } tBsdReadReturnParams;
 
 #define BSD_RECV_FROM_FROMLEN_OFFSET    (4)
@@ -152,21 +234,16 @@
 
 typedef struct _bsd_getsockopt_return_t
 {
-    unsigned char            ucOptValue[4];
-    char                     iStatus;
+    unsigned char ucOptValue[4];
+    char          iStatus;
 } tBsdGetSockOptReturnParams;
 
 typedef struct _bsd_gethostbyname_return_t
 {
-    long             retVal;
-    long             outputAddress;
+    long  retVal;
+    long  outputAddress;
 } tBsdGethostbynameParams;
 
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
 #ifdef  __cplusplus
 }
 #endif // __cplusplus
--- a/hci.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/hci.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -33,30 +33,8 @@
 *
 *****************************************************************************/
 
-//*****************************************************************************
-//
-//! \addtogroup hci_app
-//! @{
-//
-//*****************************************************************************
-
 #include "hci.h"
-#define SL_PATCH_PORTION_SIZE        (1000)
-
 
-//*****************************************************************************
-//
-//!  hci_command_send
-//!
-//!  @param  usOpcode     command operation code
-//!  @param  pucBuff      pointer to the command's arguments buffer
-//!  @param  ucArgsLength length of the arguments
-//!
-//!  @return              none
-//!
-//!  @brief               Initiate an HCI command.
-//
-//*****************************************************************************
 unsigned short hci_command_send(unsigned short usOpcode, unsigned char *pucBuff, unsigned char ucArgsLength)
 { 
     unsigned char *stream;
@@ -68,25 +46,10 @@
     UINT8_TO_STREAM(stream, ucArgsLength);
     //Update the opcode of the event we will be waiting for
     SpiWrite(pucBuff, ucArgsLength + SIMPLE_LINK_HCI_CMND_HEADER_SIZE);
-//printf("HCS-E\n");
     return(0);
 }
 
-//*****************************************************************************
-//
-//!  hci_data_send
-//!
-//!  @param  usOpcode        command operation code
-//!  @param  ucArgs          pointer to the command's arguments buffer
-//!  @param  usArgsLength    length of the arguments
-//!  @param  ucTail          pointer to the data buffer
-//!  @param  usTailLength    buffer length
-//!
-//!  @return none
-//!
-//!  @brief              Initiate an HCI data write operation
-//
-//*****************************************************************************
+
 long hci_data_send(unsigned char ucOpcode, 
                    unsigned char *ucArgs,
                    unsigned short usArgsLength, 
@@ -103,27 +66,13 @@
     UINT8_TO_STREAM(stream, usArgsLength);
     stream = UINT16_TO_STREAM(stream, usArgsLength + usDataLength + usTailLength);
     
-    // Send the packet over the SPI
+    // Send the packet
     SpiWrite(ucArgs, SIMPLE_LINK_HCI_DATA_HEADER_SIZE + usArgsLength + usDataLength + usTailLength);
     
     return(ESUCCESS);
 }
 
 
-//*****************************************************************************
-//
-//!  hci_data_command_send
-//!
-//!  @param  usOpcode      command operation code
-//!  @param  pucBuff       pointer to the data buffer
-//!  @param  ucArgsLength  arguments length
-//!  @param  ucDataLength  data length
-//!
-//!  @return none
-//!
-//!  @brief              Prepeare HCI header and initiate an HCI data write operation
-//
-//*****************************************************************************
 void hci_data_command_send(unsigned short usOpcode,
                            unsigned char *pucBuff,
                            unsigned char ucArgsLength,
@@ -136,32 +85,18 @@
     UINT8_TO_STREAM(stream, ucArgsLength);
     stream = UINT16_TO_STREAM(stream, ucArgsLength + ucDataLength);
     
-    // Send the command over SPI on data channel
+    // Send the command
     SpiWrite(pucBuff, ucArgsLength + ucDataLength + SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE);
     
     return;
 }
 
-//*****************************************************************************
-//
-//!  hci_patch_send
-//!
-//!  @param  usOpcode      command operation code
-//!  @param  pucBuff       pointer to the command's arguments buffer
-//!  @param  patch         pointer to patch content buffer 
-//!  @param  usDataLength  data length
-//!
-//!  @return              none
-//!
-//!  @brief               Prepeare HCI header and initiate an HCI patch write operation
-//
-//*****************************************************************************
+
 void hci_patch_send(unsigned char ucOpcode,
                     unsigned char *pucBuff,
                     char *patch,
                     unsigned short usDataLength)
 { 
-    unsigned char *data_ptr = (pucBuff + SPI_HEADER_SIZE);
     unsigned short usTransLength;
     unsigned char *stream = (pucBuff + SPI_HEADER_SIZE);
     UINT8_TO_STREAM(stream, HCI_TYPE_PATCH);
@@ -173,7 +108,6 @@
         stream = UINT16_TO_STREAM(stream, usDataLength);
         memcpy((pucBuff + SPI_HEADER_SIZE) + HCI_PATCH_HEADER_SIZE, patch, usDataLength);
         // Update the opcode of the event we will be waiting for
-//printf("HPS0\n");
         SpiWrite(pucBuff, usDataLength + HCI_PATCH_HEADER_SIZE);
     }
     else
@@ -187,9 +121,9 @@
         patch += SL_PATCH_PORTION_SIZE;
         
         // Update the opcode of the event we will be waiting for
-//printf("HPS1\n");
         SpiWrite(pucBuff, SL_PATCH_PORTION_SIZE + HCI_PATCH_HEADER_SIZE);
         
+        stream = (pucBuff + SPI_HEADER_SIZE);
         while (usDataLength)
         {
             if (usDataLength <= SL_PATCH_PORTION_SIZE)
@@ -204,23 +138,12 @@
                 usDataLength -= usTransLength;
             }
             
-            *(unsigned short *)data_ptr = usTransLength;
-            memcpy(data_ptr + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE, patch, usTransLength);
+            *(unsigned short *)stream = usTransLength;
+            memcpy(stream + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE, patch, usTransLength);
             patch += usTransLength;
             
             // Update the opcode of the event we will be waiting for
-            SpiWrite((unsigned char *)data_ptr, usTransLength + sizeof(usTransLength));
+            SpiWrite((unsigned char *)stream, usTransLength + sizeof(usTransLength));
         }
     }
 }
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//
-//*****************************************************************************
-
-
-
--- a/hci.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/hci.h	Mon Jul 15 14:19:46 2013 +0000
@@ -35,7 +35,6 @@
 #ifndef __HCI_H__
 #define __HCI_H__
 
-//#include "mbed.h"
 #include "cc3000_common.h"
 #include "CC3000_spi.h"
 #include "evnt_handler.h"
@@ -45,16 +44,12 @@
 /** CC3000 Host driver - HCI
 *
 */
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
+#define SL_PATCH_PORTION_SIZE                        (1000)
 
 #define SPI_HEADER_SIZE                              (5)
 #define SIMPLE_LINK_HCI_CMND_HEADER_SIZE             (4)
@@ -248,39 +243,27 @@
 //
 //*****************************************************************************
 
-//*****************************************************************************
-//
-//!  hci_command_send
-//!
-//!  @param  usOpcode     command operation code
-//!  @param  pucBuff      pointer to the command's arguments buffer
-//!  @param  ucArgsLength length of the arguments
-//!
-//!  @return              none
-//!
-//!  @brief               Initiate an HCI command.
-//
-//*****************************************************************************
+/**
+* Send a HCI command.
+* @param  usOpcode     command operation code
+* @param  pucBuff      pointer to the command's arguments buffer
+* @param  ucArgsLength length of the arguments
+* @return              none
+*/
 extern unsigned short hci_command_send(unsigned short usOpcode, 
                                    unsigned char *ucArgs,
                                    unsigned char ucArgsLength);
  
 
-//*****************************************************************************
-//
-//!  hci_data_send
-//!
-//!  @param  usOpcode        command operation code
-//!     @param  ucArgs                     pointer to the command's arguments buffer
-//!  @param  usArgsLength    length of the arguments
-//!  @param  ucTail          pointer to the data buffer
-//!  @param  usTailLength    buffer length
-//!
-//!  @return none
-//!
-//!  @brief              Initiate an HCI data write operation
-//
-//*****************************************************************************
+/**
+* Send HCI data
+* @param  usOpcode        command operation code
+* @param  ucArgs          pointer to the command's arguments buffer
+* @param  usArgsLength    length of the arguments
+* @param  ucTail          pointer to the data buffer
+* @param  usTailLength    buffer length
+* @return none
+*/
 extern long hci_data_send(unsigned char ucOpcode,
                                       unsigned char *ucArgs,
                                       unsigned short usArgsLength,
@@ -289,46 +272,32 @@
                                       unsigned short usTailLength);
 
 
-//*****************************************************************************
-//
-//!  hci_data_command_send
-//!
-//!  @param  usOpcode      command operation code
-//!  @param  pucBuff       pointer to the data buffer
-//!  @param  ucArgsLength  arguments length
-//!  @param  ucDataLength  data length
-//!
-//!  @return none
-//!
-//!  @brief              Prepare HCI header and initiate an HCI data write operation
-//
-//*****************************************************************************
-extern void hci_data_command_send(unsigned short usOpcode, unsigned char *pucBuff,
-                     unsigned char ucArgsLength, unsigned short ucDataLength);
+/**
+* Prepare HCI header and send HCI data
+* @param  usOpcode      command operation code
+* @param  pucBuff       pointer to the data buffer
+* @param  ucArgsLength  arguments length
+* @param  ucDataLength  data length
+* @return none
+*/
+extern void hci_data_command_send(unsigned short usOpcode,
+                                  unsigned char *pucBuff,
+                                  unsigned char ucArgsLength,
+                                  unsigned short ucDataLength);
 
-//*****************************************************************************
-//
-//!  hci_patch_send
-//!
-//!  @param  usOpcode      command operation code
-//!  @param  pucBuff       pointer to the command's arguments buffer
-//!  @param  patch         pointer to patch content buffer 
-//!  @param  usDataLength  data length
-//!
-//!  @return              none
-//!
-//!  @brief               Prepare HCI header and initiate an HCI patch write operation
-//
-//*****************************************************************************
+
+/**
+* Prepeare HCI header and send HCI patch
+* @param  usOpcode      command operation code
+* @param  pucBuff       pointer to the command's arguments buffer
+* @param  patch         pointer to patch content buffer 
+* @param  usDataLength  data length
+* @return none
+*/
 extern void hci_patch_send(unsigned char ucOpcode, unsigned char *pucBuff, char *patch, unsigned short usDataLength);
 
 
 
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
 #ifdef  __cplusplus
 }
 #endif // __cplusplus
--- a/netapp.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/netapp.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -35,64 +35,12 @@
 
 #include "netapp.h"
 
-#define MIN_TIMER_VAL_SECONDS      20
-#define MIN_TIMER_SET(t)    if ((0 != t) && (t < MIN_TIMER_VAL_SECONDS)) \
-                            { \
-                                t = MIN_TIMER_VAL_SECONDS; \
-                            }
-
-
-#define NETAPP_DHCP_PARAMS_LEN                 (20)
-#define NETAPP_SET_TIMER_PARAMS_LEN         (20)
-#define NETAPP_SET_DEBUG_LEVEL_PARAMS_LEN    (4)
-#define NETAPP_PING_SEND_PARAMS_LEN            (16)
-
-
-//*****************************************************************************
-//
-//!  netapp_config_mac_adrress
-//!
-//!  @param  mac   device mac address, 6 bytes. Saved: yes 
-//!
-//!  @return       return on success 0, otherwise error.
-//!
-//!  @brief        Configure device MAC address and store it in NVMEM. 
-//!                The value of the MAC address configured through the API will
-//!                     be stored in CC3000 non volatile memory, thus preserved 
-//!                over resets.
-//
-//*****************************************************************************
 long netapp_config_mac_adrress(unsigned char * mac)
 {
     return  nvmem_set_mac_address(mac);
 }
 
-//*****************************************************************************
-//
-//!  netapp_dhcp
-//!
-//!  @param  aucIP               device mac address, 6 bytes. Saved: yes 
-//!  @param  aucSubnetMask       device mac address, 6 bytes. Saved: yes 
-//!  @param  aucDefaultGateway   device mac address, 6 bytes. Saved: yes 
-//!  @param  aucDNSServer        device mac address, 6 bytes. Saved: yes 
-//!
-//!  @return       return on success 0, otherwise error.
-//!
-//!  @brief       netapp_dhcp is used to configure the network interface, 
-//!               static or dynamic (DHCP).\n In order to activate DHCP mode, 
-//!               aucIP, aucSubnetMask, aucDefaultGateway must be 0.
-//!               The default mode of CC3000 is DHCP mode.
-//!               Note that the configuration is saved in non volatile memory
-//!               and thus preserved over resets.
-//!     
-//! @note         If the mode is altered a reset of CC3000 device is required 
-//!               in order to apply changes.\nAlso note that asynchronous event 
-//!               of DHCP_EVENT, which is generated when an IP address is 
-//!               allocated either by the DHCP server or due to static 
-//!               allocation is generated only upon a connection to the 
-//!               AP was established. 
-//!
-//*****************************************************************************
+
 long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,unsigned long *aucDefaultGateway, unsigned long *aucDNSServer)
 {
     signed char scRet;
@@ -120,58 +68,8 @@
 }
 
 
-//*****************************************************************************
-//
-//!  netapp_timeout_values
-//!
-//!  @param  aucDHCP    DHCP lease time request, also impact 
-//!                     the DHCP renew timeout. Range: [0-0xffffffff] seconds,
-//!                     0 or 0xffffffff == infinity lease timeout.
-//!                     Resolution:10 seconds. Influence: only after 
-//!                     reconnecting to the AP. 
-//!                     Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds.
-//!                     The parameter is saved into the CC3000 NVMEM. 
-//!                     The default value on CC3000 is 14400 seconds.
-//!     
-//!  @param  aucARP     ARP refresh timeout, if ARP entry is not updated by
-//!                     incoming packet, the ARP entry will be  deleted by
-//!                     the end of the timeout. 
-//!                     Range: [0-0xffffffff] seconds, 0 == infinity ARP timeout
-//!                     Resolution: 10 seconds. Influence: on runtime.
-//!                     Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds
-//!                     The parameter is saved into the CC3000 NVMEM. 
-//!                        The default value on CC3000 is 3600 seconds.
-//!
-//!  @param  aucKeepalive   Keepalive event sent by the end of keepalive timeout
-//!                         Range: [0-0xffffffff] seconds, 0 == infinity timeout
-//!                         Resolution: 10 seconds.
-//!                         Influence: on runtime.
-//!                         Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec
-//!                         The parameter is saved into the CC3000 NVMEM. 
-//!                         The default value on CC3000 is 10 seconds.
-//!
-//!  @param  aucInactivity   Socket inactivity timeout, socket timeout is
-//!                          refreshed by incoming or outgoing packet, by the
-//!                          end of the socket timeout the socket will be closed
-//!                          Range: [0-0xffffffff] sec, 0 == infinity timeout.
-//!                          Resolution: 10 seconds. Influence: on runtime.
-//!                          Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec
-//!                          The parameter is saved into the CC3000 NVMEM. 
-//!                             The default value on CC3000 is 60 seconds.
-//!
-//!  @return       return on success 0, otherwise error.
-//!
-//!  @brief       Set new timeout values. Function set new timeout values for: 
-//!               DHCP lease timeout, ARP  refresh timeout, keepalive event 
-//!               timeout and socket inactivity timeout 
-//!     
-//! @note         If a parameter set to non zero value which is less than 20s,
-//!               it will be set automatically to 20s.
-//!
-//*****************************************************************************
 #ifndef CC3000_TINY_DRIVER
-long 
-netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,unsigned long *aucKeepalive,    unsigned long *aucInactivity)
+long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,unsigned long *aucKeepalive,    unsigned long *aucInactivity)
 {
     signed char scRet;
     unsigned char *ptr;
@@ -204,30 +102,8 @@
 #endif
 
 
-//*****************************************************************************
-//
-//!  netapp_ping_send
-//!
-//!  @param  ip              destination IP address
-//!  @param  pingAttempts    number of echo requests to send
-//!  @param  pingSize        send buffer size which may be up to 1400 bytes 
-//!  @param  pingTimeout     Time to wait for a response,in milliseconds.
-//!
-//!  @return       return on success 0, otherwise error.
-//!
-//!  @brief       send ICMP ECHO_REQUEST to network hosts 
-//!     
-//! @note         If an operation finished successfully asynchronous ping report 
-//!               event will be generated. The report structure is as defined
-//!               by structure netapp_pingreport_args_t.
-//!
-//! @warning      Calling this function while a previous Ping Requests are in 
-//!               progress will stop the previous ping request.
-//*****************************************************************************
-
 #ifndef CC3000_TINY_DRIVER
-long
-netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout)
+long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout)
 {
     signed char scRet;
     unsigned char *ptr, *args;
@@ -252,29 +128,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  netapp_ping_report
-//!
-//!  @param  none
-//!
-//!  @return  none
-//!
-//!  @brief   Request for ping status. This API triggers the CC3000 to send 
-//!           asynchronous events: HCI_EVNT_WLAN_ASYNC_PING_REPORT.
-//!           This event will carry  the report structure:
-//!           netapp_pingreport_args_t. This structure is filled in with ping
-//!           results up till point of triggering API.
-//!           netapp_pingreport_args_t:\n packets_sent - echo sent,
-//!           packets_received - echo reply, min_round_time - minimum
-//!           round time, max_round_time - max round time,
-//!           avg_round_time - average round time
-//!     
-//! @note     When a ping operation is not active, the returned structure 
-//!           fields are 0.
-//!
-//*****************************************************************************
-
 
 #ifndef CC3000_TINY_DRIVER
 void netapp_ping_report()
@@ -294,18 +147,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  netapp_ping_stop
-//!
-//!  @param  none
-//!
-//!  @return  On success, zero is returned. On error, -1 is returned.      
-//!
-//!  @brief   Stop any ping request.
-//!     
-//!
-//*****************************************************************************
 
 #ifndef CC3000_TINY_DRIVER
 long netapp_ping_stop()
@@ -326,31 +167,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  netapp_ipconfig
-//!
-//!  @param[out]  ipconfig  This argument is a pointer to a 
-//!                         tNetappIpconfigRetArgs structure. This structure is
-//!                         filled in with the network interface configuration.
-//!                         tNetappIpconfigRetArgs:\n aucIP - ip address,
-//!                         aucSubnetMask - mask, aucDefaultGateway - default
-//!                         gateway address, aucDHCPServer - dhcp server address
-//!                         aucDNSServer - dns server address, uaMacAddr - mac
-//!                         address, uaSSID - connected AP ssid
-//!
-//!  @return  none
-//!
-//!  @brief   Obtain the CC3000 Network interface information.
-//!           Note that the information is available only after the WLAN
-//!               connection was established. Calling this function before
-//!           associated, will cause non-defined values to be returned.
-//!     
-//! @note     The function is useful for figuring out the IP Configuration of
-//!               the device when DHCP is used and for figuring out the SSID of
-//!               the Wireless network the device is associated with.
-//!
-//*****************************************************************************
 
 #ifndef CC3000_TINY_DRIVER
 void netapp_ipconfig( tNetappIpconfigRetArgs * ipconfig )
@@ -373,17 +189,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  netapp_arp_flush
-//!
-//!  @param  none
-//!
-//!  @return  none
-//!
-//!  @brief  Flushes ARP table
-//!
-//*****************************************************************************
 
 #ifndef CC3000_TINY_DRIVER
 long netapp_arp_flush(void)
@@ -407,3 +212,4 @@
 
 
 
+
--- a/netapp.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/netapp.h	Mon Jul 15 14:19:46 2013 +0000
@@ -35,7 +35,6 @@
 #ifndef __NETAPP_H__
 #define __NETAPP_H__
 
-//#include "mbed.h"
 #include "GlobalAssigns.h"
 #include "hci.h"
 #include "socket.h"
@@ -45,22 +44,23 @@
 /** CC3000 Host driver - netapp
 *
 */
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-//*****************************************************************************
-//
-//! \addtogroup netapp_api
-//! @{
-//
-//*****************************************************************************
+#define MIN_TIMER_VAL_SECONDS      20
+#define MIN_TIMER_SET(t)    if ((0 != t) && (t < MIN_TIMER_VAL_SECONDS)) \
+                            { \
+                                t = MIN_TIMER_VAL_SECONDS; \
+                            }
+
+
+#define NETAPP_DHCP_PARAMS_LEN                 (20)
+#define NETAPP_SET_TIMER_PARAMS_LEN            (20)
+#define NETAPP_SET_DEBUG_LEVEL_PARAMS_LEN      (4)
+#define NETAPP_PING_SEND_PARAMS_LEN            (16)
+
 
 typedef struct _netapp_dhcp_ret_args_t
 {
@@ -94,233 +94,156 @@
 } netapp_pingreport_args_t;
 
 
-//*****************************************************************************
-//
-//!  netapp_config_mac_adrress
-//!
-//!  @param  mac   device mac address, 6 bytes. Saved: yes 
-//!
-//!  @return       return on success 0, otherwise error.
-//!
-//!  @brief        Configure device MAC address and store it in NVMEM. 
-//!                The value of the MAC address configured through the API will
-//!                     be stored in CC3000 non volatile memory, thus preserved 
-//!                over resets.
-//
-//*****************************************************************************
-extern long  netapp_config_mac_adrress( unsigned char *mac );
+/**
+* Configure device MAC address and store it in NVMEM. 
+* The value of the MAC address configured through the API will be
+* stored in CC3000 non volatile memory, thus preserved over resets.
+* @param  mac   device mac address, 6 bytes. Saved: yes 
+* @return       return on success 0, otherwise error.
+*/
+extern long netapp_config_mac_adrress( unsigned char *mac );
 
-//*****************************************************************************
-//
-//!  netapp_dhcp
-//!
-//!  @param  aucIP               device mac address, 6 bytes. Saved: yes 
-//!  @param  aucSubnetMask       device mac address, 6 bytes. Saved: yes 
-//!  @param  aucDefaultGateway   device mac address, 6 bytes. Saved: yes 
-//!  @param  aucDNSServer        device mac address, 6 bytes. Saved: yes 
-//!
-//!  @return       return on success 0, otherwise error.
-//!
-//!  @brief       netapp_dhcp is used to configure the network interface, 
-//!               static or dynamic (DHCP).\n In order to activate DHCP mode, 
-//!               aucIP, aucSubnetMask, aucDefaultGateway must be 0.
-//!               The default mode of CC3000 is DHCP mode.
-//!               Note that the configuration is saved in non volatile memory
-//!               and thus preserved over resets.
-//!     
-//! @note         If the mode is altered a reset of CC3000 device is required 
-//!               in order to apply changes.\nAlso note that asynchronous event 
-//!               of DHCP_EVENT, which is generated when an IP address is 
-//!               allocated either by the DHCP server or due to static 
-//!               allocation is generated only upon a connection to the 
-//!               AP was established. 
-//!
-//*****************************************************************************
-extern     long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,unsigned long *aucDefaultGateway, unsigned long *aucDNSServer);
-
-
+/**
+* Configure the network interface, static or dynamic (DHCP).
+* In order to activate DHCP mode, aucIP, aucSubnetMask, aucDefaultGateway must be 0.
+* The default mode of CC3000 is DHCP mode. The configuration is saved in non volatile memory
+* and thus preserved over resets.
+* @param  aucIP               device mac address, 6 bytes. Saved: yes 
+* @param  aucSubnetMask       device mac address, 6 bytes. Saved: yes 
+* @param  aucDefaultGateway   device mac address, 6 bytes. Saved: yes 
+* @param  aucDNSServer        device mac address, 6 bytes. Saved: yes 
+* @return       0 on success, otherwise error.
+* @note         If the mode is altered, a reset of CC3000 device is required to apply the changes.
+*               Also note that an asynchronous event of type 'DHCP_EVENT' is generated only when
+*               a connection to the AP was established. This event is generated when an IP address
+*               is allocated either by the DHCP server or by static allocation.
+*/
+extern long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,unsigned long *aucDefaultGateway, unsigned long *aucDNSServer);
 
-//*****************************************************************************
-//
-//!  netapp_timeout_values
-//!
-//!  @param  aucDHCP    DHCP lease time request, also impact 
-//!                     the DHCP renew timeout. Range: [0-0xffffffff] seconds,
-//!                     0 or 0xffffffff == infinity lease timeout.
-//!                     Resolution:10 seconds. Influence: only after 
-//!                     reconnecting to the AP. 
-//!                     Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds.
-//!                     The parameter is saved into the CC3000 NVMEM. 
-//!                     The default value on CC3000 is 14400 seconds.
-//!     
-//!  @param  aucARP     ARP refresh timeout, if ARP entry is not updated by
-//!                     incoming packet, the ARP entry will be  deleted by
-//!                     the end of the timeout. 
-//!                     Range: [0-0xffffffff] seconds, 0 == infinity ARP timeout
-//!                     Resolution: 10 seconds. Influence: on runtime.
-//!                     Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds
-//!                     The parameter is saved into the CC3000 NVMEM. 
-//!                        The default value on CC3000 is 3600 seconds.
-//!
-//!  @param  aucKeepalive   Keepalive event sent by the end of keepalive timeout
-//!                         Range: [0-0xffffffff] seconds, 0 == infinity timeout
-//!                         Resolution: 10 seconds.
-//!                         Influence: on runtime.
-//!                         Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec
-//!                         The parameter is saved into the CC3000 NVMEM. 
-//!                         The default value on CC3000 is 10 seconds.
-//!
-//!  @param  aucInactivity   Socket inactivity timeout, socket timeout is
-//!                          refreshed by incoming or outgoing packet, by the
-//!                          end of the socket timeout the socket will be closed
-//!                          Range: [0-0xffffffff] sec, 0 == infinity timeout.
-//!                          Resolution: 10 seconds. Influence: on runtime.
-//!                          Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec
-//!                          The parameter is saved into the CC3000 NVMEM. 
-//!                             The default value on CC3000 is 60 seconds.
-//!
-//!  @return       return on success 0, otherwise error.
-//!
-//!  @brief       Set new timeout values. Function set new timeout values for: 
-//!               DHCP lease timeout, ARP  refresh timeout, keepalive event 
-//!               timeout and socket inactivity timeout 
-//!     
-//! @note         If a parameter set to non zero value which is less than 20s,
-//!               it will be set automatically to 20s.
-//!
-//*****************************************************************************
+/**
+* Set new timeout values for DHCP lease timeout, ARP  refresh timeout, keepalive event timeout and socket inactivity timeout 
+* @param  aucDHCP    DHCP lease time request, also impact 
+*                    the DHCP renew timeout.
+*                    Range:               [0-0xffffffff] seconds,
+*                                         0 or 0xffffffff = infinite lease timeout.
+*                    Resolution:          10 seconds.
+*                    Influence:           only after reconnecting to the AP. 
+*                    Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds.
+*                    The parameter is saved into the CC3000 NVMEM. 
+*                    The default value on CC3000 is 14400 seconds.
+*
+* @param  aucARP     ARP refresh timeout, if ARP entry is not updated by
+*                    incoming packet, the ARP entry will be  deleted by
+*                    the end of the timeout. 
+*                    Range:               [0-0xffffffff] seconds, 0 = infinite ARP timeout
+*                    Resolution:          10 seconds.
+*                    Influence:           at runtime.
+*                    Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds
+*                    The parameter is saved into the CC3000 NVMEM. 
+*                    The default value on CC3000 is 3600 seconds.
+*
+* @param  aucKeepalive   Keepalive event sent by the end of keepalive timeout
+*                        Range:               [0-0xffffffff] seconds, 0 == infinite timeout
+*                        Resolution:          10 seconds.
+*                        Influence:           at runtime.
+*                        Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec
+*                        The parameter is saved into the CC3000 NVMEM. 
+*                        The default value on CC3000 is 10 seconds.
+*
+* @param  aucInactivity   Socket inactivity timeout, socket timeout is
+*                         refreshed by incoming or outgoing packet, by the
+*                         end of the socket timeout the socket will be closed
+*                         Range:               [0-0xffffffff] sec, 0 == infinite timeout.
+*                         Resolution:          10 seconds.
+*                         Influence:           at runtime.
+*                         Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec
+*                         The parameter is saved into the CC3000 NVMEM. 
+*                         The default value on CC3000 is 60 seconds.
+*
+* @return 0 on success 0,otherwise error.
+*
+* @note   A parameter set to a non zero value less than 20s automatically changes to 20s.
+*/
 #ifndef CC3000_TINY_DRIVER
 extern long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,unsigned long *aucKeepalive,    unsigned long *aucInactivity);
 #endif
-//*****************************************************************************
-//
-//!  netapp_ping_send
-//!
-//!  @param  ip              destination IP address
-//!  @param  pingAttempts    number of echo requests to send
-//!  @param  pingSize        send buffer size which may be up to 1400 bytes 
-//!  @param  pingTimeout     Time to wait for a response,in milliseconds.
-//!
-//!  @return       return on success 0, otherwise error.
-//!
-//!  @brief       send ICMP ECHO_REQUEST to network hosts 
-//!     
-//! @note         If an operation finished successfully asynchronous ping report 
-//!               event will be generated. The report structure is as defined
-//!               by structure netapp_pingreport_args_t.
-//!
-//! @warning      Calling this function while a previous Ping Requests are in 
-//!               progress will stop the previous ping request.
-//*****************************************************************************
 
- #ifndef CC3000_TINY_DRIVER
+/**
+* send ICMP ECHO_REQUEST to network hosts
+* @param  ip              destination IP address
+* @param  pingAttempts    number of echo requests to send
+* @param  pingSize        send buffer size which may be up to 1400 bytes 
+* @param  pingTimeout     Time to wait for a response,in milliseconds.
+* @return 0 on success, otherwise error.
+*
+* @note     A succesful operation will generate an asynchronous ping report event.
+*           The report structure is defined by structure netapp_pingreport_args_t.
+* @warning  Calling this function while a Ping Request is in progress will kill the ping request in progress.
+*/
+#ifndef CC3000_TINY_DRIVER
 extern long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout);
 #endif
 
-//*****************************************************************************
-//
-//!  netapp_ping_stop
-//!
-//!  @param  none
-//!
-//!  @return  On success, zero is returned. On error, -1 is returned.      
-//!
-//!  @brief   Stop any ping request.
-//!     
-//!
-//*****************************************************************************
-
+/**
+* Stop any ping request.
+* @param   none
+* @return   0 on success
+*          -1 on error      
+*/
 #ifndef CC3000_TINY_DRIVER
 extern long netapp_ping_stop(void);
 #endif
-//*****************************************************************************
-//
-//!  netapp_ping_report
-//!
-//!  @param  none
-//!
-//!  @return  none
-//!
-//!  @brief   Request for ping status. This API triggers the CC3000 to send 
-//!           asynchronous events: HCI_EVNT_WLAN_ASYNC_PING_REPORT.
-//!           This event will carry  the report structure:
-//!           netapp_pingreport_args_t. This structure is filled in with ping
-//!           results up till point of triggering API.
-//!           netapp_pingreport_args_t:\n packets_sent - echo sent,
-//!           packets_received - echo reply, min_round_time - minimum
-//!           round time, max_round_time - max round time,
-//!           avg_round_time - average round time
-//!     
-//! @note     When a ping operation is not active, the returned structure 
-//!           fields are 0.
-//!
-//*****************************************************************************
+
+/**
+* Ping status request. This API triggers the CC3000 to send 
+* asynchronous events: HCI_EVNT_WLAN_ASYNC_PING_REPORT.
+* This event will create the report structure in netapp_pingreport_args_t.
+* This structure is filled with ping results until the API is triggered.
+* netapp_pingreport_args_t: packets_sent     - echo sent
+*                           packets_received - echo reply
+*                           min_round_time   - minimum round time
+*                           max_round_time   - max round time
+*                           avg_round_time   - average round time
+*
+* @param   none
+* @return  none
+* @note    When a ping operation is not active, the returned structure fields are 0.
+*/
 #ifndef CC3000_TINY_DRIVER
 extern void netapp_ping_report(void);
 #endif
 
 
-//*****************************************************************************
-//
-//!  netapp_ipconfig
-//!
-//!  @param[out]  ipconfig  This argument is a pointer to a 
-//!                         tNetappIpconfigRetArgs structure. This structure is
-//!                         filled in with the network interface configuration.
-//!                         tNetappIpconfigRetArgs:\n aucIP - ip address,
-//!                         aucSubnetMask - mask, aucDefaultGateway - default
-//!                         gateway address, aucDHCPServer - dhcp server address
-//!                         aucDNSServer - dns server address, uaMacAddr - mac
-//!                         address, uaSSID - connected AP ssid
-//!
-//!  @return  none
-//!
-//!  @brief   Obtain the CC3000 Network interface information.
-//!           Note that the information is available only after the WLAN
-//!             connection was established. Calling this function before
-//!           associated, will cause non-defined values to be returned.
-//!     
-//! @note     The function is useful for figuring out the IP Configuration of
-//!               the device when DHCP is used and for figuring out the SSID of
-//!               the Wireless network the device is associated with.
-//!
-//*****************************************************************************
-
+/**
+* Get the CC3000 Network interface information.
+* This information is only available after establishing a WLAN connection.
+* Undefined values are returned when this function is called before association.
+* @param[out]  ipconfig  pointer to a tNetappIpconfigRetArgs structure for storing the network interface configuration.
+*                        tNetappIpconfigRetArgs: aucIP             - ip address,
+*                                                aucSubnetMask     - mask
+*                                                aucDefaultGateway - default gateway address
+*                                                aucDHCPServer     - dhcp server address
+*                                                aucDNSServer      - dns server address
+*                                                uaMacAddr         - mac address
+*                                                uaSSID            - connected AP ssid
+* @return  none
+* @note    This function is useful for figuring out the IP Configuration of
+*          the device when DHCP is used and for figuring out the SSID of
+*          the Wireless network the device is associated with.
+*/
 extern void netapp_ipconfig( tNetappIpconfigRetArgs * ipconfig );
 
 
-//*****************************************************************************
-//
-//!  netapp_arp_flush
-//!
-//!  @param  none
-//!
-//!  @return  none
-//!
-//!  @brief  Flushes ARP table
-//!
-//*****************************************************************************
-
+/**
+* Flush ARP table
+* @param   none
+* @return  none
+*/
 #ifndef CC3000_TINY_DRIVER
 extern long netapp_arp_flush(void);
 #endif
 
 
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
-
-
-
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
 #ifdef    __cplusplus
 }
 #endif // __cplusplus
--- a/nvmem.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/nvmem.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -33,50 +33,9 @@
 *
 *****************************************************************************/
 
-//*****************************************************************************
-//
-//! \addtogroup nvmem_api
-//! @{
-//
-//*****************************************************************************
-
 
 #include "nvmem.h"
 
-//*****************************************************************************
-//
-// Prototypes for the structures for APIs.
-//
-//*****************************************************************************
-
-#define NVMEM_READ_PARAMS_LEN     (12)
-#define NVMEM_CREATE_PARAMS_LEN     (8)
-#define NVMEM_WRITE_PARAMS_LEN  (16)
-
-//*****************************************************************************
-//
-//!  nvmem_read
-//!
-//!  @param  ulFileId   nvmem file id:\n
-//!                     NVMEM_NVS_FILEID, NVMEM_NVS_SHADOW_FILEID,
-//!                     NVMEM_WLAN_CONFIG_FILEID, NVMEM_WLAN_CONFIG_SHADOW_FILEID,
-//!                     NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
-//!                     NVMEM_MAC_FILEID, NVMEM_FRONTEND_VARS_FILEID,
-//!                     NVMEM_IP_CONFIG_FILEID, NVMEM_IP_CONFIG_SHADOW_FILEID,
-//!                     NVMEM_BOOTLOADER_SP_FILEID, NVMEM_RM_FILEID,
-//!                     and user files 12-15.
-//!  @param  ulLength    number of bytes to read 
-//!  @param  ulOffset    ulOffset in file from where to read  
-//!  @param  buff        output buffer pointer
-//!
-//!  @return       number of bytes read, otherwise error.
-//!
-//!  @brief       Reads data from the file referred by the ulFileId parameter. 
-//!               Reads data from file ulOffset till length. Err if the file can't
-//!               be used, is invalid, or if the read is out of bounds. 
-//!     
-//*****************************************************************************
-
 signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength, unsigned long ulOffset, unsigned char *buff)
 {
     unsigned char ucStatus = 0xFF;
@@ -91,42 +50,19 @@
     args = UINT32_TO_STREAM(args, ulLength);
     args = UINT32_TO_STREAM(args, ulOffset);
     
-    // Initiate a HCI command
+    // Initiate HCI command
     hci_command_send(HCI_CMND_NVMEM_READ, ptr, NVMEM_READ_PARAMS_LEN);
     SimpleLinkWaitEvent(HCI_CMND_NVMEM_READ, &ucStatus);
     
-    // In case there is data - read it - even if an error code is returned
-   // Note: It is the user responsibility to ignore the data in case of an error code
-    
-    // Wait for the data in a synchronous way. Here we assume that the buffer is 
-    // big enough to store also parameters of nvmem
-    
+    // If data is present, read it even when an error is returned.
+    // Note: It is the users responsibility to ignore the data when an error is returned.
+    // Wait for the data in a synchronous way.
+    //  We assume the buffer is large enough to also store nvmem parameters.
     SimpleLinkWaitData(buff, 0, 0);
-    
+
     return(ucStatus);
 }
 
-//*****************************************************************************
-//
-//!  nvmem_write
-//!
-//!  @param  ulFileId nvmem file id:\n
-//!                   NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
-//!                   NVMEM_MAC_FILEID, NVMEM_BOOTLOADER_SP_FILEID,
-//!                   and user files 12-15.
-//!  @param  ulLength       number of bytes to write  
-//!  @param  ulEntryOffset  offset in file to start write operation from 
-//!  @param  buff           data to write
-//!
-//!  @return       on success 0, error otherwise.
-//!
-//!  @brief       Write data to nvmem.
-//!               writes data to file referred by the ulFileId parameter. 
-//!               Writes data to file ulOffset till ulLength.The file id will be 
-//!               marked invalid till the write is done. The file entry doesn't
-//!               need to be valid - only allocated.
-//!     
-//*****************************************************************************
 
 signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long ulEntryOffset, unsigned char *buff)
 {
@@ -148,9 +84,8 @@
     memcpy((ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE + 
                     NVMEM_WRITE_PARAMS_LEN),buff,ulLength);
     
-    // Initiate a HCI command but it will come on data channel
-    hci_data_command_send(HCI_CMND_NVMEM_WRITE, ptr, NVMEM_WRITE_PARAMS_LEN,
-                                                ulLength);
+    // Initiate a HCI command on the data channel
+    hci_data_command_send(HCI_CMND_NVMEM_WRITE, ptr, NVMEM_WRITE_PARAMS_LEN, ulLength);
     
     SimpleLinkWaitEvent(HCI_EVNT_NVMEM_WRITE, &iRes);
     
@@ -158,59 +93,17 @@
 }
 
 
-//*****************************************************************************
-//
-//!  nvmem_set_mac_address
-//!
-//!  @param  mac   mac address to be set
-//!
-//!  @return       on success 0, error otherwise.
-//!
-//!  @brief       Write MAC address to EEPROM. 
-//!               mac address as appears over the air (OUI first)
-//!     
-//*****************************************************************************
-
 unsigned char nvmem_set_mac_address(unsigned char *mac)
 {
     return  nvmem_write(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac);
 }
 
-//*****************************************************************************
-//
-//!  nvmem_get_mac_address
-//!
-//!  @param[out]  mac   mac address  
-//!
-//!  @return       on success 0, error otherwise.
-//!
-//!  @brief       Read MAC address from EEPROM. 
-//!               mac address as appears over the air (OUI first)
-//!     
-//*****************************************************************************
 
 unsigned char nvmem_get_mac_address(unsigned char *mac)
 {
     return  nvmem_read(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac);
 }
 
-//*****************************************************************************
-//
-//!  nvmem_write_patch
-//!
-//!  @param  ulFileId   nvmem file id:\n
-//!                     NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
-//!  @param  spLength   number of bytes to write 
-//!  @param  spData     SP data to write
-//!
-//!  @return       on success 0, error otherwise.
-//!
-//!  @brief      program a patch to a specific file ID. 
-//!              The SP data is assumed to be organized in 2-dimensional.
-//!              Each line is SP_PORTION_SIZE bytes long. Actual programming is 
-//!              applied in SP_PORTION_SIZE bytes portions.
-//!     
-//*****************************************************************************
 
 unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const unsigned char *spData)
 {
@@ -234,32 +127,20 @@
     
     if (spLength != 0)
     {
-        // if reached here, a remainder is left
+        // If spLength MOD 512 is nonzero, write the remaining bytes.
         status = nvmem_write(ulFileId, spLength, offset, spDataPtr);
     }
     
     return status;
 }
 
-//*****************************************************************************
-//
-//!  nvmem_read_sp_version
-//!
-//!  @param[out]  patchVer    first number indicates package ID and the second 
-//!                           number indicates package build number   
-//!
-//!  @return       on success  0, error otherwise.
-//!
-//!  @brief      Read patch version. read package version (WiFi FW patch, 
-//!              driver-supplicant-NS patch, bootloader patch)
-//!     
-//*****************************************************************************
+
 #ifndef CC3000_TINY_DRIVER
 unsigned char nvmem_read_sp_version(unsigned char* patchVer)
 {
     unsigned char *ptr;
     // 1st byte is the status and the rest is the SP version
-    unsigned char    retBuf[5];    
+    unsigned char retBuf[5];    
     
     ptr = tSLInformation.pucTxCommandBuffer;
   
@@ -276,28 +157,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  nvmem_create_entry
-//!
-//!  @param       ulFileId    nvmem file Id:\n
-//!                           * NVMEM_AES128_KEY_FILEID: 12
-//!                           * NVMEM_SHARED_MEM_FILEID: 13
-//!                           * and fileIDs 14 and 15
-//!  @param       ulNewLen    entry ulLength  
-//!
-//!  @return       on success 0, error otherwise.
-//!
-//!  @brief      Create new file entry and allocate space on the NVMEM. 
-//!              Applies only to user files.
-//!              Modify the size of file.
-//!              If the entry is unallocated - allocate it to size 
-//!              ulNewLen (marked invalid).
-//!              If it is allocated then deallocate it first.
-//!              To just mark the file as invalid without resizing - 
-//!              set ulNewLen=0.
-//!     
-//*****************************************************************************
 
 signed long 
 nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen)
@@ -321,16 +180,3 @@
     return(retval);
 }
 
-
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
-
-
-
-
-
--- a/nvmem.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/nvmem.h	Mon Jul 15 14:19:46 2013 +0000
@@ -35,7 +35,6 @@
 #ifndef __NVRAM_H__
 #define __NVRAM_H__
 
-//#include "mbed.h"
 #include "GlobalAssigns.h"
 #include "cc3000_common.h"
 #include "hci.h"
@@ -46,24 +45,22 @@
 /** CC3000 Host driver - NVMEM
 *
 */
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
-
 //*****************************************************************************
 //
-//! \addtogroup nvmem_api
-//! @{
+// Prototypes for the structures for APIs.
 //
 //*****************************************************************************
 
+#define NVMEM_READ_PARAMS_LEN       (12)
+#define NVMEM_CREATE_PARAMS_LEN     (8)
+#define NVMEM_WRITE_PARAMS_LEN      (16)
+
+
 /****************************************************************************
 **
 **    Definitions for File IDs
@@ -93,163 +90,98 @@
 #define NVMEM_MAX_ENTRY                              (16)
 
 
-//*****************************************************************************
-//
-//!  nvmem_read
-//!
-//!  @param  ulFileId   nvmem file id:\n
-//!                     NVMEM_NVS_FILEID, NVMEM_NVS_SHADOW_FILEID,
-//!                     NVMEM_WLAN_CONFIG_FILEID, NVMEM_WLAN_CONFIG_SHADOW_FILEID,
-//!                     NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
-//!                     NVMEM_MAC_FILEID, NVMEM_FRONTEND_VARS_FILEID,
-//!                     NVMEM_IP_CONFIG_FILEID, NVMEM_IP_CONFIG_SHADOW_FILEID,
-//!                     NVMEM_BOOTLOADER_SP_FILEID, NVMEM_RM_FILEID,
-//!                     and user files 12-15.
-//!  @param  ulLength   number of bytes to read 
-//!  @param  ulOffset   ulOffset in file from where to read  
-//!  @param  buff       output buffer pointer
-//!
-//!  @return       number of bytes read, otherwise error.
-//!
-//!  @brief       Reads data from the file referred by the ulFileId parameter. 
-//!               Reads data from file ulOffset till length. Err if the file can't
-//!               be used, is invalid, or if the read is out of bounds. 
-//!     
-//*****************************************************************************
-
+/**
+* Read 'length' data at offset 'ulOffset' from nvmem to file 'ulFileId'.
+* @param  ulFileId   Possible nvmem file id values:
+*                    NVMEM_NVS_FILEID, NVMEM_NVS_SHADOW_FILEID,
+*                    NVMEM_WLAN_CONFIG_FILEID, NVMEM_WLAN_CONFIG_SHADOW_FILEID,
+*                    NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
+*                    NVMEM_MAC_FILEID, NVMEM_FRONTEND_VARS_FILEID,
+*                    NVMEM_IP_CONFIG_FILEID, NVMEM_IP_CONFIG_SHADOW_FILEID,
+*                    NVMEM_BOOTLOADER_SP_FILEID, NVMEM_RM_FILEID,
+*                    and user files 12-15.
+* @param  ulLength   number of bytes to read 
+* @param  ulOffset   ulOffset in file from where to read  
+* @param  buff       output buffer pointer
+* @return            number of bytes read, otherwise error.
+*                    Error conditions : file can't be used
+*                                       file is invalid
+*                                       read out of bounds. 
+*/
 extern signed long nvmem_read(unsigned long file_id, unsigned long length, unsigned long offset, unsigned char *buff);
 
-//*****************************************************************************
-//
-//!  nvmem_write
-//!
-//!  @param  ulFileId nvmem file id:\n
-//!                   NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
-//!                   NVMEM_MAC_FILEID, NVMEM_BOOTLOADER_SP_FILEID,
-//!                   and user files 12-15.
-//!  @param  ulLength       number of bytes to write  
-//!  @param  ulEntryOffset  offset in file to start write operation from 
-//!  @param  buff           data to write
-//!
-//!  @return      on success 0, error otherwise.
-//!
-//!  @brief       Write data to nvmem.
-//!               writes data to file referred by the ulFileId parameter. 
-//!               Writes data to file ulOffset till ulLength.The file id will be 
-//!               marked invalid till the write is done. The file entry doesn't
-//!               need to be valid - only allocated.
-//!     
-//*****************************************************************************
-
+/**
+* Write 'length' data at offset 'ulOffset' from file 'ulFileId' to nvmem.
+* The file id is marked as invalid until writing is ended.
+* The file entry doesn't need to be valid - only allocated.
+* @param  ulFileId  Possible nvmem file id values:
+*                   NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
+*                   NVMEM_MAC_FILEID, NVMEM_BOOTLOADER_SP_FILEID,
+*                   and user files 12-15.
+* @param  ulLength       number of bytes to write  
+* @param  ulEntryOffset  offset in file to start write operation from 
+* @param  buff           data to write
+*
+* @return      0 on success, error otherwise.
+*/
 extern signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long ulEntryOffset, unsigned char *buff);
 
 
-//*****************************************************************************
-//
-//!  nvmem_set_mac_address
-//!
-//!  @param  mac  mac address to be set
-//!
-//!  @return      on success 0, error otherwise.
-//!
-//!  @brief       Write MAC address to EEPROM. 
-//!               mac address as appears over the air (OUI first)
-//!     
-//*****************************************************************************
+/**
+* Write the MAC address to EEPROM (OUI first)
+* @param  mac  mac address to be set
+* @return      0 on success, error otherwise.
+*/
 extern unsigned char nvmem_set_mac_address(unsigned char *mac);
 
 
-//*****************************************************************************
-//
-//!  nvmem_get_mac_address
-//!
-//!  @param[out]  mac   mac address  
-//!
-//!  @return      on success 0, error otherwise.
-//!
-//!  @brief       Read MAC address from EEPROM. 
-//!               mac address as appears over the air (OUI first)
-//!     
-//*****************************************************************************
+/**
+* Read the MAC address from EEPROM (OUI first)
+* @param[out]  mac   mac address  
+*
+* @return      on success 0, error otherwise.
+*/
 extern unsigned char nvmem_get_mac_address(unsigned char *mac);
 
 
-//*****************************************************************************
-//
-//!  nvmem_write_patch
-//!
-//!  @param  ulFileId   nvmem file id:\n
-//!                     NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
-//!  @param  spLength   number of bytes to write 
-//!  @param  spData     SP data to write
-//!
-//!  @return     on success 0, error otherwise.
-//!
-//!  @brief      program a patch to a specific file ID. 
-//!              The SP data is assumed to be organized in 2-dimensional.
-//!              Each line is SP_PORTION_SIZE bytes long. Actual programming is 
-//!              applied in SP_PORTION_SIZE bytes portions.
-//!     
-//*****************************************************************************
+/**
+* Write patch code to a specific file ID. Each write contains SP_PORTION_SIZE bytes.
+* @param    ulFileId   Possible nvmem file id values:
+*                      NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
+* @param    spLength   number of bytes to write 
+* @param    spData     SP data to write
+*
+* @return   0 on success, error otherwise.
+*/
 extern unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const unsigned char *spData);
 
-
-//*****************************************************************************
-//
-//!  nvmem_read_sp_version
-//!
-//!  @param[out]  patchVer    first number indicates package ID and the second 
-//!                           number indicates package build number   
-//!
-//!  @return     on success 0, error otherwise.
-//!
-//!  @brief      Read patch version. read package version (WiFi FW patch, 
-//!              driver-supplicant-NS patch, bootloader patch)
-//!     
-//*****************************************************************************
+/**
+* Read the patch version. read package version (WiFi FW patch, driver-supplicant-NS patch, bootloader patch)
+* @param[out]  patchVer    first number indicates package ID and the second number indicates package build number   
+* @return      0 on success, error otherwise.
+*/
 #ifndef CC3000_TINY_DRIVER 
 extern unsigned char nvmem_read_sp_version(unsigned char* patchVer);
 #endif
 
-//*****************************************************************************
-//
-//!  nvmem_create_entry
-//!
-//!  @param       ulFileId    nvmem file Id:\n
-//!                           * NVMEM_AES128_KEY_FILEID: 12
-//!                           * NVMEM_SHARED_MEM_FILEID: 13
-//!                           * and fileIDs 14 and 15
-//!  @param       ulNewLen    entry ulLength  
-//!
-//!  @return     on success 0, error otherwise.
-//!
-//!  @brief      Create new file entry and allocate space on the NVMEM. 
-//!              Applies only to user files.
-//!              Modify the size of file.
-//!              If the entry is unallocated - allocate it to size 
-//!              ulNewLen (marked invalid).
-//!              If it is allocated then deallocate it first.
-//!              To just mark the file as invalid without resizing - 
-//!              set ulNewLen=0.
-//!     
-//*****************************************************************************
+/**
+* Create a new file entry and allocate space in NVMEM. 
+* Applies only to user files.
+* Modify the size of file.
+* If the entry is unallocated - allocate it to size ulNewLen (marked invalid).
+* If it is allocated then deallocate it first.
+* To just mark the file as invalid without resizing - set ulNewLen=0.
+* @param       ulFileId    Possible nvmem file Ids:
+*                          * NVMEM_AES128_KEY_FILEID: 12
+*                          * NVMEM_SHARED_MEM_FILEID: 13
+*                          * and fileIDs 14 and 15
+* @param       ulNewLen    entry ulLength  
+*
+* @return      0 on success, error otherwise.
+*/
 extern signed long nvmem_create_entry(unsigned long file_id, unsigned long newlen);
 
 
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
-
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
-
 
 #ifdef  __cplusplus
 }
--- a/security.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/security.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -33,74 +33,13 @@
 *
 *****************************************************************************/
 
-//*****************************************************************************
-//
-//! \addtogroup security_api
-//! @{
-//
-//*****************************************************************************
-
 #include "security.h"
 
 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
-// foreward sbox
-const unsigned char sbox[256] =   { 
-//0     1    2      3     4    5     6     7      8    9     A      B    C     D     E     F
-0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, //0
-0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, //1
-0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, //2
-0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, //3
-0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, //4
-0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, //5
-0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, //6
-0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, //7
-0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, //8
-0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, //9
-0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, //A
-0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, //B
-0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, //C
-0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, //D
-0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, //E
-0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; //F   
-// inverse sbox
-const unsigned char rsbox[256] =
-{ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
-, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
-, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
-, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
-, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
-, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
-, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
-, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
-, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
-, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
-, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
-, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
-, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
-, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
-, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
-, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };
-// round constant
-const unsigned char Rcon[11] = {0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
-
 
 unsigned char expandedKey[176];
 
-//*****************************************************************************
-//
-//!  expandKey
-//!
-//!  @param  key          AES128 key - 16 bytes
-//!  @param  expandedKey  expanded AES128 key
-//!
-//!  @return  none
-//!
-//!  @brief  expend a 16 bytes key for AES128 implementation
-//!
-//*****************************************************************************
-
-void expandKey(unsigned char *expandedKey,
-               unsigned char *key)
+void expandKey(unsigned char *expandedKey, unsigned char *key)
 {
   unsigned short ii, buf1;
   for (ii=0;ii<16;ii++)
@@ -128,17 +67,6 @@
     
 }
 
-//*****************************************************************************
-//
-//!  galois_mul2
-//!
-//!  @param  value    argument to multiply
-//!
-//!  @return  multiplied argument
-//!
-//!  @brief  multiply by 2 in the galois field
-//!
-//*****************************************************************************
 
 unsigned char galois_mul2(unsigned char value)
 {
@@ -150,29 +78,6 @@
         return value<<1;
 }
 
-//*****************************************************************************
-//
-//!  aes_encr
-//!
-//!  @param[in]  expandedKey expanded AES128 key
-//!  @param[in/out] state 16 bytes of plain text and cipher text
-//!
-//!  @return  none
-//!
-//!  @brief   internal implementation of AES128 encryption.
-//!           straight forward aes encryption implementation
-//!           first the group of operations
-//!          - addRoundKey
-//!          - subbytes
-//!          - shiftrows
-//!          - mixcolums
-//!          is executed 9 times, after this addroundkey to finish the 9th 
-//!          round, after that the 10th round without mixcolums
-//!          no further subfunctions to save cycles for function calls
-//!          no structuring with "for (....)" to save cycles.
-//!     
-//!
-//*****************************************************************************
 
 void aes_encr(unsigned char *state, unsigned char *expandedKey)
 {
@@ -280,27 +185,6 @@
   state[15]^=expandedKey[175];
 } 
 
-//*****************************************************************************
-//
-//!  aes_decr
-//!
-//!  @param[in]  expandedKey expanded AES128 key
-//!  @param[in\out] state 16 bytes of cipher text and plain text
-//!
-//!  @return  none
-//!
-//!  @brief   internal implementation of AES128 decryption.
-//!           straight forward aes decryption implementation
-//!           the order of substeps is the exact reverse of decryption
-//!           inverse functions:
-//!            - addRoundKey is its own inverse
-//!            - rsbox is inverse of sbox
-//!            - rightshift instead of leftshift
-//!            - invMixColumns = barreto + mixColumns
-//!           no further subfunctions to save cycles for function calls
-//!           no structuring with "for (....)" to save cycles
-//!
-//*****************************************************************************
 
 void aes_decr(unsigned char *state, unsigned char *expandedKey)
 {
@@ -429,22 +313,6 @@
     
 } 
 
-//*****************************************************************************
-//
-//!  aes_encrypt
-//!
-//!  @param[in]  key   AES128 key of size 16 bytes
-//!  @param[in\out] state   16 bytes of plain text and cipher text
-//!
-//!  @return  none
-//!
-//!  @brief   AES128 encryption:
-//!           Given AES128 key and  16 bytes plain text, cipher text of 16 bytes
-//!           is computed. The AES implementation is in mode ECB (Electronic 
-//!           Code Book). 
-//!     
-//!
-//*****************************************************************************
 
 void aes_encrypt(unsigned char *state,
                  unsigned char *key)
@@ -454,22 +322,6 @@
     aes_encr(state, expandedKey);
 }
 
-//*****************************************************************************
-//
-//!  aes_decrypt
-//!
-//!  @param[in]  key   AES128 key of size 16 bytes
-//!  @param[in\out] state   16 bytes of cipher text and plain text
-//!
-//!  @return  none
-//!
-//!  @brief   AES128 decryption:
-//!           Given AES128 key and  16 bytes cipher text, plain text of 16 bytes
-//!           is computed The AES implementation is in mode ECB 
-//!           (Electronic Code Book).
-//!     
-//!
-//*****************************************************************************
 
 void aes_decrypt(unsigned char *state,
                  unsigned char *key)
@@ -478,20 +330,6 @@
     aes_decr(state, expandedKey);
 }
 
-//*****************************************************************************
-//
-//!  aes_read_key
-//!
-//!  @param[out]  key   AES128 key of size 16 bytes
-//!
-//!  @return  on success 0, error otherwise.
-//!
-//!  @brief   Reads AES128 key from EEPROM
-//!           Reads the AES128 key from fileID #12 in EEPROM
-//!           returns an error if the key does not exist. 
-//!     
-//!
-//*****************************************************************************
 
 signed long aes_read_key(unsigned char *key)
 {
@@ -502,19 +340,6 @@
     return returnValue;
 }
 
-//*****************************************************************************
-//
-//!  aes_write_key
-//!
-//!  @param[out]  key   AES128 key of size 16 bytes
-//!
-//!  @return  on success 0, error otherwise.
-//!
-//!  @brief   writes AES128 key from EEPROM
-//!           Writes the AES128 key to fileID #12 in EEPROM
-//!     
-//!
-//*****************************************************************************
 
 signed long aes_write_key(unsigned char *key)
 {
@@ -527,10 +352,3 @@
 
 #endif //CC3000_UNENCRYPTED_SMART_CONFIG
 
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
-
--- a/security.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/security.h	Mon Jul 15 14:19:46 2013 +0000
@@ -35,19 +35,13 @@
 #ifndef __SECURITY__
 #define __SECURITY__
 
-//#include "mbed.h"
 #include "GlobalAssigns.h"
 #include "nvmem.h"
 
 /** CC3000 Host driver - Security
 *
 */
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -55,75 +49,130 @@
 
 #define AES128_KEY_SIZE        16
 
+
 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
 
+// forward sbox
+const unsigned char sbox[256] =   { 
+//0     1    2      3     4    5     6     7      8    9     A      B    C     D     E     F
+0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, //0
+0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, //1
+0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, //2
+0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, //3
+0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, //4
+0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, //5
+0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, //6
+0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, //7
+0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, //8
+0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, //9
+0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, //A
+0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, //B
+0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, //C
+0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, //D
+0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, //E
+0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; //F   
+// inverse sbox
+const unsigned char rsbox[256] =
+{ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
+, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
+, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
+, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
+, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
+, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
+, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
+, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
+, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
+, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
+, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
+, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
+, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
+, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
+, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
+, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };
+// round constant
+const unsigned char Rcon[11] = {0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
 
-//*****************************************************************************
-//
-//!  aes_encrypt
-//!
-//!  @param[in]  key   AES128 key of size 16 bytes
-//!  @param[in\out] state   16 bytes of plain text and cipher text
-//!
-//!  @return  none
-//!
-//!  @brief   AES128 encryption:
-//!           Given AES128 key and  16 bytes plain text, cipher text of 16 bytes
-//!           is computed. The AES implementation is in mode ECB (Electronic 
-//!           Code Book). 
-//!     
-//!
-//*****************************************************************************
+/**
+* expend a 16 bytes key for AES128 implementation
+* @param   key          AES128 key - 16 bytes
+* @param   expandedKey  expanded AES128 key
+* @return  none
+*/
+void expandKey(unsigned char *expandedKey, unsigned char *key);
+
+/**
+* multiply by 2 in the galois field
+* @param   value    argument to multiply
+* @return  multiplied argument
+*/
+unsigned char galois_mul2(unsigned char value);
+
+/**
+* internal implementation of AES128 encryption.
+* straight forward aes encryption implementation
+* first the group of operations
+* - addRoundKey
+* - subbytes
+* - shiftrows
+* - mixcolums
+* is executed 9 times, after this addroundkey to finish the 9th 
+* round, after that the 10th round without mixcolums
+* no further subfunctions to save cycles for function calls
+* no structuring with "for (....)" to save cycles.
+* @param[in]  expandedKey expanded AES128 key
+* @param[in/out] state 16 bytes of plain text and cipher text
+* @return  none
+*/
+void aes_encr(unsigned char *state, unsigned char *expandedKey);
+
+/**
+* internal implementation of AES128 decryption.
+* straightforward aes decryption implementation
+* the order of substeps is the exact reverse of decryption
+* inverse functions:
+* - addRoundKey is its own inverse
+* - rsbox is inverse of sbox
+* - rightshift instead of leftshift
+* - invMixColumns = barreto + mixColumns
+* no further subfunctions to save cycles for function calls
+* no structuring with "for (....)" to save cycles
+* @param[in]     expandedKey expanded AES128 key
+* @param[in\out] state 16 bytes of cipher text and plain text
+* @return  none
+*/
+void aes_decr(unsigned char *state, unsigned char *expandedKey);
+
+/**
+* AES128 encryption: Given AES128 key and 16 bytes plain text, cipher text of 16 bytes is
+*                    computed. The AES implementation is in mode ECB (Electronic Code Book). 
+* @param[in]  key   AES128 key of size 16 bytes
+* @param[in\out] state   16 bytes of plain text and cipher text
+* @return  none
+*/
 extern void aes_encrypt(unsigned char *state, unsigned char *key);
 
-//*****************************************************************************
-//
-//!  aes_decrypt
-//!
-//!  @param[in]  key   AES128 key of size 16 bytes
-//!  @param[in\out] state   16 bytes of cipher text and plain text
-//!
-//!  @return  none
-//!
-//!  @brief   AES128 decryption:
-//!           Given AES128 key and  16 bytes cipher text, plain text of 16 bytes
-//!           is computed The AES implementation is in mode ECB 
-//!           (Electronic Code Book).
-//!     
-//!
-//*****************************************************************************
+/**
+* AES128 decryption: Given AES128 key and  16 bytes cipher text, plain text of 16 bytes is
+*                    computed The AES implementation is in mode ECB (Electronic Code Book).
+* @param[in]  key   AES128 key of size 16 bytes
+* @param[in\out] state   16 bytes of cipher text and plain text
+* @return  none
+*/
 extern void aes_decrypt(unsigned char *state, unsigned char *key);
 
 
-//*****************************************************************************
-//
-//!  aes_read_key
-//!
-//!  @param[out]  key   AES128 key of size 16 bytes
-//!
-//!  @return  on success 0, error otherwise.
-//!
-//!  @brief   Reads AES128 key from EEPROM
-//!           Reads the AES128 key from fileID #12 in EEPROM
-//!           returns an error if the key does not exist. 
-//!     
-//!
-//*****************************************************************************
+/**
+* Read the AES128 key from fileID #12 in EEPROM
+* @param[out]  key   AES128 key of size 16 bytes
+* @return  0 on success, error otherwise.
+*/
 extern signed long aes_read_key(unsigned char *key);
 
-//*****************************************************************************
-//
-//!  aes_write_key
-//!
-//!  @param[out]  key   AES128 key of size 16 bytes
-//!
-//!  @return  on success 0, error otherwise.
-//!
-//!  @brief   writes AES128 key from EEPROM
-//!           Writes the AES128 key to fileID #12 in EEPROM
-//!     
-//!
-//*****************************************************************************
+/**
+* Write the AES128 key to fileID #12 in EEPROM
+* @param[out]  key   AES128 key of size 16 bytes
+* @return  on success 0, error otherwise.
+*/
 extern signed long aes_write_key(unsigned char *key);
 
 #endif //CC3000_UNENCRYPTED_SMART_CONFIG
--- a/socket.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/socket.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -33,89 +33,19 @@
 *
 *****************************************************************************/
 
-//*****************************************************************************
-//
-//! \addtogroup socket_api
-//! @{
-//
-//*****************************************************************************
-
-/*#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>*/
 #include "socket.h"
 #include "hci.h"
 #include "evnt_handler.h"
 #include "netapp.h"
 
-//Enable this flag if and only if you must comply with BSD socket 
-//close() function
-#ifdef _API_USE_BSD_CLOSE
-   #define close(sd) closesocket(sd)
-#endif
 
-//Enable this flag if and only if you must comply with BSD socket read() and 
-//write() functions
-#ifdef _API_USE_BSD_READ_WRITE
-              #define read(sd, buf, len, flags) recv(sd, buf, len, flags)
-              #define write(sd, buf, len, flags) send(sd, buf, len, flags)
-#endif
-
-#define SOCKET_OPEN_PARAMS_LEN                 (12)
-#define SOCKET_CLOSE_PARAMS_LEN                (4)
-#define SOCKET_ACCEPT_PARAMS_LEN               (4)
-#define SOCKET_BIND_PARAMS_LEN                 (20)
-#define SOCKET_LISTEN_PARAMS_LEN               (8)
-#define SOCKET_GET_HOST_BY_NAME_PARAMS_LEN     (9)
-#define SOCKET_CONNECT_PARAMS_LEN              (20)
-#define SOCKET_SELECT_PARAMS_LEN               (44)
-#define SOCKET_SET_SOCK_OPT_PARAMS_LEN         (20)
-#define SOCKET_GET_SOCK_OPT_PARAMS_LEN         (12)
-#define SOCKET_RECV_FROM_PARAMS_LEN            (12)
-#define SOCKET_SENDTO_PARAMS_LEN               (24)
-#define SOCKET_MDNS_ADVERTISE_PARAMS_LEN       (12)
-
-#define NULL 0
-
-// The legnth of arguments for the SEND command: sd + buff_offset + len + flags, 
-// while size of each parameter is 32 bit - so the total length is 16 bytes;
-
-#define HCI_CMND_SEND_ARG_LENGTH    (16)
-
-
-#define SELECT_TIMEOUT_MIN_MICRO_SECONDS  5000
-
-#define HEADERS_SIZE_DATA       (SPI_HEADER_SIZE + 5)
-
-#define SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE  (SPI_HEADER_SIZE + SIMPLE_LINK_HCI_CMND_HEADER_SIZE)
-
-#define MDNS_DEVICE_SERVICE_MAX_LENGTH     (32)
-
-
-//*****************************************************************************
-//
-//! HostFlowControlConsumeBuff
-//!
-//!  @param  sd  socket descriptor
-//!
-//!  @return 0 in case there are buffers available, 
-//!          -1 in case of bad socket
-//!          -2 if there are no free buffers present (only when 
-//!          SEND_NON_BLOCKING is enabled)
-//!
-//!  @brief  if SEND_NON_BLOCKING not define - block until have free buffer 
-//!          becomes available, else return immediately  with correct status 
-//!          regarding the buffers available.
-//
-//*****************************************************************************
 int HostFlowControlConsumeBuff(int sd)
 {
 #ifndef SEND_NON_BLOCKING
     /* wait in busy loop */
     do
     {
-        // In case last transmission failed then we will return the last failure 
-        // reason here.
+        // When the last transmission failed, return the last failure reason.
         // Note that the buffer will not be allocated in this case
         if (tSLInformation.slTransmitDataError != 0)
         {
@@ -133,8 +63,7 @@
     return 0;
 #else
     
-    // In case last transmission failed then we will return the last failure 
-    // reason here.
+    // When the last transmission failed, return the last failure reason.
     // Note that the buffer will not be allocated in this case
     if (tSLInformation.slTransmitDataError != 0)
     {
@@ -145,7 +74,7 @@
     if(SOCKET_STATUS_ACTIVE != get_socket_active_status(sd))
         return -1;
     
-    //If there are no available buffers, return -2. It is recommended to use  
+    // If there are no available buffers, return -2. It is recommended to use  
     // select or receive to see if there is any buffer occupied with received data
     // If so, call receive() to release the buffer.
     if(0 == tSLInformation.usNumberOfFreeBuffers)
@@ -160,27 +89,6 @@
 #endif
 }
 
-//*****************************************************************************
-//
-//! socket
-//!
-//!  @param  domain    selects the protocol family which will be used for 
-//!                    communication. On this version only AF_INET is supported
-//!  @param  type      specifies the communication semantics. On this version 
-//!                    only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported
-//!  @param  protocol  specifies a particular protocol to be used with the 
-//!                    socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are 
-//!                    supported.
-//!
-//!  @return  On success, socket handle that is used for consequent socket 
-//!           operations. On error, -1 is returned.
-//!
-//!  @brief  create an endpoint for communication
-//!          The socket function creates a socket that is bound to a specific 
-//!          transport service provider. This function is called by the 
-//!          application layer to obtain a socket handle.
-//
-//*****************************************************************************
 
 int socket(long domain, long type, long protocol)
 {
@@ -210,17 +118,6 @@
     return(ret);
 }
 
-//*****************************************************************************
-//
-//! closesocket
-//!
-//!  @param  sd    socket handle.
-//!
-//!  @return  On success, zero is returned. On error, -1 is returned.
-//!
-//!  @brief  The socket function closes a created socket.
-//
-//*****************************************************************************
 
 long closesocket(long sd)
 {
@@ -241,57 +138,12 @@
     SimpleLinkWaitEvent(HCI_CMND_CLOSE_SOCKET, &ret);
     errno = ret;
     
-    // since 'close' call may result in either OK (and then it closed) or error 
-    // mark this socket as invalid 
+    // since 'close' call may result in either OK (and then it closed) or error, mark this socket as invalid 
     set_socket_active_status(sd, SOCKET_STATUS_INACTIVE);
     
     return(ret);
 }
 
-//*****************************************************************************
-//
-//! accept
-//!
-//!  @param[in]   sd      socket descriptor (handle)              
-//!  @param[out]  addr    the argument addr is a pointer to a sockaddr structure
-//!                       This structure is filled in with the address of the  
-//!                       peer socket, as known to the communications layer.        
-//!                       determined. The exact format of the address returned             
-//!                       addr is by the socket's address sockaddr. 
-//!                       On this version only AF_INET is supported.
-//!                       This argument returns in network order.
-//!  @param[out] addrlen  the addrlen argument is a value-result argument: 
-//!                       it should initially contain the size of the structure
-//!                       pointed to by addr.
-//!
-//!  @return  For socket in blocking mode:
-//!                      On success, socket handle. on failure negative
-//!                  For socket in non-blocking mode:
-//!                     - On connection establishment, socket handle
-//!                     - On connection pending, SOC_IN_PROGRESS (-2)
-//!                   - On failure, SOC_ERROR    (-1)
-//!
-//!  @brief  accept a connection on a socket:
-//!          This function is used with connection-based socket types 
-//!          (SOCK_STREAM). It extracts the first connection request on the 
-//!          queue of pending connections, creates a new connected socket, and
-//!          returns a new file descriptor referring to that socket.
-//!          The newly created socket is not in the listening state. 
-//!          The original socket sd is unaffected by this call. 
-//!          The argument sd is a socket that has been created with socket(),
-//!          bound to a local address with bind(), and is  listening for 
-//!          connections after a listen(). The argument addr is a pointer 
-//!          to a sockaddr structure. This structure is filled in with the 
-//!          address of the peer socket, as known to the communications layer.
-//!          The exact format of the address returned addr is determined by the 
-//!          socket's address family. The addrlen argument is a value-result
-//!          argument: it should initially contain the size of the structure
-//!          pointed to by addr, on return it will contain the actual 
-//!          length (in bytes) of the address returned.
-//!
-//! @sa     socket ; bind ; listen
-//
-//*****************************************************************************
 
 long accept(long sd, sockaddr *addr, socklen_t *addrlen)
 {
@@ -332,28 +184,6 @@
     return(ret);
 }
 
-//*****************************************************************************
-//
-//! bind
-//!
-//!  @param[in]   sd      socket descriptor (handle)              
-//!  @param[out]  addr    specifies the destination address. On this version 
-//!                       only AF_INET is supported.
-//!  @param[out] addrlen  contains the size of the structure pointed to by addr.
-//!
-//!  @return      On success, zero is returned. On error, -1 is returned.
-//!
-//!  @brief  assign a name to a socket
-//!          This function gives the socket the local address addr.
-//!          addr is addrlen bytes long. Traditionally, this is called when a 
-//!          socket is created with socket, it exists in a name space (address 
-//!          family) but has no name assigned.
-//!          It is necessary to assign a local address before a SOCK_STREAM
-//!          socket may receive connections.
-//!
-//! @sa     socket ; accept ; listen
-//
-//*****************************************************************************
 
 long bind(long sd, const sockaddr *addr, long addrlen)
 {
@@ -383,28 +213,6 @@
     return(ret);
 }
 
-//*****************************************************************************
-//
-//! listen
-//!
-//!  @param[in]   sd      socket descriptor (handle)              
-//!  @param[in]  backlog  specifies the listen queue depth. On this version
-//!                       backlog is not supported.
-//!  @return      On success, zero is returned. On error, -1 is returned.
-//!
-//!  @brief  listen for connections on a socket
-//!          The willingness to accept incoming connections and a queue
-//!          limit for incoming connections are specified with listen(),
-//!          and then the connections are accepted with accept.
-//!          The listen() call applies only to sockets of type SOCK_STREAM
-//!          The backlog parameter defines the maximum length the queue of
-//!          pending connections may grow to. 
-//!
-//! @sa     socket ; accept ; bind
-//!
-//! @note   On this version, backlog is not supported
-//
-//*****************************************************************************
 
 long listen(long sd, long backlog)
 {
@@ -429,24 +237,7 @@
     return(ret);
 }
 
-//*****************************************************************************
-//
-//! gethostbyname
-//!
-//!  @param[in]   hostname     host name              
-//!  @param[in]   usNameLen    name length 
-//!  @param[out]  out_ip_addr  This parameter is filled in with host IP address. 
-//!                            In case that host name is not resolved, 
-//!                            out_ip_addr is zero.                  
-//!  @return      On success, positive is returned. On error, negative is returned
-//!
-//!  @brief  Get host IP by name. Obtain the IP Address of machine on network, 
-//!          by its name.
-//!
-//!  @note  On this version, only blocking mode is supported. Also note that
-//!             the function requires DNS server to be configured prior to its usage.
-//
-//*****************************************************************************
+
 #ifndef CC3000_TINY_DRIVER
 int gethostbyname(char * hostname, unsigned short usNameLen, unsigned long* out_ip_addr)
 {
@@ -483,34 +274,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//! connect
-//!
-//!  @param[in]   sd       socket descriptor (handle)         
-//!  @param[in]   addr     specifies the destination addr. On this version
-//!                        only AF_INET is supported.
-//!  @param[out]  addrlen  contains the size of the structure pointed to by addr    
-//!  @return      On success, zero is returned. On error, -1 is returned
-//!
-//!  @brief  initiate a connection on a socket 
-//!          Function connects the socket referred to by the socket descriptor 
-//!          sd, to the address specified by addr. The addrlen argument 
-//!          specifies the size of addr. The format of the address in addr is 
-//!          determined by the address space of the socket. If it is of type 
-//!          SOCK_DGRAM, this call specifies the peer with which the socket is 
-//!          to be associated; this address is that to which datagrams are to be
-//!          sent, and the only address from which datagrams are to be received.  
-//!          If the socket is of type SOCK_STREAM, this call attempts to make a 
-//!          connection to another socket. The other socket is specified  by 
-//!          address, which is an address in the communications space of the
-//!          socket. Note that the function implements only blocking behavior 
-//!          thus the caller will be waiting either for the connection 
-//!          establishment or for the connection establishment failure.
-//!
-//!  @sa socket
-//
-//*****************************************************************************
 
 long connect(long sd, const sockaddr *addr, long addrlen)
 {
@@ -540,44 +303,6 @@
 }
 
 
-//*****************************************************************************
-//
-//! select
-//!
-//!  @param[in]   nfds       the highest-numbered file descriptor in any of the
-//!                           three sets, plus 1.     
-//!  @param[out]   writesds   socket descriptors list for write monitoring
-//!  @param[out]   readsds    socket descriptors list for read monitoring  
-//!  @param[out]   exceptsds  socket descriptors list for exception monitoring
-//!  @param[in]   timeout     is an upper bound on the amount of time elapsed
-//!                           before select() returns. Null means infinity 
-//!                           timeout. The minimum timeout is 5 milliseconds,
-//!                          less than 5 milliseconds will be set
-//!                           automatically to 5 milliseconds.
-//!  @return      On success, select() returns the number of file descriptors
-//!             contained in the three returned descriptor sets (that is, the
-//!             total number of bits that are set in readfds, writefds,
-//!             exceptfds) which may be zero if the timeout expires before
-//!             anything interesting  happens.
-//!             On error, -1 is returned.
-//!                   *readsds - return the sockets on which Read request will
-//!                              return without delay with valid data.
-//!                   *writesds - return the sockets on which Write request 
-//!                                 will return without delay.
-//!                   *exceptsds - return the sockets which closed recently.
-//!
-//!  @brief  Monitor socket activity  
-//!          Select allow a program to monitor multiple file descriptors,
-//!          waiting until one or more of the file descriptors become 
-//!         "ready" for some class of I/O operation 
-//!
-//!  @Note   If the timeout value set to less than 5ms it will automatically set
-//!          to 5ms to prevent overload of the system
-//!
-//!  @sa socket
-//
-//*****************************************************************************
-
 int select(long nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout)
 {
     unsigned char *ptr, *args;
@@ -652,52 +377,6 @@
     }
 }
 
-//*****************************************************************************
-//
-//! setsockopt
-//!
-//!  @param[in]   sd          socket handle
-//!  @param[in]   level       defines the protocol level for this option
-//!  @param[in]   optname     defines the option name to Interrogate
-//!  @param[in]   optval      specifies a value for the option
-//!  @param[in]   optlen      specifies the length of the option value
-//!  @return      On success, zero is returned. On error, -1 is returned
-//!
-//!  @brief  set socket options
-//!          This function manipulate the options associated with a socket.
-//!          Options may exist at multiple protocol levels; they are always
-//!          present at the uppermost socket level.
-//!          When manipulating socket options the level at which the option 
-//!          resides and the name of the option must be specified.  
-//!          To manipulate options at the socket level, level is specified as 
-//!          SOL_SOCKET. To manipulate options at any other level the protocol 
-//!          number of the appropriate protocol controlling the option is 
-//!          supplied. For example, to indicate that an option is to be 
-//!          interpreted by the TCP protocol, level should be set to the 
-//!          protocol number of TCP; 
-//!          The parameters optval and optlen are used to access optval - 
-//!          use for setsockopt(). For getsockopt() they identify a buffer
-//!          in which the value for the requested option(s) are to 
-//!          be returned. For getsockopt(), optlen is a value-result 
-//!          parameter, initially containing the size of the buffer 
-//!          pointed to by option_value, and modified on return to 
-//!          indicate the actual size of the value returned. If no option 
-//!          value is to be supplied or returned, option_value may be NULL.
-//!
-//!  @Note   On this version the following two socket options are enabled:
-//!                 The only protocol level supported in this version
-//!          is SOL_SOCKET (level).
-//!               1. SOCKOPT_RECV_TIMEOUT (optname)
-//!                  SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout 
-//!           in milliseconds.
-//!                In that case optval should be pointer to unsigned long.
-//!               2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on 
-//!           or off.
-//!                In that case optval should be SOCK_ON or SOCK_OFF (optval).
-//!
-//!  @sa getsockopt
-//
-//*****************************************************************************
 
 #ifndef CC3000_TINY_DRIVER
 int setsockopt(long sd, long level, long optname, const void *optval, socklen_t optlen)
@@ -734,52 +413,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//! getsockopt
-//!
-//!  @param[in]   sd          socket handle
-//!  @param[in]   level       defines the protocol level for this option
-//!  @param[in]   optname     defines the option name to Interrogate
-//!  @param[out]   optval      specifies a value for the option
-//!  @param[out]   optlen      specifies the length of the option value
-//!  @return      On success, zero is returned. On error, -1 is returned
-//!
-//!  @brief  set socket options
-//!          This function manipulate the options associated with a socket.
-//!          Options may exist at multiple protocol levels; they are always
-//!          present at the uppermost socket level.
-//!          When manipulating socket options the level at which the option 
-//!          resides and the name of the option must be specified.  
-//!          To manipulate options at the socket level, level is specified as 
-//!          SOL_SOCKET. To manipulate options at any other level the protocol 
-//!          number of the appropriate protocol controlling the option is 
-//!          supplied. For example, to indicate that an option is to be 
-//!          interpreted by the TCP protocol, level should be set to the 
-//!          protocol number of TCP; 
-//!          The parameters optval and optlen are used to access optval - 
-//!          use for setsockopt(). For getsockopt() they identify a buffer
-//!          in which the value for the requested option(s) are to 
-//!          be returned. For getsockopt(), optlen is a value-result 
-//!          parameter, initially containing the size of the buffer 
-//!          pointed to by option_value, and modified on return to 
-//!          indicate the actual size of the value returned. If no option 
-//!          value is to be supplied or returned, option_value may be NULL.
-//!
-//!  @Note   On this version the following two socket options are enabled:
-//!                 The only protocol level supported in this version
-//!          is SOL_SOCKET (level).
-//!               1. SOCKOPT_RECV_TIMEOUT (optname)
-//!                  SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout 
-//!           in milliseconds.
-//!                In that case optval should be pointer to unsigned long.
-//!               2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on 
-//!           or off.
-//!                In that case optval should be SOCK_ON or SOCK_OFF (optval).
-//!
-//!  @sa setsockopt
-//
-//*****************************************************************************
 
 int
 getsockopt (long sd, long level, long optname, void *optval, socklen_t *optlen)
@@ -814,27 +447,7 @@
     }
 }
 
-//*****************************************************************************
-//
-//!  simple_link_recv
-//!
-//!  @param sd       socket handle
-//!  @param buf      read buffer
-//!  @param len      buffer length
-//!  @param flags    indicates blocking or non-blocking operation
-//!  @param from     pointer to an address structure indicating source address
-//!  @param fromlen  source address structure size
-//!
-//!  @return         Return the number of bytes received, or -1 if an error
-//!                  occurred
-//!
-//!  @brief          Read data from socket
-//!                  Return the length of the message on successful completion.
-//!                  If a message is too long to fit in the supplied buffer,
-//!                  excess bytes may be discarded depending on the type of
-//!                  socket the message is received from
-//
-//*****************************************************************************
+
 int simple_link_recv(long sd, void *buf, long len, long flags, sockaddr *from, socklen_t *fromlen, long opcode)
 {
     unsigned char *ptr, *args;
@@ -867,86 +480,19 @@
     return(tSocketReadEvent.iNumberOfBytes);
 }
 
-//*****************************************************************************
-//
-//!  recv
-//!
-//!  @param[in]  sd     socket handle
-//!  @param[out] buf    Points to the buffer where the message should be stored
-//!  @param[in]  len    Specifies the length in bytes of the buffer pointed to 
-//!                     by the buffer argument.
-//!  @param[in] flags   Specifies the type of message reception. 
-//!                     On this version, this parameter is not supported.
-//!
-//!  @return         Return the number of bytes received, or -1 if an error
-//!                  occurred
-//!
-//!  @brief          function receives a message from a connection-mode socket
-//!
-//!  @sa recvfrom
-//!
-//!  @Note On this version, only blocking mode is supported.
-//
-//*****************************************************************************
 
 int recv(long sd, void *buf, long len, long flags)
 {
     return(simple_link_recv(sd, buf, len, flags, NULL, NULL, HCI_CMND_RECV));
 }
 
-//*****************************************************************************
-//
-//!  recvfrom
-//!
-//!  @param[in]  sd     socket handle
-//!  @param[out] buf    Points to the buffer where the message should be stored
-//!  @param[in]  len    Specifies the length in bytes of the buffer pointed to 
-//!                     by the buffer argument.
-//!  @param[in] flags   Specifies the type of message reception. 
-//!                     On this version, this parameter is not supported.
-//!  @param[in] from   pointer to an address structure indicating the source
-//!                    address: sockaddr. On this version only AF_INET is
-//!                    supported.
-//!  @param[in] fromlen   source address tructure size
-//!
-//!  @return         Return the number of bytes received, or -1 if an error
-//!                  occurred
-//!
-//!  @brief         read data from socket
-//!                 function receives a message from a connection-mode or
-//!                 connectionless-mode socket. Note that raw sockets are not
-//!                 supported.
-//!
-//!  @sa recv
-//!
-//!  @Note On this version, only blocking mode is supported.
-//
-//*****************************************************************************
+
 int recvfrom(long sd, void *buf, long len, long flags, sockaddr *from, socklen_t *fromlen)
 {
     return(simple_link_recv(sd, buf, len, flags, from, fromlen, HCI_CMND_RECVFROM));
 }
 
-//*****************************************************************************
-//
-//!  simple_link_send
-//!
-//!  @param sd       socket handle
-//!  @param buf      write buffer
-//!  @param len      buffer length
-//!  @param flags    On this version, this parameter is not supported
-//!  @param to       pointer to an address structure indicating destination
-//!                  address
-//!  @param tolen    destination address structure size
-//!
-//!  @return         Return the number of bytes transmitted, or -1 if an error
-//!                  occurred, or -2 in case there are no free buffers available
-//!                 (only when SEND_NON_BLOCKING is enabled)
-//!
-//!  @brief          This function is used to transmit a message to another
-//!                  socket
-//
-//*****************************************************************************
+
 int simple_link_send(long sd, const void *buf, long len, long flags, const sockaddr *to, long tolen, long opcode)
 {    
     unsigned char uArgSize = 0x00,  addrlen = 0x00;
@@ -1027,80 +573,17 @@
 }
 
 
-//*****************************************************************************
-//
-//!  send
-//!
-//!  @param sd       socket handle
-//!  @param buf      Points to a buffer containing the message to be sent
-//!  @param len      message size in bytes
-//!  @param flags    On this version, this parameter is not supported
-//!
-//!  @return         Return the number of bytes transmitted, or -1 if an
-//!                  error occurred
-//!
-//!  @brief          Write data to TCP socket
-//!                  This function is used to transmit a message to another 
-//!                  socket.
-//!
-//!  @Note           On this version, only blocking mode is supported.
-//!
-//!  @sa             sendto
-//
-//*****************************************************************************
-
 int send(long sd, const void *buf, long len, long flags)
 {
     return(simple_link_send(sd, buf, len, flags, NULL, 0, HCI_CMND_SEND));
 }
 
-//*****************************************************************************
-//
-//!  sendto
-//!
-//!  @param sd       socket handle
-//!  @param buf      Points to a buffer containing the message to be sent
-//!  @param len      message size in bytes
-//!  @param flags    On this version, this parameter is not supported
-//!  @param to       pointer to an address structure indicating the destination
-//!                  address: sockaddr. On this version only AF_INET is
-//!                  supported.
-//!  @param tolen    destination address structure size
-//!
-//!  @return         Return the number of bytes transmitted, or -1 if an
-//!                  error occurred
-//!
-//!  @brief          Write data to TCP socket
-//!                  This function is used to transmit a message to another 
-//!                  socket.
-//!
-//!  @Note           On this version, only blocking mode is supported.
-//!
-//!  @sa             send
-//
-//*****************************************************************************
 
 int sendto(long sd, const void *buf, long len, long flags, const sockaddr *to, socklen_t tolen)
 {
     return(simple_link_send(sd, buf, len, flags, to, tolen, HCI_CMND_SENDTO));
 }
 
-//*****************************************************************************
-//
-//!  mdnsAdvertiser
-//!
-//!  @param[in] mdnsEnabled         flag to enable/disable the mDNS feature
-//!  @param[in] deviceServiceName   Service name as part of the published
-//!                                 canonical domain name
-//!  @param[in] deviceServiceNameLength   Length of the service name
-//!  
-//!
-//!  @return   On success, zero is returned, return SOC_ERROR if socket was not 
-//!            opened successfully, or if an error occurred.
-//!
-//!  @brief    Set CC3000 in mDNS advertiser mode in order to advertise itself.
-//
-//*****************************************************************************
 
 int mdnsAdvertiser(unsigned short mdnsEnabled, char * deviceServiceName, unsigned short deviceServiceNameLength)
 {
@@ -1131,5 +614,3 @@
     
 }
 
-
-
--- a/socket.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/socket.h	Mon Jul 15 14:19:46 2013 +0000
@@ -35,29 +35,55 @@
 #ifndef __SOCKET_H__
 #define __SOCKET_H__
 
-//#include "mbed.h"
 #include "GlobalAssigns.h"
+
 /** CC3000 Host driver - Socket API
 *
 */
-//*****************************************************************************
-//
-//! \addtogroup socket_api
-//! @{
-//
-//*****************************************************************************
 
-
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
+//Enable this flag if and only if you must comply with BSD socket 
+//close() function
+#ifdef _API_USE_BSD_CLOSE
+    #define close(sd) closesocket(sd)
+#endif
+
+//Enable this flag if and only if you must comply with BSD socket read() and 
+//write() functions
+#ifdef _API_USE_BSD_READ_WRITE
+    #define read(sd, buf, len, flags) recv(sd, buf, len, flags)
+    #define write(sd, buf, len, flags) send(sd, buf, len, flags)
+#endif
+
+#define SOCKET_OPEN_PARAMS_LEN                 (12)
+#define SOCKET_CLOSE_PARAMS_LEN                (4)
+#define SOCKET_ACCEPT_PARAMS_LEN               (4)
+#define SOCKET_BIND_PARAMS_LEN                 (20)
+#define SOCKET_LISTEN_PARAMS_LEN               (8)
+#define SOCKET_GET_HOST_BY_NAME_PARAMS_LEN     (9)
+#define SOCKET_CONNECT_PARAMS_LEN              (20)
+#define SOCKET_SELECT_PARAMS_LEN               (44)
+#define SOCKET_SET_SOCK_OPT_PARAMS_LEN         (20)
+#define SOCKET_GET_SOCK_OPT_PARAMS_LEN         (12)
+#define SOCKET_RECV_FROM_PARAMS_LEN            (12)
+#define SOCKET_SENDTO_PARAMS_LEN               (24)
+#define SOCKET_MDNS_ADVERTISE_PARAMS_LEN       (12)
+
+//#define NULL 0
+
+// The legnth of arguments for the SEND command: sd + buff_offset + len + flags, 
+// while size of each parameter is 32 bit - so the total length is 16 bytes;
+
+#define HCI_CMND_SEND_ARG_LENGTH                    (16)
+#define SELECT_TIMEOUT_MIN_MICRO_SECONDS            5000
+#define HEADERS_SIZE_DATA                           (SPI_HEADER_SIZE + 5)
+#define SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE  (SPI_HEADER_SIZE + SIMPLE_LINK_HCI_CMND_HEADER_SIZE)
+#define MDNS_DEVICE_SERVICE_MAX_LENGTH              (32)
+
+
 #define HOSTNAME_MAX_LENGTH (230)  // 230 bytes + header shouldn't exceed 8 bit value
 
 //--------- Address Families --------
@@ -88,12 +114,12 @@
 //----------- Socket retunr codes  -----------
 
 #define SOC_ERROR                (-1)        // error 
-#define SOC_IN_PROGRESS            (-2)        // socket in progress
+#define SOC_IN_PROGRESS          (-2)        // socket in progress
 
 //----------- Socket Options -----------
-#define  SOL_SOCKET             0xffff        //  socket level
-#define  SOCKOPT_RECV_TIMEOUT    1            //  optname to configure recv and recvfromtimeout
-#define  SOCKOPT_NONBLOCK          2            // accept non block mode set SOCK_ON or SOCK_OFF (default block mode )
+#define  SOL_SOCKET             0xffff       //  socket level
+#define  SOCKOPT_RECV_TIMEOUT   1            //  optname to configure recv and recvfromtimeout
+#define  SOCKOPT_NONBLOCK       2            // accept non block mode set SOCK_ON or SOCK_OFF (default block mode )
 #define  SOCK_ON                0            // socket non-blocking mode    is enabled        
 #define  SOCK_OFF               1            // socket blocking mode is enabled
 
@@ -121,8 +147,8 @@
 
 typedef struct _sockaddr_t
 {
-    unsigned short int    sa_family;
-    unsigned char     sa_data[14];
+    unsigned short int  sa_family;
+    unsigned char       sa_data[14];
 } sockaddr;
 
 typedef struct _sockaddr_in_t
@@ -186,12 +212,12 @@
 #define ntohs                   htons
 
 // mDNS port - 5353    mDNS multicast address - 224.0.0.251 
-#define SET_mDNS_ADD(sockaddr)                sockaddr.sa_data[0] = 0x14; \
-                                                                                                sockaddr.sa_data[1] = 0xe9; \
-                                                                                                sockaddr.sa_data[2] = 0xe0; \
-                                                                                                sockaddr.sa_data[3] = 0x0; \
-                                                                                                sockaddr.sa_data[4] = 0x0; \
-                                                                                                sockaddr.sa_data[5] = 0xfb; 
+#define SET_mDNS_ADD(sockaddr) sockaddr.sa_data[0] = 0x14; \
+                               sockaddr.sa_data[1] = 0xe9; \
+                               sockaddr.sa_data[2] = 0xe0; \
+                               sockaddr.sa_data[3] = 0x0;  \
+                               sockaddr.sa_data[4] = 0x0;  \
+                               sockaddr.sa_data[5] = 0xfb; 
 
 
 //*****************************************************************************
@@ -200,466 +226,368 @@
 //
 //*****************************************************************************
 
-//*****************************************************************************
-//
-//! socket
-//!
-//!  @param  domain    selects the protocol family which will be used for 
-//!                    communication. On this version only AF_INET is supported
-//!  @param  type      specifies the communication semantics. On this version 
-//!                    only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported
-//!  @param  protocol  specifies a particular protocol to be used with the 
-//!                    socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are 
-//!                    supported.
-//!
-//!  @return  On success, socket handle that is used for consequent socket 
-//!           operations. On error, -1 is returned.
-//!
-//!  @brief  create an endpoint for communication
-//!          The socket function creates a socket that is bound to a specific 
-//!          transport service provider. This function is called by the 
-//!          application layer to obtain a socket handle.
-//
-//*****************************************************************************
+/**
+* HostFlowControlConsumeBuff
+* if SEND_NON_BLOCKING is not defined - block until a free buffer is available,
+* otherwise return the status of the available buffers.
+* @param  sd  socket descriptor
+* @return  0 in case there are buffers available, 
+*         -1 in case of bad socket
+*         -2 if there are no free buffers present (only when SEND_NON_BLOCKING is enabled)
+*/
+int HostFlowControlConsumeBuff(int sd);
+
+/**
+* create an endpoint for communication
+* The socket function creates a socket that is bound to a specific transport service provider.
+* This function is called by the application layer to obtain a socket handle.
+* @param   domain    selects the protocol family which will be used for 
+*                    communication. On this version only AF_INET is supported
+* @param   type      specifies the communication semantics. On this version 
+*                    only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported
+* @param   protocol  specifies a particular protocol to be used with the 
+*                    socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are supported.
+* @return  On success, socket handle that is used for consequent socket 
+*          operations. On error, -1 is returned.
+*/
 extern int socket(long domain, long type, long protocol);
 
-//*****************************************************************************
-//
-//! closesocket
-//!
-//!  @param  sd    socket handle.
-//!
-//!  @return  On success, zero is returned. On error, -1 is returned.
-//!
-//!  @brief  The socket function closes a created socket.
-//
-//*****************************************************************************
+/**
+* The socket function closes a created socket.
+* @param   sd    socket handle.
+* @return  On success, zero is returned. On error, -1 is returned.
+*/
 extern long closesocket(long sd);
 
-//*****************************************************************************
-//
-//! accept
-//!
-//!  @param[in]   sd      socket descriptor (handle)              
-//!  @param[out]  addr    the argument addr is a pointer to a sockaddr structure
-//!                       This structure is filled in with the address of the  
-//!                       peer socket, as known to the communications layer.        
-//!                       determined. The exact format of the address returned             
-//!                       addr is by the socket's address sockaddr. 
-//!                       On this version only AF_INET is supported.
-//!                       This argument returns in network order.
-//!  @param[out] addrlen  the addrlen argument is a value-result argument: 
-//!                       it should initially contain the size of the structure
-//!                       pointed to by addr.
-//!
-//!  @return  For socket in blocking mode:
-//!                      On success, socket handle. on failure negative
-//!                  For socket in non-blocking mode:
-//!                     - On connection establishment, socket handle
-//!                     - On connection pending, SOC_IN_PROGRESS (-2)
-//!                   - On failure, SOC_ERROR    (-1)
-//!
-//!  @brief  accept a connection on a socket:
-//!          This function is used with connection-based socket types 
-//!          (SOCK_STREAM). It extracts the first connection request on the 
-//!          queue of pending connections, creates a new connected socket, and
-//!          returns a new file descriptor referring to that socket.
-//!          The newly created socket is not in the listening state. 
-//!          The original socket sd is unaffected by this call. 
-//!          The argument sd is a socket that has been created with socket(),
-//!          bound to a local address with bind(), and is  listening for 
-//!          connections after a listen(). The argument addr is a pointer 
-//!          to a sockaddr structure. This structure is filled in with the 
-//!          address of the peer socket, as known to the communications layer.
-//!          The exact format of the address returned addr is determined by the 
-//!          socket's address family. The addrlen argument is a value-result
-//!          argument: it should initially contain the size of the structure
-//!          pointed to by addr, on return it will contain the actual 
-//!          length (in bytes) of the address returned.
-//!
-//! @sa     socket ; bind ; listen
-//
-//*****************************************************************************
+/**
+* accept a connection on a socket:
+* This function is used with connection-based socket types 
+* (SOCK_STREAM). It extracts the first connection request on the 
+* queue of pending connections, creates a new connected socket, and
+* returns a new file descriptor referring to that socket.
+* The newly created socket is not in the listening state. 
+* The original socket sd is unaffected by this call. 
+* The argument sd is a socket that has been created with socket(),
+* bound to a local address with bind(), and is  listening for 
+* connections after a listen(). The argument addr is a pointer 
+* to a sockaddr structure. This structure is filled in with the 
+* address of the peer socket, as known to the communications layer.
+* The exact format of the address returned addr is determined by the 
+* socket's address family. The addrlen argument is a value-result
+* argument: it should initially contain the size of the structure
+* pointed to by addr, on return it will contain the actual 
+* length (in bytes) of the address returned.
+* @param[in]   sd      socket descriptor (handle)              
+* @param[out]  addr    the argument addr is a pointer to a sockaddr structure
+*                      This structure is filled in with the address of the  
+*                      peer socket, as known to the communications layer.        
+*                      determined. The exact format of the address returned             
+*                      addr is by the socket's address sockaddr. 
+*                      On this version only AF_INET is supported.
+*                      This argument returns in network order.
+* @param[out] addrlen  the addrlen argument is a value-result argument: 
+*                      it should initially contain the size of the structure
+*                      pointed to by addr.
+* @return  For socket in blocking mode:
+*           - On success, socket handle. on failure negative
+*          For socket in non-blocking mode:
+*           - On connection establishment, socket handle
+*           - On connection pending, SOC_IN_PROGRESS (-2)
+*           - On failure, SOC_ERROR    (-1)
+* @sa     socket ; bind ; listen
+*/
 extern long accept(long sd, sockaddr *addr, socklen_t *addrlen);
 
-//*****************************************************************************
-//
-//! bind
-//!
-//!  @param[in]   sd      socket descriptor (handle)              
-//!  @param[out]  addr    specifies the destination address. On this version 
-//!                       only AF_INET is supported.
-//!  @param[out] addrlen  contains the size of the structure pointed to by addr.
-//!
-//!  @return      On success, zero is returned. On error, -1 is returned.
-//!
-//!  @brief  assign a name to a socket
-//!          This function gives the socket the local address addr.
-//!          addr is addrlen bytes long. Traditionally, this is called when a 
-//!          socket is created with socket, it exists in a name space (address 
-//!          family) but has no name assigned.
-//!          It is necessary to assign a local address before a SOCK_STREAM
-//!          socket may receive connections.
-//!
-//! @sa     socket ; accept ; listen
-//
-//*****************************************************************************
+/**
+* assign a name to a socket
+* This function gives the socket the local address addr.
+* addr is addrlen bytes long. Traditionally, this is called when a 
+* socket is created with socket, it exists in a name space (address 
+* family) but has no name assigned.
+* It is necessary to assign a local address before a SOCK_STREAM
+* socket may receive connections.
+* @param[in]   sd      socket descriptor (handle)              
+* @param[out]  addr    specifies the destination address. On this version 
+*                      only AF_INET is supported.
+* @param[out] addrlen  contains the size of the structure pointed to by addr.
+* @return      On success, zero is returned. On error, -1 is returned.
+* @sa          socket ; accept ; listen
+*/
 extern long bind(long sd, const sockaddr *addr, long addrlen);
 
-//*****************************************************************************
-//
-//! listen
-//!
-//!  @param[in]   sd      socket descriptor (handle)              
-//!  @param[in]  backlog  specifies the listen queue depth. On this version
-//!                       backlog is not supported.
-//!  @return      On success, zero is returned. On error, -1 is returned.
-//!
-//!  @brief  listen for connections on a socket
-//!          The willingness to accept incoming connections and a queue
-//!          limit for incoming connections are specified with listen(),
-//!          and then the connections are accepted with accept.
-//!          The listen() call applies only to sockets of type SOCK_STREAM
-//!          The backlog parameter defines the maximum length the queue of
-//!          pending connections may grow to. 
-//!
-//! @sa     socket ; accept ; bind
-//!
-//! @note   On this version, backlog is not supported
-//
-//*****************************************************************************
+/**
+* listen for connections on a socket
+* The willingness to accept incoming connections and a queue
+* limit for incoming connections are specified with listen(),
+* and then the connections are accepted with accept.
+* The listen() call applies only to sockets of type SOCK_STREAM
+* The backlog parameter defines the maximum length the queue of
+* pending connections may grow to. 
+* @param[in]  sd       socket descriptor (handle)              
+* @param[in]  backlog  specifies the listen queue depth. On this version
+*                      backlog is not supported.
+* @return     On success, zero is returned. On error, -1 is returned.
+* @sa         socket ; accept ; bind
+* @note       On this version, backlog is not supported
+*/
 extern long listen(long sd, long backlog);
 
-//*****************************************************************************
-//
-//! gethostbyname
-//!
-//!  @param[in]   hostname     host name              
-//!  @param[in]   usNameLen    name length 
-//!  @param[out]  out_ip_addr  This parameter is filled in with host IP address. 
-//!                            In case that host name is not resolved, 
-//!                            out_ip_addr is zero.                  
-//!  @return      On success, positive is returned. On error, negative is returned
-//!
-//!  @brief  Get host IP by name. Obtain the IP Address of machine on network, 
-//!          by its name.
-//!
-//!  @note  On this version, only blocking mode is supported. Also note that
-//!             the function requires DNS server to be configured prior to its usage.
-//
-//*****************************************************************************
+/**
+* Get host IP by name. Obtain the IP Address of machine on network, 
+* @param[in]   hostname     host name              
+* @param[in]   usNameLen    name length 
+* @param[out]  out_ip_addr  This parameter is filled in with host IP address. 
+*                           In case that host name is not resolved, 
+*                           out_ip_addr is zero.                  
+* @return      On success, positive is returned. On error, negative is returned by its name.
+* @note  On this version, only blocking mode is supported. Also note that
+*        The function requires DNS server to be configured prior to its usage.
+*/
 #ifndef CC3000_TINY_DRIVER 
 extern int gethostbyname(char * hostname, unsigned short usNameLen, unsigned long* out_ip_addr);
 #endif
 
 
-//*****************************************************************************
-//
-//! connect
-//!
-//!  @param[in]   sd       socket descriptor (handle)         
-//!  @param[in]   addr     specifies the destination addr. On this version
-//!                        only AF_INET is supported.
-//!  @param[out]  addrlen  contains the size of the structure pointed to by addr    
-//!  @return      On success, zero is returned. On error, -1 is returned
-//!
-//!  @brief  initiate a connection on a socket 
-//!          Function connects the socket referred to by the socket descriptor 
-//!          sd, to the address specified by addr. The addrlen argument 
-//!          specifies the size of addr. The format of the address in addr is 
-//!          determined by the address space of the socket. If it is of type 
-//!          SOCK_DGRAM, this call specifies the peer with which the socket is 
-//!          to be associated; this address is that to which datagrams are to be
-//!          sent, and the only address from which datagrams are to be received.  
-//!          If the socket is of type SOCK_STREAM, this call attempts to make a 
-//!          connection to another socket. The other socket is specified  by 
-//!          address, which is an address in the communications space of the
-//!          socket. Note that the function implements only blocking behavior 
-//!          thus the caller will be waiting either for the connection 
-//!          establishment or for the connection establishment failure.
-//!
-//!  @sa socket
-//
-//*****************************************************************************
+/**
+* initiate a connection on a socket 
+* Function connects the socket referred to by the socket descriptor 
+* sd, to the address specified by addr. The addrlen argument 
+* specifies the size of addr. The format of the address in addr is 
+* determined by the address space of the socket. If it is of type 
+* SOCK_DGRAM, this call specifies the peer with which the socket is 
+* to be associated; this address is that to which datagrams are to be
+* sent, and the only address from which datagrams are to be received.  
+* If the socket is of type SOCK_STREAM, this call attempts to make a 
+* connection to another socket. The other socket is specified  by 
+* address, which is an address in the communications space of the
+* socket. Note that the function implements only blocking behavior 
+* thus the caller will be waiting either for the connection 
+* establishment or for the connection establishment failure.
+* @param[in]   sd       socket descriptor (handle)         
+* @param[in]   addr     specifies the destination addr. On this version
+*                       only AF_INET is supported.
+* @param[out]  addrlen  contains the size of the structure pointed to by addr    
+* @return      On success, zero is returned. On error, -1 is returned
+* @sa socket
+*/
 extern long connect(long sd, const sockaddr *addr, long addrlen);
 
-//*****************************************************************************
-//
-//! select
-//!
-//!  @param[in]   nfds       the highest-numbered file descriptor in any of the
-//!                           three sets, plus 1.     
-//!  @param[out]   writesds   socket descriptors list for write monitoring
-//!  @param[out]   readsds    socket descriptors list for read monitoring  
-//!  @param[out]   exceptsds  socket descriptors list for exception monitoring
-//!  @param[in]   timeout     is an upper bound on the amount of time elapsed
-//!                           before select() returns. Null means infinity 
-//!                           timeout. The minimum timeout is 5 milliseconds,
-//!                          less than 5 milliseconds will be set
-//!                           automatically to 5 milliseconds.
-//!  @return      On success, select() returns the number of file descriptors
-//!             contained in the three returned descriptor sets (that is, the
-//!             total number of bits that are set in readfds, writefds,
-//!             exceptfds) which may be zero if the timeout expires before
-//!             anything interesting  happens.
-//!             On error, -1 is returned.
-//!                   *readsds - return the sockets on which Read request will
-//!                              return without delay with valid data.
-//!                   *writesds - return the sockets on which Write request 
-//!                                 will return without delay.
-//!                   *exceptsds - return the sockets which closed recently.
-//!
-//!  @brief  Monitor socket activity  
-//!          Select allow a program to monitor multiple file descriptors,
-//!          waiting until one or more of the file descriptors become 
-//!         "ready" for some class of I/O operation 
-//!
-//!  @Note   If the timeout value set to less than 5ms it will automatically set
-//!          to 5ms to prevent overload of the system
-//!
-//!  @sa socket
-//
-//*****************************************************************************
-extern int select(long nfds, fd_set *readsds, fd_set *writesds,
-                  fd_set *exceptsds, struct timeval *timeout);
+/**
+* Monitor socket activity  
+* Select allow a program to monitor multiple file descriptors,
+* waiting until one or more of the file descriptors become 
+*"ready" for some class of I/O operation 
+* @param[in]    nfds       the highest-numbered file descriptor in any of the
+*                          three sets, plus 1.     
+* @param[out]   writesds   socket descriptors list for write monitoring
+* @param[out]   readsds    socket descriptors list for read monitoring  
+* @param[out]   exceptsds  socket descriptors list for exception monitoring
+* @param[in]    timeout    is an upper bound on the amount of time elapsed
+*                          before select() returns. Null means infinity 
+*                          timeout. The minimum timeout is 5 milliseconds,
+*                         less than 5 milliseconds will be set
+*                          automatically to 5 milliseconds.
+* @return    On success, select() returns the number of file descriptors
+*            contained in the three returned descriptor sets (that is, the
+*            total number of bits that are set in readfds, writefds,
+*            exceptfds) which may be zero if the timeout expires before
+*            anything interesting  happens.
+*            On error, -1 is returned.
+*                  *readsds - return the sockets on which Read request will
+*                             return without delay with valid data.
+*                  *writesds - return the sockets on which Write request 
+*                                will return without delay.
+*                  *exceptsds - return the sockets which closed recently.
+* @Note   If the timeout value set to less than 5ms it will automatically
+*         change to 5ms to prevent overload of the system
+* @sa socket
+*/
+extern int select(long nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout);
 
-//*****************************************************************************
-//
-//! setsockopt
-//!
-//!  @param[in]   sd          socket handle
-//!  @param[in]   level       defines the protocol level for this option
-//!  @param[in]   optname     defines the option name to Interrogate
-//!  @param[in]   optval      specifies a value for the option
-//!  @param[in]   optlen      specifies the length of the option value
-//!  @return      On success, zero is returned. On error, -1 is returned
-//!
-//!  @brief  set socket options
-//!          This function manipulate the options associated with a socket.
-//!          Options may exist at multiple protocol levels; they are always
-//!          present at the uppermost socket level.
-//!          When manipulating socket options the level at which the option 
-//!          resides and the name of the option must be specified.  
-//!          To manipulate options at the socket level, level is specified as 
-//!          SOL_SOCKET. To manipulate options at any other level the protocol 
-//!          number of the appropriate protocol controlling the option is 
-//!          supplied. For example, to indicate that an option is to be 
-//!          interpreted by the TCP protocol, level should be set to the 
-//!          protocol number of TCP; 
-//!          The parameters optval and optlen are used to access optval - 
-//!          use for setsockopt(). For getsockopt() they identify a buffer
-//!          in which the value for the requested option(s) are to 
-//!          be returned. For getsockopt(), optlen is a value-result 
-//!          parameter, initially containing the size of the buffer 
-//!          pointed to by option_value, and modified on return to 
-//!          indicate the actual size of the value returned. If no option 
-//!          value is to be supplied or returned, option_value may be NULL.
-//!
-//!  @Note   On this version the following two socket options are enabled:
-//!                 The only protocol level supported in this version
-//!          is SOL_SOCKET (level).
-//!               1. SOCKOPT_RECV_TIMEOUT (optname)
-//!                  SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout 
-//!           in milliseconds.
-//!                In that case optval should be pointer to unsigned long.
-//!               2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on 
-//!           or off.
-//!                In that case optval should be SOCK_ON or SOCK_OFF (optval).
-//!
-//!  @sa getsockopt
-//
-//*****************************************************************************
+/**
+* set socket options
+* This function manipulate the options associated with a socket.
+* Options may exist at multiple protocol levels; they are always
+* present at the uppermost socket level.
+* When manipulating socket options the level at which the option 
+* resides and the name of the option must be specified.  
+* To manipulate options at the socket level, level is specified as 
+* SOL_SOCKET. To manipulate options at any other level the protocol 
+* number of the appropriate protocol controlling the option is 
+* supplied. For example, to indicate that an option is to be 
+* interpreted by the TCP protocol, level should be set to the 
+* protocol number of TCP; 
+* The parameters optval and optlen are used to access optval - 
+* use for setsockopt(). For getsockopt() they identify a buffer
+* in which the value for the requested option(s) are to 
+* be returned. For getsockopt(), optlen is a value-result 
+* parameter, initially containing the size of the buffer 
+* pointed to by option_value, and modified on return to 
+* indicate the actual size of the value returned. If no option 
+* value is to be supplied or returned, option_value may be NULL.
+* @param[in]   sd          socket handle
+* @param[in]   level       defines the protocol level for this option
+* @param[in]   optname     defines the option name to Interrogate
+* @param[in]   optval      specifies a value for the option
+* @param[in]   optlen      specifies the length of the option value
+* @return      On success, zero is returned. On error, -1 is returned
+*
+* @Note   On this version the following two socket options are enabled:
+*         The only protocol level supported in this version is SOL_SOCKET (level).
+*              1. SOCKOPT_RECV_TIMEOUT (optname)
+*                 SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout in milliseconds.
+*                 In that case optval should be pointer to unsigned long.
+*              2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on or off.
+*                 In that case optval should be SOCK_ON or SOCK_OFF (optval).
+* @sa getsockopt
+*/
 #ifndef CC3000_TINY_DRIVER 
-extern int setsockopt(long sd, long level, long optname, const void *optval,
-                      socklen_t optlen);
+extern int setsockopt(long sd, long level, long optname, const void *optval, socklen_t optlen);
 #endif
-//*****************************************************************************
-//
-//! getsockopt
-//!
-//!  @param[in]   sd          socket handle
-//!  @param[in]   level       defines the protocol level for this option
-//!  @param[in]   optname     defines the option name to Interrogate
-//!  @param[out]   optval      specifies a value for the option
-//!  @param[out]   optlen      specifies the length of the option value
-//!  @return      On success, zero is returned. On error, -1 is returned
-//!
-//!  @brief  set socket options
-//!          This function manipulate the options associated with a socket.
-//!          Options may exist at multiple protocol levels; they are always
-//!          present at the uppermost socket level.
-//!          When manipulating socket options the level at which the option 
-//!          resides and the name of the option must be specified.  
-//!          To manipulate options at the socket level, level is specified as 
-//!          SOL_SOCKET. To manipulate options at any other level the protocol 
-//!          number of the appropriate protocol controlling the option is 
-//!          supplied. For example, to indicate that an option is to be 
-//!          interpreted by the TCP protocol, level should be set to the 
-//!          protocol number of TCP; 
-//!          The parameters optval and optlen are used to access optval - 
-//!          use for setsockopt(). For getsockopt() they identify a buffer
-//!          in which the value for the requested option(s) are to 
-//!          be returned. For getsockopt(), optlen is a value-result 
-//!          parameter, initially containing the size of the buffer 
-//!          pointed to by option_value, and modified on return to 
-//!          indicate the actual size of the value returned. If no option 
-//!          value is to be supplied or returned, option_value may be NULL.
-//!
-//!  @Note   On this version the following two socket options are enabled:
-//!                 The only protocol level supported in this version
-//!          is SOL_SOCKET (level).
-//!               1. SOCKOPT_RECV_TIMEOUT (optname)
-//!                  SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout 
-//!           in milliseconds.
-//!                In that case optval should be pointer to unsigned long.
-//!               2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on 
-//!           or off.
-//!                In that case optval should be SOCK_ON or SOCK_OFF (optval).
-//!
-//!  @sa setsockopt
-//
-//*****************************************************************************
-extern int getsockopt(long sd, long level, long optname, void *optval,
-                      socklen_t *optlen);
 
-//*****************************************************************************
-//
-//!  recv
-//!
-//!  @param[in]  sd     socket handle
-//!  @param[out] buf    Points to the buffer where the message should be stored
-//!  @param[in]  len    Specifies the length in bytes of the buffer pointed to 
-//!                     by the buffer argument.
-//!  @param[in] flags   Specifies the type of message reception. 
-//!                     On this version, this parameter is not supported.
-//!
-//!  @return         Return the number of bytes received, or -1 if an error
-//!                  occurred
-//!
-//!  @brief          function receives a message from a connection-mode socket
-//!
-//!  @sa recvfrom
-//!
-//!  @Note On this version, only blocking mode is supported.
-//
-//*****************************************************************************
+/**
+* get socket options
+* This function manipulate the options associated with a socket.
+* Options may exist at multiple protocol levels; they are always
+* present at the uppermost socket level.
+* When manipulating socket options the level at which the option 
+* resides and the name of the option must be specified.  
+* To manipulate options at the socket level, level is specified as 
+* SOL_SOCKET. To manipulate options at any other level the protocol 
+* number of the appropriate protocol controlling the option is 
+* supplied. For example, to indicate that an option is to be 
+* interpreted by the TCP protocol, level should be set to the 
+* protocol number of TCP; 
+* The parameters optval and optlen are used to access optval - 
+* use for setsockopt(). For getsockopt() they identify a buffer
+* in which the value for the requested option(s) are to 
+* be returned. For getsockopt(), optlen is a value-result 
+* parameter, initially containing the size of the buffer 
+* pointed to by option_value, and modified on return to 
+* indicate the actual size of the value returned. If no option 
+* value is to be supplied or returned, option_value may be NULL.
+* @param[in]   sd          socket handle
+* @param[in]   level       defines the protocol level for this option
+* @param[in]   optname     defines the option name to Interrogate
+* @param[out]  optval      specifies a value for the option
+* @param[out]  optlen      specifies the length of the option value
+* @return      On success, zero is returned. On error, -1 is returned
+*
+* @Note   On this version the following two socket options are enabled:
+*         The only protocol level supported in this version is SOL_SOCKET (level).
+*              1. SOCKOPT_RECV_TIMEOUT (optname)
+*                 SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout in milliseconds.
+*                 In that case optval should be pointer to unsigned long.
+*              2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on or off.
+*                 In that case optval should be SOCK_ON or SOCK_OFF (optval).
+* @sa setsockopt
+*/
+extern int getsockopt(long sd, long level, long optname, void *optval, socklen_t *optlen);
+
+/**
+* Read data from socket (simple_link_recv)
+* Return the length of the message on successful completion.
+* If a message is too long to fit in the supplied buffer, excess bytes may
+* be discarded depending on the type of socket the message is received from.
+* @param sd       socket handle
+* @param buf      read buffer
+* @param len      buffer length
+* @param flags    indicates blocking or non-blocking operation
+* @param from     pointer to an address structure indicating source address
+* @param fromlen  source address structure size
+* @return         Return the number of bytes received, or -1 if an error occurred
+*/
+int simple_link_recv(long sd, void *buf, long len, long flags, sockaddr *from, socklen_t *fromlen, long opcode);
+
+/**
+* Receive a message from a connection-mode socket
+* @param[in]  sd     socket handle
+* @param[out] buf    Points to the buffer where the message should be stored
+* @param[in]  len    Specifies the length in bytes of the buffer pointed to 
+*                    by the buffer argument.
+* @param[in] flags   Specifies the type of message reception. 
+*                    On this version, this parameter is not supported.
+* @return         Return the number of bytes received, or -1 if an error occurred
+* @sa recvfrom
+* @Note On this version, only blocking mode is supported.
+*/
 extern int recv(long sd, void *buf, long len, long flags);
 
-//*****************************************************************************
-//
-//!  recvfrom
-//!
-//!  @param[in]  sd     socket handle
-//!  @param[out] buf    Points to the buffer where the message should be stored
-//!  @param[in]  len    Specifies the length in bytes of the buffer pointed to 
-//!                     by the buffer argument.
-//!  @param[in] flags   Specifies the type of message reception. 
-//!                     On this version, this parameter is not supported.
-//!  @param[in] from   pointer to an address structure indicating the source
-//!                    address: sockaddr. On this version only AF_INET is
-//!                    supported.
-//!  @param[in] fromlen   source address structure size
-//!
-//!  @return         Return the number of bytes received, or -1 if an error
-//!                  occurred
-//!
-//!  @brief         read data from socket
-//!                 function receives a message from a connection-mode or
-//!                 connectionless-mode socket. Note that raw sockets are not
-//!                 supported.
-//!
-//!  @sa recv
-//!
-//!  @Note On this version, only blocking mode is supported.
-//
-//*****************************************************************************
-extern int recvfrom(long sd, void *buf, long len, long flags, sockaddr *from, 
-                    socklen_t *fromlen);
+/**
+* read data from socket (recvfrom)
+* Receives a message from a connection-mode or connectionless-mode socket.
+* Note that raw sockets are not supported.
+* @param[in]  sd       socket handle
+* @param[out] buf      Points to the buffer where the message should be stored
+* @param[in]  len      Specifies the length in bytes of the buffer pointed to 
+*                      by the buffer argument.
+* @param[in] flags     Specifies the type of message reception. 
+*                      On this version, this parameter is not supported.
+* @param[in] from      pointer to an address structure indicating the source
+*                      address: sockaddr. On this version only AF_INET is
+*                      supported.
+* @param[in] fromlen   source address structure size
+* @return              Return the number of bytes received, or -1 if an error occurred
+* @sa recv
+* @Note On this version, only blocking mode is supported.
+*/
+extern int recvfrom(long sd, void *buf, long len, long flags, sockaddr *from, socklen_t *fromlen);
 
-//*****************************************************************************
-//
-//!  send
-//!
-//!  @param sd       socket handle
-//!  @param buf      Points to a buffer containing the message to be sent
-//!  @param len      message size in bytes
-//!  @param flags    On this version, this parameter is not supported
-//!
-//!  @return         Return the number of bytes transmitted, or -1 if an
-//!                  error occurred
-//!
-//!  @brief          Write data to TCP socket
-//!                  This function is used to transmit a message to another 
-//!                  socket.
-//!
-//!  @Note           On this version, only blocking mode is supported.
-//!
-//!  @sa             sendto
-//
-//*****************************************************************************
+/**
+* Transmit a message to another socket (simple_link_send)
+* @param sd       socket handle
+* @param buf      write buffer
+* @param len      buffer length
+* @param flags    On this version, this parameter is not supported
+* @param to       pointer to an address structure indicating destination address
+* @param tolen    destination address structure size
+* @return         Return the number of bytes transmitted, or -1 if an error
+*                 occurred, or -2 in case there are no free buffers available
+*                 (only when SEND_NON_BLOCKING is enabled)
+*/
+int simple_link_send(long sd, const void *buf, long len, long flags, const sockaddr *to, long tolen, long opcode);
 
+/**
+* Transmit a message to another socket (send).
+* @param sd       socket handle
+* @param buf      Points to a buffer containing the message to be sent
+* @param len      message size in bytes
+* @param flags    On this version, this parameter is not supported
+* @return         Return the number of bytes transmitted, or -1 if an
+*                 error occurred
+* @Note           On this version, only blocking mode is supported.
+* @sa             sendto
+*/
 extern int send(long sd, const void *buf, long len, long flags);
 
-//*****************************************************************************
-//
-//!  sendto
-//!
-//!  @param sd       socket handle
-//!  @param buf      Points to a buffer containing the message to be sent
-//!  @param len      message size in bytes
-//!  @param flags    On this version, this parameter is not supported
-//!  @param to       pointer to an address structure indicating the destination
-//!                  address: sockaddr. On this version only AF_INET is
-//!                  supported.
-//!  @param tolen    destination address structure size
-//!
-//!  @return         Return the number of bytes transmitted, or -1 if an
-//!                  error occurred
-//!
-//!  @brief          Write data to TCP socket
-//!                  This function is used to transmit a message to another 
-//!                  socket.
-//!
-//!  @Note           On this version, only blocking mode is supported.
-//!
-//!  @sa             send
-//
-//*****************************************************************************
+/**
+* Transmit a message to another socket (sendto).
+* @param sd       socket handle
+* @param buf      Points to a buffer containing the message to be sent
+* @param len      message size in bytes
+* @param flags    On this version, this parameter is not supported
+* @param to       pointer to an address structure indicating the destination
+*                 address: sockaddr. On this version only AF_INET is
+*                 supported.
+* @param tolen    destination address structure size
+* @return         Return the number of bytes transmitted, or -1 if an error occurred
+* @Note           On this version, only blocking mode is supported.
+* @sa             send
+*/
+extern int sendto(long sd, const void *buf, long len, long flags, const sockaddr *to, socklen_t tolen);
 
-extern int sendto(long sd, const void *buf, long len, long flags, 
-                  const sockaddr *to, socklen_t tolen);
-
-//*****************************************************************************
-//
-//!  mdnsAdvertiser
-//!
-//!  @param[in] mdnsEnabled         flag to enable/disable the mDNS feature
-//!  @param[in] deviceServiceName   Service name as part of the published
-//!                                 canonical domain name
-//!  @param[in] deviceServiceNameLength   Length of the service name
-//!  
-//!
-//!  @return   On success, zero is returned, return SOC_ERROR if socket was not 
-//!            opened successfully, or if an error occurred.
-//!
-//!  @brief    Set CC3000 in mDNS advertiser mode in order to advertise itself.
-//
-//*****************************************************************************
+/**
+* Set CC3000 in mDNS advertiser mode in order to advertise itself.
+* @param[in] mdnsEnabled         flag to enable/disable the mDNS feature
+* @param[in] deviceServiceName   Service name as part of the published
+*                                canonical domain name
+* @param[in] deviceServiceNameLength   Length of the service name
+* @return   On success, zero is returned, return SOC_ERROR if socket was not 
+*           opened successfully, or if an error occurred.
+*/
 extern int mdnsAdvertiser(unsigned short mdnsEnabled, char * deviceServiceName, unsigned short deviceServiceNameLength);
 
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
 
-
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
 #ifdef  __cplusplus
 }
 #endif // __cplusplus
--- a/wlan.cpp	Sat Jul 13 13:12:46 2013 +0000
+++ b/wlan.cpp	Mon Jul 15 14:19:46 2013 +0000
@@ -33,77 +33,17 @@
 *
 *****************************************************************************/
 
-//*****************************************************************************
-//
-//! \addtogroup wlan_api
-//! @{
-//
-//*****************************************************************************
 #include "wlan.h"
 
 extern void WriteWlanPin( unsigned char val );
 volatile sSimplLinkInformation tSLInformation;
 
-#define SMART_CONFIG_PROFILE_SIZE        67        // 67 = 32 (max ssid) + 32 (max key) + 1 (SSID length) + 1 (security type) + 1 (key length)
-
 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
 unsigned char key[AES128_KEY_SIZE];    
 unsigned char profileArray[SMART_CONFIG_PROFILE_SIZE];
 #endif //CC3000_UNENCRYPTED_SMART_CONFIG
 
-/* patches type */
-#define PATCHES_HOST_TYPE_WLAN_DRIVER   0x01
-#define PATCHES_HOST_TYPE_WLAN_FW       0x02
-#define PATCHES_HOST_TYPE_BOOTLOADER    0x03
 
-#define SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE    (16)
-#define SL_SIMPLE_CONFIG_PREFIX_LENGTH           (3)
-#define ETH_ALEN                                 (6)
-#define MAXIMAL_SSID_LENGTH                      (32)
-
-#define SL_PATCHES_REQUEST_DEFAULT               (0)
-#define SL_PATCHES_REQUEST_FORCE_HOST            (1)
-#define SL_PATCHES_REQUEST_FORCE_NONE            (2)
-
-
-#define      WLAN_SEC_UNSEC  (0)
-#define      WLAN_SEC_WEP    (1)
-#define      WLAN_SEC_WPA    (2)
-#define      WLAN_SEC_WPA2   (3)
-
-
-#define WLAN_SL_INIT_START_PARAMS_LEN           (1)
-#define WLAN_PATCH_PARAMS_LENGTH                (8)
-#define WLAN_SET_CONNECTION_POLICY_PARAMS_LEN   (12)
-#define WLAN_DEL_PROFILE_PARAMS_LEN             (4)
-#define WLAN_SET_MASK_PARAMS_LEN                (4)
-#define WLAN_SET_SCAN_PARAMS_LEN                (100)
-#define WLAN_GET_SCAN_RESULTS_PARAMS_LEN        (4)
-#define WLAN_ADD_PROFILE_NOSEC_PARAM_LEN        (24)            
-#define WLAN_ADD_PROFILE_WEP_PARAM_LEN          (36)
-#define WLAN_ADD_PROFILE_WPA_PARAM_LEN          (44)
-#define WLAN_CONNECT_PARAM_LEN                  (29)
-#define WLAN_SMART_CONFIG_START_PARAMS_LEN      (4)
-
-
-
-
-//*****************************************************************************
-//
-//!  SimpleLink_Init_Start
-//!
-//!  @param  usPatchesAvailableAtHost  flag to indicate if patches available
-//!                                    from host or from EEPROM. Due to the 
-//!                                    fact the patches are burn to the EEPROM
-//!                                    using the patch programmer utility, the 
-//!                                    patches will be available from the EEPROM
-//!                                    and not from the host.
-//!
-//!  @return   none
-//!
-//!  @brief    Send HCI_CMND_SIMPLE_LINK_START to CC3000
-//
-//*****************************************************************************
 static void SimpleLink_Init_Start(unsigned short usPatchesAvailableAtHost)
 {
     unsigned char *ptr;
@@ -116,59 +56,10 @@
     
     // IRQ Line asserted - send HCI_CMND_SIMPLE_LINK_START to CC3000
     hci_command_send(HCI_CMND_SIMPLE_LINK_START, ptr, WLAN_SL_INIT_START_PARAMS_LEN);
-//printf("HCS-E\n");
     SimpleLinkWaitEvent(HCI_CMND_SIMPLE_LINK_START, 0);
-//printf("SLWE-E\n");
 }
 
 
-
-//*****************************************************************************
-//
-//!  wlan_init
-//!
-//!  @param  sWlanCB   Asynchronous events callback.  
-//!                    0 no event call back.
-//!                  -call back parameters:
-//!                   1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event,
-//!                     HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event,
-//!                     HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done,
-//!                     HCI_EVNT_WLAN_UNSOL_DHCP dhcp report, 
-//!                     HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR 
-//!                     HCI_EVNT_WLAN_KEEPALIVE keepalive.
-//!                   2) data: pointer to extra data that received by the event
-//!                     (NULL no data).
-//!                   3) length: data length.
-//!                  -Events with extra data:
-//!                     HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask, 
-//!                     4 bytes default gateway, 4 bytes DHCP server and 4 bytes
-//!                     for DNS server.
-//!                     HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent, 
-//!                     4 bytes Packets received, 4 bytes Min round time, 
-//!                     4 bytes Max round time and 4 bytes for Avg round time.
-//!
-//!  @param    sFWPatches  0 no patch or pointer to FW patches 
-//!  @param    sDriverPatches  0 no patch or pointer to driver patches
-//!  @param    sBootLoaderPatches  0 no patch or pointer to bootloader patches
-//!  @param    sReadWlanInterruptPin    init callback. the callback read wlan 
-//!            interrupt status.
-//!  @param    sWlanInterruptEnable   init callback. the callback enable wlan 
-//!            interrupt.
-//!  @param    sWlanInterruptDisable   init callback. the callback disable wlan
-//!            interrupt.
-//!  @param    sWriteWlanPin      init callback. the callback write value 
-//!            to device pin.  
-//!
-//!  @return   none
-//!
-//!  @sa       wlan_set_event_mask , wlan_start , wlan_stop 
-//!
-//!  @brief    Initialize wlan driver
-//!
-//!  @warning This function must be called before ANY other wlan driver function
-//
-//*****************************************************************************
-
 void wlan_init(tWlanCB               sWlanCB,
                tFWPatches            sFWPatches,
                tDriverPatches        sDriverPatches,
@@ -196,20 +87,7 @@
     tSLInformation.InformHostOnTxComplete = 1;
 }
 
-//*****************************************************************************
-//
-//!  SpiReceiveHandler
-//!
-//!  @param         pvBuffer - pointer to the received data buffer
-//!                      The function triggers Received event/data processing
-//!                 
-//!  @param         Pointer to the received data
-//!  @return        none
-//!
-//!  @brief         The function triggers Received event/data processing. It is 
-//!                       called from the SPI library to receive the data
-//
-//*****************************************************************************
+
 void SpiReceiveHandler(void *pvBuffer)
 {    
     tSLInformation.usEventOrDataReceived = 1;
@@ -218,32 +96,6 @@
     hci_unsolicited_event_handler();
 }
 
-//*****************************************************************************
-//
-//!  wlan_start
-//!
-//!  @param   usPatchesAvailableAtHost -  flag to indicate if patches available
-//!                                    from host or from EEPROM. Due to the 
-//!                                    fact the patches are burn to the EEPROM
-//!                                    using the patch programmer utility, the 
-//!                                    patches will be available from the EEPROM
-//!                                    and not from the host.
-//!
-//!  @return        none
-//!
-//!  @brief        Start WLAN device. This function asserts the enable pin of 
-//!                the device (WLAN_EN), starting the HW initialization process.
-//!                The function blocked until device Initialization is completed.
-//!                Function also configure patches (FW, driver or bootloader) 
-//!                and calls appropriate device callbacks.
-//!
-//!  @Note          Prior calling the function wlan_init shall be called.
-//!  @Warning       This function must be called after wlan_init and before any 
-//!                 other wlan API
-//!  @sa            wlan_init , wlan_stop
-//!
-//
-//*****************************************************************************
 
 void wlan_start(unsigned short usPatchesAvailableAtHost)
 {
@@ -276,17 +128,6 @@
         // wait till the IRQ line goes low
         while(tSLInformation.ReadWlanInterruptPin() != 0)
         {
-            // Code inserted to avoid a wait forever. This only happens when wlan_start(0) is called.
-            // We need to reassert the enable pin to get an IRQ acknowledge from the CC3000.
-            // The real cause is unknown.
-            // A test indicates the enable pin only needs to be reasserted once.
-            if(usPatchesAvailableAtHost == 0)
-            {
-                tSLInformation.WriteWlanPin( WLAN_DISABLE );
-                wait_ms(50);
-                tSLInformation.WriteWlanPin( WLAN_ENABLE );
-                wait(1.5);
-            }
         }
     }
     else
@@ -303,26 +144,10 @@
     
     // Read Buffer's size and finish
     hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0);
-//printf("HCS-E %02X\n",IRQ_cnt);
     SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0);
-//printf("SLWE-E\n");
 }
 
 
-//*****************************************************************************
-//
-//!  wlan_stop
-//!
-//!  @param         none
-//!
-//!  @return        none
-//!
-//!  @brief         Stop WLAN device by putting it into reset state.
-//!
-//!  @sa            wlan_stop
-//
-//*****************************************************************************
-
 void wlan_stop(void)
 {
     // ASIC 1273 chip disable
@@ -343,36 +168,6 @@
 }
 
 
-//*****************************************************************************
-//
-//!  wlan_connect
-//!
-//!  @param    sec_type   security options:
-//!               WLAN_SEC_UNSEC, 
-//!               WLAN_SEC_WEP (ASCII support only),
-//!               WLAN_SEC_WPA or WLAN_SEC_WPA2
-//!  @param    ssid       up to 32 bytes and is ASCII SSID of the AP
-//!  @param    ssid_len   length of the SSID
-//!  @param    bssid      6 bytes specified the AP bssid
-//!  @param    key        up to 16 bytes specified the AP security key
-//!  @param    key_len    key length 
-//!
-//!  @return     On success, zero is returned. On error, negative is returned. 
-//!              Note that even though a zero is returned on success to trigger
-//!              connection operation, it does not mean that CCC3000 is already
-//!              connected. An asynchronous "Connected" event is generated when 
-//!              actual association process finishes and CC3000 is connected to
-//!              the AP. If DHCP is set, An asynchronous "DHCP" event is 
-//!              generated when DHCP process is finish.
-//!              
-//!
-//!  @brief      Connect to AP
-//!  @warning    Please Note that when connection to AP configured with security
-//!              type WEP, please confirm that the key is set as ASCII and not
-//!              as HEX.
-//!  @sa         wlan_disconnect
-//
-//*****************************************************************************
 #ifndef CC3000_TINY_DRIVER
 long wlan_connect(unsigned long ulSecType,
                   char *ssid,
@@ -459,17 +254,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  wlan_disconnect
-//!
-//!  @return    0 disconnected done, other CC3000 already disconnected            
-//!
-//!  @brief      Disconnect connection from AP. 
-//!
-//!  @sa         wlan_connect
-//
-//*****************************************************************************
 
 long wlan_disconnect()
 {
@@ -488,37 +272,6 @@
     return(ret);
 }
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_set_connection_policy
-//!
-//!  @param    should_connect_to_open_ap  enable(1), disable(0) connect to any 
-//!            available AP. This parameter corresponds to the configuration of 
-//!            item # 3 in the brief description.
-//!  @param    should_use_fast_connect enable(1), disable(0). if enabled, tries 
-//!            to connect to the last connected AP. This parameter corresponds 
-//!            to the configuration of item # 1 in the brief description.
-//!  @param    auto_start enable(1), disable(0) auto connect 
-//!            after reset and periodically reconnect if needed. This 
-//!              configuration configures option 2 in the above description.
-//!
-//!  @return     On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief      When auto is enabled, the device tries to connect according 
-//!              the following policy:
-//!              1) If fast connect is enabled and last connection is valid, 
-//!                 the device will try to connect to it without the scanning 
-//!                 procedure (fast). The last connection will be marked as
-//!                 invalid, due to adding/removing profile. 
-//!              2) If profile exists, the device will try to connect it 
-//!                 (Up to seven profiles).
-//!              3) If fast and profiles are not found, and open mode is
-//!                 enabled, the device will try to connect to any AP.
-//!              * Note that the policy settings are stored in the CC3000 NVMEM.
-//!
-//!  @sa         wlan_add_profile , wlan_ioctl_del_profile 
-//
-//*****************************************************************************
 
 long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, 
                                       unsigned long ulShouldUseFastConnect,
@@ -546,33 +299,6 @@
     return(ret);
 }
 
-//*****************************************************************************
-//
-//!  wlan_add_profile
-//!
-//!  @param    ulSecType  WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2
-//!  @param    ucSsid    ssid  SSID up to 32 bytes
-//!  @param    ulSsidLen ssid length
-//!  @param    ucBssid   bssid  6 bytes
-//!  @param    ulPriority ulPriority profile priority. Lowest priority:0.
-//!  @param    ulPairwiseCipher_Or_TxKeyLen  key length for WEP security
-//!  @param    ulGroupCipher_TxKeyIndex  key index
-//!  @param    ulKeyMgmt        KEY management 
-//!  @param    ucPf_OrKey       security key
-//!  @param    ulPassPhraseLen  security key length for WPA\WPA2
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief     When auto start is enabled, the device connects to
-//!             station from the profiles table. Up to 7 profiles are supported. 
-//!             If several profiles configured the device choose the highest 
-//!             priority profile, within each priority group, device will choose 
-//!             profile based on security policy, signal strength, etc 
-//!             parameters. All the profiles are stored in CC3000 NVMEM.
-//!
-//!  @sa        wlan_ioctl_del_profile 
-//
-//*****************************************************************************
 
 #ifndef CC3000_TINY_DRIVER
 long wlan_add_profile(unsigned long ulSecType, 
@@ -710,21 +436,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_del_profile
-//!
-//!  @param    index   number of profile to delete
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief     Delete WLAN profile 
-//!
-//!  @Note      In order to delete all stored profile, set index to 255.
-//!
-//!  @sa        wlan_add_profile 
-//
-//*****************************************************************************
 
 long wlan_ioctl_del_profile(unsigned long ulIndex)
 {
@@ -748,39 +459,6 @@
     return(ret);
 }
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_get_scan_results
-//!
-//!  @param[in]    scan_timeout   parameter not supported
-//!  @param[out]   ucResults  scan results (_wlan_full_scan_results_args_t)
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief    Gets entry from scan result table.
-//!            The scan results are returned one by one, and each entry 
-//!            represents a single AP found in the area. The following is a 
-//!            format of the scan result: 
-//!             - 4 Bytes: number of networks found
-//!          - 4 Bytes: The status of the scan: 0 - aged results,
-//!                     1 - results valid, 2 - no results
-//!          - 42 bytes: Result entry, where the bytes are arranged as  follows:
-//!              
-//!                          - 1 bit isValid - is result valid or not
-//!                         - 7 bits rssi - RSSI value;     
-//!                 - 2 bits: securityMode - security mode of the AP:
-//!                           0 - Open, 1 - WEP, 2 WPA, 3 WPA2
-//!                         - 6 bits: SSID name length
-//!                         - 2 bytes: the time at which the entry has entered into 
-//!                            scans result table
-//!                         - 32 bytes: SSID name
-//!                 - 6 bytes:    BSSID 
-//!
-//!  @Note      scan_timeout, is not supported on this version.
-//!
-//!  @sa        wlan_ioctl_set_scan_params 
-//
-//*****************************************************************************
 
 #ifndef CC3000_TINY_DRIVER
 long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout,
@@ -805,42 +483,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_set_scan_params
-//!
-//!  @param    uiEnable - start/stop application scan: 
-//!            1 = start scan with default interval value of 10 min. 
-//!            in order to set a different scan interval value apply the value 
-//!            in milliseconds. minimum 1 second. 0=stop). Wlan reset
-//!           (wlan_stop() wlan_start()) is needed when changing scan interval
-//!            value. Saved: No
-//!  @param   uiMinDwellTime   minimum dwell time value to be used for each 
-//!           channel, in milliseconds. Saved: yes
-//!           Recommended Value: 100 (Default: 20)
-//!  @param   uiMaxDwellTime    maximum dwell time value to be used for each
-//!           channel, in milliseconds. Saved: yes
-//!           Recommended Value: 100 (Default: 30)
-//!  @param   uiNumOfProbeRequests  max probe request between dwell time. 
-//!           Saved: yes. Recommended Value: 5 (Default:2)
-//!  @param   uiChannelMask  bitwise, up to 13 channels (0x1fff). 
-//!           Saved: yes. Default: 0x7ff
-//!  @param   uiRSSIThreshold   RSSI threshold. Saved: yes (Default: -80)
-//!  @param   uiSNRThreshold    NSR threshold. Saved: yes (Default: 0)
-//!  @param   uiDefaultTxPower  probe Tx power. Saved: yes (Default: 205)
-//!  @param   aiIntervalList    pointer to array with 16 entries (16 channels) 
-//!           each entry (unsigned long) holds timeout between periodic scan 
-//!           (connection scan) - in millisecond. Saved: yes. Default 2000ms.
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief    start and stop scan procedure. Set scan parameters. 
-//!
-//!  @Note     uiDefaultTxPower, is not supported on this version.
-//!
-//!  @sa        wlan_ioctl_get_scan_results 
-//
-//*****************************************************************************
 
 #ifndef CC3000_TINY_DRIVER
 long wlan_ioctl_set_scan_params(unsigned long uiEnable,
@@ -882,27 +524,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  wlan_set_event_mask
-//!
-//!  @param    mask   mask option:
-//!       HCI_EVNT_WLAN_UNSOL_CONNECT connect event
-//!       HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event
-//!       HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE  smart config done
-//!       HCI_EVNT_WLAN_UNSOL_INIT init done
-//!       HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report
-//!       HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report
-//!       HCI_EVNT_WLAN_KEEPALIVE keepalive
-//!       HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission
-//!         Saved: no.
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief    Mask event according to bit mask. In case that event is 
-//!            masked (1), the device will not send the masked event to host. 
-//
-//*****************************************************************************
 
 long wlan_set_event_mask(unsigned long ulMask)
 {
@@ -946,18 +567,6 @@
     return(ret);
 }
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_statusget
-//!
-//!  @param none 
-//!
-//!  @return    WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING, 
-//!             STATUS_CONNECTING or WLAN_STATUS_CONNECTED      
-//!
-//!  @brief    get wlan status: disconnected, scanning, connecting or connected
-//
-//*****************************************************************************
 
 #ifndef CC3000_TINY_DRIVER
 long wlan_ioctl_statusget(void)
@@ -977,26 +586,6 @@
 }
 #endif
 
-//*****************************************************************************
-//
-//!  wlan_smart_config_start
-//!
-//!  @param    algoEncryptedFlag indicates whether the information is encrypted
-//!
-//!  @return   On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief   Start to acquire device profile. The device acquire its own 
-//!           profile, if profile message is found. The acquired AP information
-//!           is stored in CC3000 EEPROM only in case AES128 encryption is used.
-//!           In case AES128 encryption is not used, a profile is created by 
-//!           CC3000 internally.
-//!
-//!  @Note    An asynchronous event - Smart Config Done will be generated as soon
-//!           as the process finishes successfully.
-//!
-//!  @sa      wlan_smart_config_set_prefix , wlan_smart_config_stop
-//
-//*****************************************************************************
 
 long wlan_smart_config_start(unsigned long algoEncryptedFlag)
 {
@@ -1020,19 +609,6 @@
     return(ret);    
 }
 
-//*****************************************************************************
-//
-//!  wlan_smart_config_stop
-//!
-//!  @param    algoEncryptedFlag indicates whether the information is encrypted
-//!
-//!  @return   On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief   Stop the acquire profile procedure 
-//!
-//!  @sa      wlan_smart_config_start , wlan_smart_config_set_prefix
-//
-//*****************************************************************************
 
 long wlan_smart_config_stop(void)
 {
@@ -1050,22 +626,6 @@
     return(ret);    
 }
 
-//*****************************************************************************
-//
-//!  wlan_smart_config_set_prefix
-//!
-//!  @param   newPrefix  3 bytes identify the SSID prefix for the Smart Config. 
-//!
-//!  @return   On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief   Configure station ssid prefix. The prefix is used internally 
-//!           in CC3000. It should always be TTT.
-//!
-//!  @Note    The prefix is stored in CC3000 NVMEM
-//!
-//!  @sa      wlan_smart_config_start , wlan_smart_config_stop
-//
-//*****************************************************************************
 
 long wlan_smart_config_set_prefix(char* cNewPrefix)
 {
@@ -1096,21 +656,6 @@
     return(ret);    
 }
 
-//*****************************************************************************
-//
-//!  wlan_smart_config_process
-//!
-//!  @param   none 
-//!
-//!  @return   On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief   process the acquired data and store it as a profile. The acquired 
-//!           AP information is stored in CC3000 EEPROM encrypted.
-//!           The encrypted data is decrypted and stored as a profile.
-//!           behavior is as defined by connection policy.
-//
-//*****************************************************************************
-
 
 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
 long wlan_smart_config_process()
@@ -1199,8 +744,8 @@
             break;
         }
         
-    case WLAN_SEC_WPA://WPA
-    case WLAN_SEC_WPA2://WPA2
+    case WLAN_SEC_WPA:  //WPA
+    case WLAN_SEC_WPA2: //WPA2
         {
             returnValue = wlan_add_profile(WLAN_SEC_WPA2,     // security type
                                            ssidPtr,
@@ -1220,12 +765,3 @@
     return returnValue;
 }
 #endif //CC3000_UNENCRYPTED_SMART_CONFIG        
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
-
-
--- a/wlan.h	Sat Jul 13 13:12:46 2013 +0000
+++ b/wlan.h	Mon Jul 15 14:19:46 2013 +0000
@@ -35,7 +35,6 @@
 #ifndef __WLAN_H__
 #define __WLAN_H__
 
-//#include "mbed.h"
 #include "GlobalAssigns.h"
 #include "cc3000_common.h"
 #include "hci.h"
@@ -48,73 +47,97 @@
 /** CC3000 Host driver - WLAN
 *
 */
-//*****************************************************************************
-//
-// If building with a C++ compiler, make all of the definitions in this header
-// have a C binding.
-//
-//*****************************************************************************
+
 #ifdef    __cplusplus
 extern "C" {
 #endif
 
+#define SMART_CONFIG_PROFILE_SIZE        67        // 67 = 32 (max ssid) + 32 (max key) + 1 (SSID length) + 1 (security type) + 1 (key length)
+
+/* patches type */
+#define PATCHES_HOST_TYPE_WLAN_DRIVER   0x01
+#define PATCHES_HOST_TYPE_WLAN_FW       0x02
+#define PATCHES_HOST_TYPE_BOOTLOADER    0x03
+
+#define SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE    (16)
+#define SL_SIMPLE_CONFIG_PREFIX_LENGTH           (3)
+#define ETH_ALEN                                 (6)
+#define MAXIMAL_SSID_LENGTH                      (32)
+
+#define SL_PATCHES_REQUEST_DEFAULT               (0)
+#define SL_PATCHES_REQUEST_FORCE_HOST            (1)
+#define SL_PATCHES_REQUEST_FORCE_NONE            (2)
+
+
+#define      WLAN_SEC_UNSEC  (0)
+#define      WLAN_SEC_WEP    (1)
+#define      WLAN_SEC_WPA    (2)
+#define      WLAN_SEC_WPA2   (3)
+
+
+#define WLAN_SL_INIT_START_PARAMS_LEN           (1)
+#define WLAN_PATCH_PARAMS_LENGTH                (8)
+#define WLAN_SET_CONNECTION_POLICY_PARAMS_LEN   (12)
+#define WLAN_DEL_PROFILE_PARAMS_LEN             (4)
+#define WLAN_SET_MASK_PARAMS_LEN                (4)
+#define WLAN_SET_SCAN_PARAMS_LEN                (100)
+#define WLAN_GET_SCAN_RESULTS_PARAMS_LEN        (4)
+#define WLAN_ADD_PROFILE_NOSEC_PARAM_LEN        (24)            
+#define WLAN_ADD_PROFILE_WEP_PARAM_LEN          (36)
+#define WLAN_ADD_PROFILE_WPA_PARAM_LEN          (44)
+#define WLAN_CONNECT_PARAM_LEN                  (29)
+#define WLAN_SMART_CONFIG_START_PARAMS_LEN      (4)
+
+
 #define      WLAN_SEC_UNSEC (0)
 #define      WLAN_SEC_WEP   (1)
 #define      WLAN_SEC_WPA   (2)
 #define      WLAN_SEC_WPA2  (3)
-//*****************************************************************************
-//
-//! \addtogroup wlan_api
-//! @{
-//
-//*****************************************************************************
 
+/**
+* Send HCI_CMND_SIMPLE_LINK_START to CC3000
+* @param  usPatchesAvailableAtHost  flag to indicate if patches available
+*                                   from host or from EEPROM. Due to the 
+*                                   fact the patches are burn to the EEPROM
+*                                   using the patch programmer utility, the 
+*                                   patches will be available from the EEPROM
+*                                   and not from the host.
+* @return   none
+*/
+static void SimpleLink_Init_Start(unsigned short usPatchesAvailableAtHost);
 
-//*****************************************************************************
-//
-//!  wlan_init
-//!
-//!  @param  sWlanCB   Asynchronous events callback.  
-//!                    0 no event call back.
-//!                  -call back parameters:
-//!                   1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event,
-//!                     HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event,
-//!                     HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done,
-//!                     HCI_EVNT_WLAN_UNSOL_DHCP dhcp report, 
-//!                     HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR 
-//!                     HCI_EVNT_WLAN_KEEPALIVE keepalive.
-//!                   2) data: pointer to extra data that received by the event
-//!                     (NULL no data).
-//!                   3) length: data length.
-//!                  -Events with extra data:
-//!                     HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask, 
-//!                     4 bytes default gateway, 4 bytes DHCP server and 4 bytes
-//!                     for DNS server.
-//!                     HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent, 
-//!                     4 bytes Packets received, 4 bytes Min round time, 
-//!                     4 bytes Max round time and 4 bytes for Avg round time.
-//!
-//!  @param    sFWPatches  0 no patch or pointer to FW patches 
-//!  @param    sDriverPatches  0 no patch or pointer to driver patches
-//!  @param    sBootLoaderPatches  0 no patch or pointer to bootloader patches
-//!  @param    sReadWlanInterruptPin    init callback. the callback read wlan 
-//!            interrupt status.
-//!  @param    sWlanInterruptEnable   init callback. the callback enable wlan 
-//!            interrupt.
-//!  @param    sWlanInterruptDisable   init callback. the callback disable wlan
-//!            interrupt.
-//!  @param    sWriteWlanPin      init callback. the callback write value 
-//!            to device pin.  
-//!
-//!  @return   none
-//!
-//!  @sa       wlan_set_event_mask , wlan_start , wlan_stop 
-//!
-//!  @brief    Initialize wlan driver
-//!
-//!  @warning This function must be called before ANY other wlan driver function
-//
-//*****************************************************************************
+/**
+* Initialize wlan driver
+* @param  sWlanCB   Asynchronous events callback.  
+*                   0 no event call back.
+*                 -call back parameters:
+*                  1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event,
+*                    HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event,
+*                    HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done,
+*                    HCI_EVNT_WLAN_UNSOL_DHCP dhcp report, 
+*                    HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR 
+*                    HCI_EVNT_WLAN_KEEPALIVE keepalive.
+*                  2) data: pointer to extra data that received by the event
+*                    (NULL no data).
+*                  3) length: data length.
+*                 -Events with extra data:
+*                    HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask, 
+*                    4 bytes default gateway, 4 bytes DHCP server and 4 bytes
+*                    for DNS server.
+*                    HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent, 
+*                    4 bytes Packets received, 4 bytes Min round time, 
+*                    4 bytes Max round time and 4 bytes for Avg round time.
+* @param    sFWPatches              0 no patch or pointer to FW patches 
+* @param    sDriverPatches          0 no patch or pointer to driver patches
+* @param    sBootLoaderPatches      0 no patch or pointer to bootloader patches
+* @param    sReadWlanInterruptPin   init callback. the callback read wlan interrupt status.
+* @param    sWlanInterruptEnable    init callback. the callback enable wlan interrupt.
+* @param    sWlanInterruptDisable   init callback. the callback disable wlan interrupt.
+* @param    sWriteWlanPin           init callback. the callback write value to device pin.  
+* @return   none
+* @sa       wlan_set_event_mask , wlan_start , wlan_stop 
+* @warning  This function must be called before ANY other wlan driver function
+*/
 extern void wlan_init(tWlanCB               sWlanCB,
                       tFWPatches            sFWPatches,
                       tDriverPatches        sDriverPatches,
@@ -124,81 +147,66 @@
                       tWlanInterruptDisable sWlanInterruptDisable,
                       tWriteWlanPin         sWriteWlanPin);
 
+/**
+* Trigger Received event/data processing - called from the SPI library to receive the data
+* @param         pvBuffer - pointer to the received data buffer
+*                The function triggers Received event/data processing
+* @param         Pointer to the received data
+* @return        none
+*/
+void SpiReceiveHandler(void *pvBuffer);
 
 
-//*****************************************************************************
-//
-//!  wlan_start
-//!
-//!  @param   usPatchesAvailableAtHost -  flag to indicate if patches available
-//!                                    from host or from EEPROM. Due to the 
-//!                                    fact the patches are burn to the EEPROM
-//!                                    using the patch programmer utility, the 
-//!                                    patches will be available from the EEPROM
-//!                                    and not from the host.
-//!
-//!  @return        none
-//!
-//!  @brief        Start WLAN device. This function asserts the enable pin of 
-//!                the device (WLAN_EN), starting the HW initialization process.
-//!                The function blocked until device Initialization is completed.
-//!                Function also configure patches (FW, driver or bootloader) 
-//!                and calls appropriate device callbacks.
-//!
-//!  @Note          Prior calling the function wlan_init shall be called.
-//!  @Warning       This function must be called after wlan_init and before any 
-//!                 other wlan API
-//!  @sa            wlan_init , wlan_stop
-//!
-//
-//*****************************************************************************
+/**
+* Start WLAN device. This function asserts the enable pin of 
+* the device (WLAN_EN), starting the HW initialization process.
+* The function blocked until device Initialization is completed.
+* Function also configure patches (FW, driver or bootloader) 
+* and calls appropriate device callbacks.
+* @param   usPatchesAvailableAtHost - flag to indicate if patches available
+*                                     from host or from EEPROM. Due to the 
+*                                     fact the patches are burn to the EEPROM
+*                                     using the patch programmer utility, the 
+*                                     patches will be available from the EEPROM
+*                                     and not from the host.
+* @return        none
+* @Note          Prior calling the function wlan_init shall be called.
+* @Warning       This function must be called after wlan_init and before any 
+*                other wlan API
+* @sa            wlan_init , wlan_stop
+*/
 extern void wlan_start(unsigned short usPatchesAvailableAtHost);
 
-//*****************************************************************************
-//
-//!  wlan_stop
-//!
-//!  @param         none
-//!
-//!  @return        none
-//!
-//!  @brief         Stop WLAN device by putting it into reset state.
-//!
-//!  @sa            wlan_start
-//
-//*****************************************************************************
+/**
+* Stop WLAN device by putting it into reset state.
+* @param         none
+* @return        none
+* @sa            wlan_start
+*/
 extern void wlan_stop(void);
 
-//*****************************************************************************
-//
-//!  wlan_connect
-//!
-//!  @param    sec_type   security options:
-//!               WLAN_SEC_UNSEC, 
-//!               WLAN_SEC_WEP (ASCII support only),
-//!               WLAN_SEC_WPA or WLAN_SEC_WPA2
-//!  @param    ssid       up to 32 bytes and is ASCII SSID of the AP
-//!  @param    ssid_len   length of the SSID
-//!  @param    bssid      6 bytes specified the AP bssid
-//!  @param    key        up to 16 bytes specified the AP security key
-//!  @param    key_len    key length 
-//!
-//!  @return     On success, zero is returned. On error, negative is returned. 
-//!              Note that even though a zero is returned on success to trigger
-//!              connection operation, it does not mean that CCC3000 is already
-//!              connected. An asynchronous "Connected" event is generated when 
-//!              actual association process finishes and CC3000 is connected to
-//!              the AP. If DHCP is set, An asynchronous "DHCP" event is 
-//!              generated when DHCP process is finish.
-//!              
-//!
-//!  @brief      Connect to AP
-//!  @warning    Please Note that when connection to AP configured with security
-//!              type WEP, please confirm that the key is set as ASCII and not
-//!              as HEX.
-//!  @sa         wlan_disconnect
-//
-//*****************************************************************************
+/**
+* Connect to AP
+* @param    sec_type   security options:
+*              WLAN_SEC_UNSEC, 
+*              WLAN_SEC_WEP (ASCII support only),
+*              WLAN_SEC_WPA or WLAN_SEC_WPA2
+* @param    ssid       up to 32 bytes and is ASCII SSID of the AP
+* @param    ssid_len   length of the SSID
+* @param    bssid      6 bytes specified the AP bssid
+* @param    key        up to 16 bytes specified the AP security key
+* @param    key_len    key length 
+* @return   On success, zero is returned. On error, negative is returned. 
+*           Note that even though a zero is returned on success to trigger
+*           connection operation, it does not mean that CCC3000 is already
+*           connected. An asynchronous "Connected" event is generated when 
+*           actual association process finishes and CC3000 is connected to
+*           the AP. If DHCP is set, An asynchronous "DHCP" event is 
+*           generated when DHCP process is finish.
+* @warning  Please Note that when connection to AP configured with security
+*           type WEP, please confirm that the key is set as ASCII and not as HEX.
+* @sa       wlan_disconnect
+*/
 #ifndef CC3000_TINY_DRIVER
 extern long wlan_connect(unsigned long ulSecType,
                          char *ssid,
@@ -211,48 +219,35 @@
 
 #endif
 
-//*****************************************************************************
-//
-//!  wlan_disconnect
-//!
-//!  @return    0 disconnected done, other CC3000 already disconnected            
-//!
-//!  @brief      Disconnect connection from AP. 
-//!
-//!  @sa         wlan_connect
-//
-//*****************************************************************************
-
+/**
+* Disconnect connection from AP. 
+* @return    0 disconnected done, other CC3000 already disconnected            
+* @sa        wlan_connect
+*/
 extern long wlan_disconnect(void);
 
-//*****************************************************************************
-//
-//!  wlan_add_profile
-//!
-//!  @param    ulSecType  WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2
-//!  @param    ucSsid    ssid  SSID up to 32 bytes
-//!  @param    ulSsidLen ssid length
-//!  @param    ucBssid   bssid  6 bytes
-//!  @param    ulPriority ulPriority profile priority. Lowest priority:0.
-//!  @param    ulPairwiseCipher_Or_TxKeyLen  key length for WEP security
-//!  @param    ulGroupCipher_TxKeyIndex  key index
-//!  @param    ulKeyMgmt        KEY management 
-//!  @param    ucPf_OrKey       security key
-//!  @param    ulPassPhraseLen  security key length for WPA\WPA2
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief     When auto start is enabled, the device connects to
-//!             station from the profiles table. Up to 7 profiles are supported. 
-//!             If several profiles configured the device choose the highest 
-//!             priority profile, within each priority group, device will choose 
-//!             profile based on security policy, signal strength, etc 
-//!             parameters. All the profiles are stored in CC3000 NVMEM.
-//!
-//!  @sa        wlan_ioctl_del_profile 
-//
-//*****************************************************************************
-
+/**
+* Add profile
+* When auto start is enabled, the device connects to
+* station from the profiles table. Up to 7 profiles are supported. 
+* If several profiles configured the device choose the highest 
+* priority profile, within each priority group, device will choose 
+* profile based on security policy, signal strength, etc 
+* parameters. All the profiles are stored in CC3000 NVMEM.
+*
+* @param    ulSecType  WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2
+* @param    ucSsid    ssid  SSID up to 32 bytes
+* @param    ulSsidLen ssid length
+* @param    ucBssid   bssid  6 bytes
+* @param    ulPriority ulPriority profile priority. Lowest priority:0.
+* @param    ulPairwiseCipher_Or_TxKeyLen  key length for WEP security
+* @param    ulGroupCipher_TxKeyIndex  key index
+* @param    ulKeyMgmt        KEY management 
+* @param    ucPf_OrKey       security key
+* @param    ulPassPhraseLen  security key length for WPA\WPA2
+* @return    On success, zero is returned. On error, -1 is returned        
+* @sa        wlan_ioctl_del_profile 
+*/
 extern long wlan_add_profile(unsigned long ulSecType,
                              unsigned char* ucSsid,
                              unsigned long ulSsidLen, 
@@ -264,172 +259,133 @@
                              unsigned char* ucPf_OrKey,
                              unsigned long ulPassPhraseLen);
 
-
-
-//*****************************************************************************
-//
-//!  wlan_ioctl_del_profile
-//!
-//!  @param    index   number of profile to delete
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief     Delete WLAN profile 
-//!
-//!  @Note      In order to delete all stored profile, set index to 255.
-//!
-//!  @sa        wlan_add_profile 
-//
-//*****************************************************************************
+/**
+* Delete WLAN profile 
+* @param    index   number of profile to delete
+* @return   On success, zero is returned. On error, -1 is returned        
+* @Note     In order to delete all stored profile, set index to 255.
+* @sa       wlan_add_profile 
+*/
 extern long wlan_ioctl_del_profile(unsigned long ulIndex);
 
-//*****************************************************************************
-//
-//!  wlan_set_event_mask
-//!
-//!  @param    mask   mask option:
-//!       HCI_EVNT_WLAN_UNSOL_CONNECT connect event
-//!       HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event
-//!       HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE  smart config done
-//!       HCI_EVNT_WLAN_UNSOL_INIT init done
-//!       HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report
-//!       HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report
-//!       HCI_EVNT_WLAN_KEEPALIVE keepalive
-//!       HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission
-//!         Saved: no.
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief    Mask event according to bit mask. In case that event is 
-//!            masked (1), the device will not send the masked event to host. 
-//
-//*****************************************************************************
+/**
+* Mask event according to bit mask. In case that event is 
+* masked (1), the device will not send the masked event to host. 
+* @param    mask   mask option:
+*                  HCI_EVNT_WLAN_UNSOL_CONNECT connect event
+*                  HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event
+*                  HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE  smart config done
+*                  HCI_EVNT_WLAN_UNSOL_INIT init done
+*                  HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report
+*                  HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report
+*                  HCI_EVNT_WLAN_KEEPALIVE keepalive
+*                  HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission
+*           Saved: no.
+* @return   On success, zero is returned. On error, -1 is returned        
+*/
 extern long wlan_set_event_mask(unsigned long ulMask);
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_statusget
-//!
-//!  @param none 
-//!
-//!  @return    WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING, 
-//!             STATUS_CONNECTING or WLAN_STATUS_CONNECTED      
-//!
-//!  @brief    get wlan status: disconnected, scanning, connecting or connected
-//
-//*****************************************************************************
+/**
+* Get wlan status: disconnected, scanning, connecting or connected
+* @param none 
+* @return    WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING, 
+*            STATUS_CONNECTING or WLAN_STATUS_CONNECTED      
+*/
 extern long wlan_ioctl_statusget(void);
 
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_set_connection_policy
-//!
-//!  @param    should_connect_to_open_ap  enable(1), disable(0) connect to any 
-//!            available AP. This parameter corresponds to the configuration of 
-//!            item # 3 in the brief description.
-//!  @param    should_use_fast_connect enable(1), disable(0). if enabled, tries 
-//!            to connect to the last connected AP. This parameter corresponds 
-//!            to the configuration of item # 1 in the brief description.
-//!  @param    auto_start enable(1), disable(0) auto connect 
-//!            after reset and periodically reconnect if needed. This 
-//!              configuration configures option 2 in the above description.
-//!
-//!  @return     On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief      When auto is enabled, the device tries to connect according 
-//!              the following policy:
-//!              1) If fast connect is enabled and last connection is valid, 
-//!                 the device will try to connect to it without the scanning 
-//!                 procedure (fast). The last connection will be marked as
-//!                 invalid, due to adding/removing profile. 
-//!              2) If profile exists, the device will try to connect it 
-//!                 (Up to seven profiles).
-//!              3) If fast and profiles are not found, and open mode is
-//!                 enabled, the device will try to connect to any AP.
-//!              * Note that the policy settings are stored in the CC3000 NVMEM.
-//!
-//!  @sa         wlan_add_profile , wlan_ioctl_del_profile 
-//
-//*****************************************************************************
+/**
+* Set connection policy
+* When auto is enabled, the device tries to connect according the following policy:
+* 1) If fast connect is enabled and last connection is valid, 
+*    the device will try to connect to it without the scanning 
+*    procedure (fast). The last connection will be marked as
+*    invalid, due to adding/removing profile. 
+* 2) If profile exists, the device will try to connect it 
+*    (Up to seven profiles).
+* 3) If fast and profiles are not found, and open mode is
+*    enabled, the device will try to connect to any AP.
+* Note that the policy settings are stored in the CC3000 NVMEM.
+* @param    should_connect_to_open_ap  enable(1), disable(0) connect to any 
+*           available AP. This parameter corresponds to the configuration of 
+*           item # 3 in the brief description.
+* @param    should_use_fast_connect enable(1), disable(0). if enabled, tries 
+*           to connect to the last connected AP. This parameter corresponds 
+*           to the configuration of item # 1 in the brief description.
+* @param    auto_start enable(1), disable(0) auto connect 
+*           after reset and periodically reconnect if needed. This 
+*           configuration configures option 2 in the above description.
+* @return   On success, zero is returned. On error, -1 is returned        
+* @sa       wlan_add_profile , wlan_ioctl_del_profile 
+*/
 extern long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
                                              unsigned long should_use_fast_connect,
                                              unsigned long ulUseProfiles);
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_get_scan_results
-//!
-//!  @param[in]    scan_timeout   parameter not supported
-//!  @param[out]   ucResults  scan result (_wlan_full_scan_results_args_t)
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief    Gets entry from scan result table.
-//!            The scan results are returned one by one, and each entry 
-//!            represents a single AP found in the area. The following is a 
-//!            format of the scan result: 
-//!             - 4 Bytes: number of networks found
-//!          - 4 Bytes: The status of the scan: 0 - aged results,
-//!                     1 - results valid, 2 - no results
-//!          - 42 bytes: Result entry, where the bytes are arranged as  follows:
-//!              
-//!                          - 1 bit isValid - is result valid or not
-//!                         - 7 bits rssi - RSSI value;     
-//!                 - 2 bits: securityMode - security mode of the AP:
-//!                           0 - Open, 1 - WEP, 2 WPA, 3 WPA2
-//!                         - 6 bits: SSID name length
-//!                         - 2 bytes: the time at which the entry has entered into 
-//!                            scans result table
-//!                         - 32 bytes: SSID name
-//!                 - 6 bytes:    BSSID 
-//!
-//!  @Note      scan_timeout, is not supported on this version.
-//!
-//!  @sa        wlan_ioctl_set_scan_params 
-//
-//*****************************************************************************
-
-
+/**
+* Gets entry from scan result table.
+* The scan results are returned one by one, and each entry represents a single AP found in the area.
+* The following is a format of the scan result: 
+* - 4 Bytes: number of networks found
+* - 4 Bytes: The status of the scan: 0 - aged results, 1 - results valid, 2 - no results
+* - 42 bytes: Result entry, where the bytes are arranged as  follows:
+*             - 1 bit      isValid      - is result valid or not
+*             - 7 bits     rssi         - RSSI value     
+*             - 2 bits     securityMode - security mode of the AP: 0 - Open, 1 - WEP, 2 WPA, 3 WPA2
+*             - 6 bits     SSID name length
+*             - 2 bytes    the time at which the entry has entered into scans result table
+*             - 32 bytes   SSID name
+*             - 6 bytes    BSSID 
+* @param[in]    scan_timeout   parameter not supported
+* @param[out]   ucResults  scan result (_wlan_full_scan_results_args_t)
+* @return       On success, zero is returned. On error, -1 is returned        
+* @Note      scan_timeout, is not supported on this version.
+* @sa        wlan_ioctl_set_scan_params 
+*/
 extern long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout,
                                         unsigned char *ucResults);
 
-//*****************************************************************************
-//
-//!  wlan_ioctl_set_scan_params
-//!
-//!  @param    uiEnable - start/stop application scan: 
-//!            1 = start scan with default interval value of 10 min. 
-//!            in order to set a different scan interval value apply the value 
-//!            in milliseconds. minimum 1 second. 0=stop). Wlan reset
-//!           (wlan_stop() wlan_start()) is needed when changing scan interval
-//!            value. Saved: No
-//!  @param   uiMinDwellTime   minimum dwell time value to be used for each 
-//!           channel, in milliseconds. Saved: yes
-//!           Recommended Value: 100 (Default: 20)
-//!  @param   uiMaxDwellTime    maximum dwell time value to be used for each
-//!           channel, in milliseconds. Saved: yes
-//!           Recommended Value: 100 (Default: 30)
-//!  @param   uiNumOfProbeRequests  max probe request between dwell time. 
-//!           Saved: yes. Recommended Value: 5 (Default:2)
-//!  @param   uiChannelMask  bitwise, up to 13 channels (0x1fff). 
-//!           Saved: yes. Default: 0x7ff
-//!  @param   uiRSSIThreshold   RSSI threshold. Saved: yes (Default: -80)
-//!  @param   uiSNRThreshold    NSR threshold. Saved: yes (Default: 0)
-//!  @param   uiDefaultTxPower  probe Tx power. Saved: yes (Default: 205)
-//!  @param   aiIntervalList    pointer to array with 16 entries (16 channels) 
-//!           each entry (unsigned long) holds timeout between periodic scan 
-//!           (connection scan) - in milliseconds. Saved: yes. Default 2000ms.
-//!
-//!  @return    On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief    start and stop scan procedure. Set scan parameters. 
-//!
-//!  @Note     uiDefaultTxPower, is not supported on this version.
-//!
-//!  @sa        wlan_ioctl_get_scan_results 
-//
-//*****************************************************************************
+/**
+* start and stop scan procedure. Set scan parameters. 
+* @param    uiEnable             start/stop application scan: 
+*                                1 = start scan with default interval value of 10 min. 
+*                                To set a different scan interval value, apply the value in milliseconds.
+*                                minimum = 1 second. 0=stop.
+*                                Wlan reset (wlan_stop() wlan_start()) is needed when changing scan interval value.
+*                                Saved: No
+* @param   uiMinDwellTime        minimum dwell time value to be used for each channel, in milliseconds.
+*                                Saved: yes
+*                                Recommended Value: 100
+*                                Default: 20
+* @param   uiMaxDwellTime        maximum dwell time value to be used for each channel, in milliseconds.
+*                                Saved: yes
+*                                Recommended Value: 100
+*                                Default: 30
+* @param   uiNumOfProbeRequests  max probe request between dwell time. 
+*                                Saved: yes.
+*                                Recommended Value: 5
+*                                Default:2
+* @param   uiChannelMask         bitwise, up to 13 channels (0x1fff). 
+*                                Saved: yes.
+*                                Default: 0x7ff
+* @param   uiRSSIThreshold       RSSI threshold.
+*                                Saved: yes
+*                                Default: -80
+* @param   uiSNRThreshold        NSR threshold.
+*                                Saved: yes
+*                                Default: 0
+* @param   uiDefaultTxPower      probe Tx power.
+*                                Saved: yes
+*                                Default: 205
+* @param   aiIntervalList        pointer to array with 16 entries (16 channels) 
+*                                Each entry (unsigned long) holds timeout between periodic scan 
+*                                and connection scan - in milliseconds.
+*                                Saved: yes.
+*                                Default 2000ms.
+* @return  On success, zero is returned. On error, -1 is returned        
+* @Note    uiDefaultTxPower, is not supported on this version.
+* @sa      wlan_ioctl_get_scan_results 
+*/
 extern long wlan_ioctl_set_scan_params(unsigned long uiEnable,
                                        unsigned long uiMinDwellTime,
                                        unsigned long uiMaxDwellTime,
@@ -441,92 +397,46 @@
                                        unsigned long *aiIntervalList);
 
                                            
-//*****************************************************************************
-//
-//!  wlan_smart_config_start
-//!
-//!  @param    algoEncryptedFlag indicates whether the information is encrypted
-//!
-//!  @return   On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief   Start to acquire device profile. The device acquire its own 
-//!           profile, if profile message is found. The acquired AP information
-//!           is stored in CC3000 EEPROM only in case AES128 encryption is used.
-//!           In case AES128 encryption is not used, a profile is created by 
-//!           CC3000 internally.
-//!
-//!  @Note    An asynchronous event - Smart Config Done will be generated as soon
-//!           as the process finishes successfully.
-//!
-//!  @sa      wlan_smart_config_set_prefix , wlan_smart_config_stop
-//
-//*****************************************************************************                                        
+/**
+* Start to acquire device profile. The device acquire its own profile, if profile message is found.
+* The acquired AP information is stored in CC3000 EEPROM only when AES128 encryption is used.
+* When AES128 encryption is not used, a profile is internally created by the device.
+* @param    algoEncryptedFlag indicates whether the information is encrypted
+* @return   On success, zero is returned. On error, -1 is returned        
+* @Note     An asynchronous event - Smart Config Done will be generated as soon
+*           as the process finishes successfully.
+* @sa       wlan_smart_config_set_prefix , wlan_smart_config_stop
+*/
 extern long wlan_smart_config_start(unsigned long algoEncryptedFlag);
 
-
-//*****************************************************************************
-//
-//!  wlan_smart_config_stop
-//!
-//!  @param    algoEncryptedFlag indicates whether the information is encrypted
-//!
-//!  @return   On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief   Stop the acquire profile procedure 
-//!
-//!  @sa      wlan_smart_config_start , wlan_smart_config_set_prefix
-//
-//*****************************************************************************
+/**
+* Stop the acquire profile procedure 
+* @param    algoEncryptedFlag indicates whether the information is encrypted
+* @return   On success, zero is returned. On error, -1 is returned        
+* @sa      wlan_smart_config_start , wlan_smart_config_set_prefix
+*/
 extern long wlan_smart_config_stop(void);
 
-//*****************************************************************************
-//
-//!  wlan_smart_config_set_prefix
-//!
-//!  @param   newPrefix  3 bytes identify the SSID prefix for the Smart Config. 
-//!
-//!  @return   On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief   Configure station ssid prefix. The prefix is used internally 
-//!           in CC3000. It should always be TTT.
-//!
-//!  @Note    The prefix is stored in CC3000 NVMEM
-//!
-//!  @sa      wlan_smart_config_start , wlan_smart_config_stop
-//
-//*****************************************************************************
+/**
+* Configure station ssid prefix. The prefix is used internally in CC3000. It should always be TTT.
+* @param   newPrefix  3 bytes identify the SSID prefix for the Smart Config. 
+* @return  On success, zero is returned. On error, -1 is returned        
+* @Note    The prefix is stored in CC3000 NVMEM
+* @sa      wlan_smart_config_start , wlan_smart_config_stop
+*/
 extern long wlan_smart_config_set_prefix(char* cNewPrefix);
 
-//*****************************************************************************
-//
-//!  wlan_smart_config_process
-//!
-//!  @param   none 
-//!
-//!  @return   On success, zero is returned. On error, -1 is returned        
-//!
-//!  @brief   process the acquired data and store it as a profile. The acquired 
-//!           AP information is stored in CC3000 EEPROM encrypted.
-//!           The encrypted data is decrypted and stored as a profile.
-//!           behavior is as defined by connection policy.
-//
-//*****************************************************************************
+/**
+* Process the acquired data and store it as a profile.
+* The acquired AP information is stored in CC3000 EEPROM encrypted.
+* The encrypted data is decrypted and stored as a profile.
+* behavior is as defined by connection policy.
+* @param    none 
+* @return   On success, zero is returned. On error, -1 is returned        
+*/
 extern long wlan_smart_config_process(void);
 
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
 
-
-
-//*****************************************************************************
-//
-// Mark the end of the C bindings section for C++ compilers.
-//
-//*****************************************************************************
 #ifdef    __cplusplus
 }
 #endif // __cplusplus