long wlan_disconnect(void)
{
  long ret;
  uint8_t *ptr;

  cc3000_lib_lock();

  ret = EFAIL;
  ptr = tSLInformation.pucTxCommandBuffer;

  hci_command_send(HCI_CMND_WLAN_DISCONNECT, ptr, 0);

  /* Wait for command complete event */

  SimpleLinkWaitEvent(HCI_CMND_WLAN_DISCONNECT, &ret);
  errno = ret;

  cc3000_lib_unlock();

  return ret;
}
Beispiel #2
0
long
accept(long sd, sockaddr *addr, socklen_t *addrlen)
{
	long ret;
	unsigned char *ptr, *args;
	tBsdReturnParams tAcceptReturnArguments;
	
	ret = EFAIL;
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (ptr + HEADERS_SIZE_CMD);
	
	// Fill in temporary command buffer
	args = UINT32_TO_STREAM(args, sd);
	
	// Initiate a HCI command
	hci_command_send(HCI_CMND_ACCEPT,
									 ptr, SOCKET_ACCEPT_PARAMS_LEN);
	
	// Since we are in blocking state - wait for event complete
	SimpleLinkWaitEvent(HCI_CMND_ACCEPT, &tAcceptReturnArguments);
	
	
	// need specify return parameters!!!
	memcpy(addr, &tAcceptReturnArguments.tSocketAddress, ASIC_ADDR_LEN);
	*addrlen = ASIC_ADDR_LEN;
	errno = tAcceptReturnArguments.iStatus; 
	ret = errno;
	
	// if succeeded, iStatus = new socket descriptor. otherwise - error number 
	if(M_IS_VALID_SD(ret))
	{
		set_socket_active_status(ret, SOCKET_STATUS_ACTIVE);
	}
	else
	{
		set_socket_active_status(sd, SOCKET_STATUS_INACTIVE);
	}
	
	return(ret);
}
Beispiel #3
0
long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,
                           unsigned long *aucKeepalive,
                           unsigned long *aucInactivity)
{
  int8_t scRet;
  uint8_t *ptr;
  uint8_t *args;

  cc3000_lib_lock();

  scRet = EFAIL;
  ptr = tSLInformation.pucTxCommandBuffer;
  args = (ptr + HEADERS_SIZE_CMD);

  /* Set minimal values of timers */

  MIN_TIMER_SET(*aucDHCP)
  MIN_TIMER_SET(*aucARP)
  MIN_TIMER_SET(*aucKeepalive)
  MIN_TIMER_SET(*aucInactivity)

  /* Fill in temporary command buffer */

  args = UINT32_TO_STREAM(args, *aucDHCP);
  args = UINT32_TO_STREAM(args, *aucARP);
  args = UINT32_TO_STREAM(args, *aucKeepalive);
  args = UINT32_TO_STREAM(args, *aucInactivity);

  /* Initiate a HCI command */

  hci_command_send(HCI_NETAPP_SET_TIMERS, ptr, NETAPP_SET_TIMER_PARAMS_LEN);

  /* Wait for command complete event */

  SimpleLinkWaitEvent(HCI_NETAPP_SET_TIMERS, &scRet);

  cc3000_lib_unlock();

  return scRet;
}
Beispiel #4
0
long netapp_ping_stop(void)
{
  int8_t scRet;
  uint8_t *ptr;

  cc3000_lib_lock();

  scRet = EFAIL;
  ptr = tSLInformation.pucTxCommandBuffer;

  /* Initiate a HCI command */

  hci_command_send(HCI_NETAPP_PING_STOP, ptr, 0);

  /* Wait for command complete event */

  SimpleLinkWaitEvent(HCI_NETAPP_PING_STOP, &scRet);

  cc3000_lib_unlock();

  return(scRet);
}
Beispiel #5
0
INT32 wlan_smart_config_start(UINT32 algoEncryptedFlag)
{
	INT32 ret;
	UINT8 *ptr;
	UINT8 *args;

	ret = EFAIL;
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (UINT8 *)(ptr + HEADERS_SIZE_CMD);

	// Fill in HCI packet structure
	args = UINT32_TO_STREAM(args, algoEncryptedFlag);
	ret = EFAIL;

	hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, ptr, 
		WLAN_SMART_CONFIG_START_PARAMS_LEN);

	// Wait for command complete event
	SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, &ret);

	return(ret);    
}
Beispiel #6
0
static void SimpleLink_Init_Start(uint16_t usPatchesAvailableAtHost)
{
  uint8_t *ptr;
  uint8_t *args;

  ptr = tSLInformation.pucTxCommandBuffer;
  args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);

  if (usPatchesAvailableAtHost <= SL_PATCHES_REQUEST_DEFAULT ||
      usPatchesAvailableAtHost > SL_PATCHES_REQUEST_FORCE_NONE)
    {
      usPatchesAvailableAtHost = SL_PATCHES_REQUEST_DEFAULT;
    }

  UINT8_TO_STREAM(args, usPatchesAvailableAtHost);

  /* 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);

  SimpleLinkWaitEvent(HCI_CMND_SIMPLE_LINK_START, 0);
}
Beispiel #7
0
long wlan_smart_config_set_prefix(char* cNewPrefix)
{
  long ret;
  uint8_t *ptr;
  uint8_t *args;

  cc3000_lib_lock();

  ret  = EFAIL;
  ptr  = tSLInformation.pucTxCommandBuffer;
  args = (ptr + HEADERS_SIZE_CMD);

  if (cNewPrefix == NULL)
    {
      return ret;
    }

  /* With the new Smart Config, prefix must be TTT */

  else
    {
      *cNewPrefix = 'T';
      *(cNewPrefix + 1) = 'T';
      *(cNewPrefix + 2) = 'T';
    }

  ARRAY_TO_STREAM(args, cNewPrefix, SL_SIMPLE_CONFIG_PREFIX_LENGTH);

  hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, ptr,
                   SL_SIMPLE_CONFIG_PREFIX_LENGTH);

  /* Wait for command complete event */

  SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, &ret);

  cc3000_lib_unlock();

  return ret;
}
Beispiel #8
0
long
wlan_ioctl_get_scan_results(unsigned long ulScanTimeout,
                            unsigned char *ucResults)
{
    unsigned char *ptr;
    unsigned char *args;

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, ulScanTimeout);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS,
                     ptr, WLAN_GET_SCAN_RESULTS_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, ucResults);

    return(0);
}
Beispiel #9
0
int c_socket(long domain, long type, long protocol)
{
  long ret;
  uint8_t *args;

  ret = EFAIL;
  args = hci_get_cmd_buffer();

  // Fill in HCI packet structure
  args = UINT32_TO_STREAM(args, domain);
  args = UINT32_TO_STREAM(args, type);
  args = UINT32_TO_STREAM(args, protocol);

  // Initiate a HCI command
  hci_command_send(HCI_CMND_SOCKET, SOCKET_OPEN_PARAMS_LEN,
      HCI_CMND_SOCKET, &ret);

  // Process the event
  errno = ret;

  return(ret);
}
Beispiel #10
0
INT32 wlan_ioctl_del_profile(UINT32 ulIndex)
{
	INT32 ret;
	UINT8 *ptr;
	UINT8 *args;

	ptr = tSLInformation.pucTxCommandBuffer;
	args = (UINT8 *)(ptr + HEADERS_SIZE_CMD);

	// Fill in HCI packet structure
	args = UINT32_TO_STREAM(args, ulIndex);
	ret = EFAIL;

	// Initiate a HCI command
	hci_command_send(HCI_CMND_WLAN_IOCTL_DEL_PROFILE,
		ptr, WLAN_DEL_PROFILE_PARAMS_LEN);

	// Wait for command complete event
	SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret);

	return(ret);
}
Beispiel #11
0
signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength,
                       unsigned long ulOffset, uint8_t *buff)
{
  uint8_t ucStatus = 0xff;
  uint8_t *ptr;
  uint8_t *args;

  cc3000_lib_lock();

  ptr = tSLInformation.pucTxCommandBuffer;
  args = (ptr + HEADERS_SIZE_CMD);

  /* Fill in HCI packet structure */

  args = UINT32_TO_STREAM(args, ulFileId);
  args = UINT32_TO_STREAM(args, ulLength);
  args = UINT32_TO_STREAM(args, ulOffset);

  /* Initiate a 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
   */

  SimpleLinkWaitData(buff, 0, &ucStatus);

  cc3000_lib_unlock();

  return ucStatus;
}
Beispiel #12
0
long
wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime,
                           unsigned long uiMaxDwellTime,
                           unsigned long uiNumOfProbeRequests,
                           unsigned long uiChannelMask,long iRSSIThreshold,
                           unsigned long uiSNRThreshold,
                           unsigned long uiDefaultTxPower,
                           unsigned long *aiIntervalList)
{
    unsigned long  uiRes;
    unsigned char *ptr;
    unsigned char *args;

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, 36);
    args = UINT32_TO_STREAM(args, uiEnable);
    args = UINT32_TO_STREAM(args, uiMinDwellTime);
    args = UINT32_TO_STREAM(args, uiMaxDwellTime);
    args = UINT32_TO_STREAM(args, uiNumOfProbeRequests);
    args = UINT32_TO_STREAM(args, uiChannelMask);
    args = UINT32_TO_STREAM(args, iRSSIThreshold);
    args = UINT32_TO_STREAM(args, uiSNRThreshold);
    args = UINT32_TO_STREAM(args, uiDefaultTxPower);
    ARRAY_TO_STREAM(args, aiIntervalList, sizeof(unsigned long) *
                    SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM,
                     ptr, WLAN_SET_SCAN_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, &uiRes);

    return(uiRes);
}
Beispiel #13
0
/*****************************************************************************
 * \brief Read data from nvmem
 *
 * Reads data from the file referred by the ulFileId parameter. 
 * Reads data from file ulOffset till len. Err if the file can't
 * be used, is invalid, or if the read is out of bounds. 
 *
 *
 * \param[in] 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 or NVMEM_RM_FILEID.
 * \param[in] ulLength   number of bytes to read  
 * \param[in] ulOffset   ulOffset in file from where to read  
 * \param[out] buff    output buffer pointer
 *
 * \return	    number of bytes read.
 *
 * \sa
 * \note
 * \warning
 *
 *****************************************************************************/
signed long 
nvmem_read(unsigned long ulFileId, unsigned long ulLength, unsigned long ulOffset, unsigned char *buff)
{
    unsigned char ucStatus = 0xFF;
    unsigned char *ptr;
    unsigned char *args;
    
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);
    
    //
    // Fill in HCI packet structure
    //
	args = UINT32_TO_STREAM(args, ulFileId);
	args = UINT32_TO_STREAM(args, ulLength);
	args = UINT32_TO_STREAM(args, ulOffset);

	//
    // Initiate a HCI command
    //
	hci_command_send(HCI_CMND_NVMEM_READ, ptr, NVMEM_READ_PARAMS_LEN);

    SimpleLinkWaitEvent(HCI_CMND_NVMEM_READ, &ucStatus);

	//
	// In case there is a data - read it
	//
	if (ucStatus == 0)
	{
		//
		// Wait for the data in a synchronous way. Here we assume that the buffer is big enough
		// to store also parameters of nvmem
		//
		SimpleLinkWaitData(buff, 0, 0);
	}

    return(ucStatus);
}
    /* init io callback */
    tSLInformation.ReadWlanInterruptPin = sReadWlanInterruptPin;
    tSLInformation.WlanInterruptEnable  = sWlanInterruptEnable;
    tSLInformation.WlanInterruptDisable = sWlanInterruptDisable;
    tSLInformation.WriteWlanPin = sWriteWlanPin;

    //init asynchronous events callback
    tSLInformation.sWlanCB= sWlanCB;

    // By default TX Complete events are routed to host too
    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;
    tSLInformation.pucReceivedData = (unsigned char     *)pvBuffer;

    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
//!
//
//*****************************************************************************

#ifdef __ENABLE_MULTITHREADED_SUPPORT__
void c_wlan_start(unsigned short usPatchesAvailableAtHost)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
void wlan_start(unsigned short usPatchesAvailableAtHost)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{

    unsigned long ulSpiIRQState;

    tSLInformation.NumberOfSentPackets = 0;
    tSLInformation.NumberOfReleasedPackets = 0;
    tSLInformation.usRxEventOpcode = 0;
    tSLInformation.usNumberOfFreeBuffers = 0;
    tSLInformation.usSlBufferLength = 0;
    tSLInformation.usBufferSize = 0;
    tSLInformation.usRxDataPending = 0;
    tSLInformation.slTransmitDataError = 0;
    tSLInformation.usEventOrDataReceived = 0;
    tSLInformation.pucReceivedData = 0;

    // Allocate the memory for the RX/TX data transactions
    tSLInformation.pucTxCommandBuffer = (unsigned char *)wlan_tx_buffer;

    // init spi
    SpiOpen(SpiReceiveHandler);

    // Check the IRQ line
    ulSpiIRQState = tSLInformation.ReadWlanInterruptPin();

    // ASIC 1273 chip enable: toggle WLAN EN line
    tSLInformation.WriteWlanPin( WLAN_ENABLE );

    if (ulSpiIRQState)
    {
        // wait till the IRQ line goes low
        while(tSLInformation.ReadWlanInterruptPin() != 0)
        {
        }
    }
    else
    {
        // Wait till the IRQ line goes high and then low.
        while(tSLInformation.ReadWlanInterruptPin() == 0)
        {
        }

        while(tSLInformation.ReadWlanInterruptPin() != 0)
        {
        }
    }

    SimpleLink_Init_Start(usPatchesAvailableAtHost);

    // Read Buffer's size and finish
    hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0);
    SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0);
}


//*****************************************************************************
//
//!  wlan_stop
//!
//!  @param         none
//!
//!  @return        none
//!
//!  @brief         Stop WLAN device by putting it into reset state.
//!
//!  @sa            wlan_start
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
void c_wlan_stop(void)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
void wlan_stop(void)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    // ASIC 1273 chip disable
    tSLInformation.WriteWlanPin( WLAN_DISABLE );

    // Wait till IRQ line goes high...
    while(tSLInformation.ReadWlanInterruptPin() == 0)
    {
    }

    // Free the used by WLAN Driver memory
    if (tSLInformation.pucTxCommandBuffer)
    {
        tSLInformation.pucTxCommandBuffer = 0;
    }

    SpiClose();
}


//*****************************************************************************
//
//!  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
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len,
                    unsigned char *bssid, unsigned char *key, long key_len)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len,
                  unsigned char *bssid, unsigned char *key, long key_len)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;
    unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};

    ret     = EFAIL;
    ptr     = tSLInformation.pucTxCommandBuffer;
    args    = (ptr + HEADERS_SIZE_CMD);

    // Fill in command buffer
    args = UINT32_TO_STREAM(args, 0x0000001c);
    args = UINT32_TO_STREAM(args, ssid_len);
    args = UINT32_TO_STREAM(args, ulSecType);
    args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
    args = UINT32_TO_STREAM(args, key_len);
    args = UINT16_TO_STREAM(args, 0);

    // padding shall be zeroed
    if(bssid)
    {
        ARRAY_TO_STREAM(args, bssid, ETH_ALEN);
    }
    else
    {
        ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
    }

    ARRAY_TO_STREAM(args, ssid, ssid_len);

    if(key_len && key)
    {
        ARRAY_TO_STREAM(args, key, key_len);
    }

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN +
                                     ssid_len + key_len - 1);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret);
    errno = ret;

    return(ret);
}
#else
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_connect(char *ssid, long ssid_len)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_connect(char *ssid, long ssid_len)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;
    unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};

    ret     = EFAIL;
    ptr     = tSLInformation.pucTxCommandBuffer;
    args    = (ptr + HEADERS_SIZE_CMD);

    // Fill in command buffer
    args = UINT32_TO_STREAM(args, 0x0000001c);
    args = UINT32_TO_STREAM(args, ssid_len);
    args = UINT32_TO_STREAM(args, 0);
    args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
    args = UINT32_TO_STREAM(args, 0);
    args = UINT16_TO_STREAM(args, 0);

    // padding shall be zeroed
    ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
    ARRAY_TO_STREAM(args, ssid, ssid_len);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN +
                                     ssid_len  - 1);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret);
    errno = ret;

    return(ret);
}
#endif

//*****************************************************************************
//
//!  wlan_disconnect
//!
//!  @return    0 disconnected done, other CC3000 already disconnected
//!
//!  @brief      Disconnect connection from AP.
//!
//!  @sa         wlan_connect
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_disconnect(void)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_disconnect(void)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;

    hci_command_send(HCI_CMND_WLAN_DISCONNECT, ptr, 0);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_DISCONNECT, &ret);
    errno = ret;

    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
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
                                        unsigned long ulShouldUseFastConnect,
                                        unsigned long ulUseProfiles)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
                                        unsigned long ulShouldUseFastConnect,
                                        unsigned long ulUseProfiles)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);

    // Fill in HCI packet structure
    args = UINT32_TO_STREAM(args, should_connect_to_open_ap);
    args = UINT32_TO_STREAM(args, ulShouldUseFastConnect);
    args = UINT32_TO_STREAM(args, ulUseProfiles);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY,
                    ptr, WLAN_SET_CONNECTION_POLICY_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, &ret);

    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.
//!			   Important Note: Smartconfig process (in unencrypted mode)
//!			   stores the profile internally with priority 1, so changing
//!			   priorities when adding new profiles should be done with extra care
//!  @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, index (1-7) of the stored profile 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
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_add_profile(unsigned long ulSecType,
                                        unsigned char* ucSsid,
                                        unsigned long ulSsidLen,
                                        unsigned char *ucBssid,
                                        unsigned long ulPriority,
                                        unsigned long ulPairwiseCipher_Or_TxKeyLen,
                                        unsigned long ulGroupCipher_TxKeyIndex,
                                        unsigned long ulKeyMgmt,
                                        unsigned char* ucPf_OrKey,
                                        unsigned long ulPassPhraseLen)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_add_profile(unsigned long ulSecType,
                                        unsigned char* ucSsid,
                                        unsigned long ulSsidLen,
                                        unsigned char *ucBssid,
                                        unsigned long ulPriority,
                                        unsigned long ulPairwiseCipher_Or_TxKeyLen,
                                        unsigned long ulGroupCipher_TxKeyIndex,
                                        unsigned long ulKeyMgmt,
                                        unsigned char* ucPf_OrKey,
                                        unsigned long ulPassPhraseLen)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    unsigned short arg_len;
    long ret;
    unsigned char *ptr;
    long i = 0;
    unsigned char *args;
    unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    args = UINT32_TO_STREAM(args, ulSecType);

    // Setup arguments in accordance with the security type
    switch (ulSecType)
    {
        //OPEN
        case WLAN_SEC_UNSEC:
        {
            args = UINT32_TO_STREAM(args, 0x00000014);
            args = UINT32_TO_STREAM(args, ulSsidLen);
            args = UINT16_TO_STREAM(args, 0);
            if(ucBssid)
            {
                ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, ulPriority);
            ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);

            arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ulSsidLen;
        }
        break;

        //WEP
        case WLAN_SEC_WEP:
        {
            args = UINT32_TO_STREAM(args, 0x00000020);
            args = UINT32_TO_STREAM(args, ulSsidLen);
            args = UINT16_TO_STREAM(args, 0);
            if(ucBssid)
            {
                ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, ulPriority);
            args = UINT32_TO_STREAM(args, 0x0000000C + ulSsidLen);
            args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen);
            args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex);
            ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);

            for(i = 0; i < 4; i++)
            {
                unsigned char *p = &ucPf_OrKey[i * ulPairwiseCipher_Or_TxKeyLen];

                ARRAY_TO_STREAM(args, p, ulPairwiseCipher_Or_TxKeyLen);
            }

            arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ulSsidLen +
                ulPairwiseCipher_Or_TxKeyLen * 4;

        }
        break;

        //WPA
        //WPA2
        case WLAN_SEC_WPA:
        case WLAN_SEC_WPA2:
        {
            args = UINT32_TO_STREAM(args, 0x00000028);
            args = UINT32_TO_STREAM(args, ulSsidLen);
            args = UINT16_TO_STREAM(args, 0);
            if(ucBssid)
            {
                ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, ulPriority);
            args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen);
            args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex);
            args = UINT32_TO_STREAM(args, ulKeyMgmt);
            args = UINT32_TO_STREAM(args, 0x00000008 + ulSsidLen);
            args = UINT32_TO_STREAM(args, ulPassPhraseLen);
            ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);
            ARRAY_TO_STREAM(args, ucPf_OrKey, ulPassPhraseLen);

            arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ulSsidLen + ulPassPhraseLen;
        }

        break;

        //
        // An unrecognized security type was detected. Return an error.
        //
        default:
        {
            return(-1);
        }
    }

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE,
        ptr, arg_len);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret);

    return(ret);
}
#else
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_add_profile(unsigned long ulSecType,
                                        unsigned char* ucSsid,
                                        unsigned long ulSsidLen,
                                        unsigned char *ucBssid,
                                        unsigned long ulPriority,
                                        unsigned long ulPairwiseCipher_Or_TxKeyLen,
                                        unsigned long ulGroupCipher_TxKeyIndex,
                                        unsigned long ulKeyMgmt,
                                        unsigned char* ucPf_OrKey,
                                        unsigned long ulPassPhraseLen)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_add_profile(unsigned long ulSecType,
                                        unsigned char* ucSsid,
                                        unsigned long ulSsidLen,
                                        unsigned char *ucBssid,
                                        unsigned long ulPriority,
                                        unsigned long ulPairwiseCipher_Or_TxKeyLen,
                                        unsigned long ulGroupCipher_TxKeyIndex,
                                        unsigned long ulKeyMgmt,
                                        unsigned char* ucPf_OrKey,
                                        unsigned long ulPassPhraseLen)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    return -1;
}
#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
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_ioctl_del_profile(unsigned long ulIndex)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_ioctl_del_profile(unsigned long ulIndex)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);

    // Fill in HCI packet structure
    args = UINT32_TO_STREAM(args, ulIndex);
    ret = EFAIL;

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_DEL_PROFILE,
        ptr, WLAN_DEL_PROFILE_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret);

    return(ret);
}
Beispiel #15
0
INT32 netapp_ping_send(UINT32 *ip, UINT32 ulPingAttempts, UINT32 ulPingSize, UINT32 ulPingTimeout)
{
    INT8 scRet;
    UINT8 *ptr, *args;

    scRet = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, *ip);
    args = UINT32_TO_STREAM(args, ulPingAttempts);
    args = UINT32_TO_STREAM(args, ulPingSize);
    args = UINT32_TO_STREAM(args, ulPingTimeout);

    // Initiate a HCI command
    hci_command_send(HCI_NETAPP_PING_SEND, ptr, NETAPP_PING_SEND_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_NETAPP_PING_SEND, &scRet);

    return(scRet);
}
Beispiel #16
0
//*****************************************************************************
//
//! 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 c_connect(long sd, const sockaddr *addr, long addrlen)
{
  long ret;
  uint8_t *args;

  ret = EFAIL;
  args = hci_get_cmd_buffer();
  addrlen = 8;

  // Fill in temporary command buffer
  args = UINT32_TO_STREAM(args, sd);
  args = UINT32_TO_STREAM(args, 0x00000008);
  args = UINT32_TO_STREAM(args, addrlen);
  ARRAY_TO_STREAM(args, ((uint8_t *)addr), addrlen);

  // Initiate a HCI command
  hci_command_send(HCI_CMND_CONNECT, SOCKET_CONNECT_PARAMS_LEN,
      HCI_CMND_CONNECT, &ret);

  errno = ret;

  return ret;
}
    /* init io callback */
    tSLInformation.ReadWlanInterruptPin = sReadWlanInterruptPin;
    tSLInformation.WlanInterruptEnable  = sWlanInterruptEnable;
    tSLInformation.WlanInterruptDisable = sWlanInterruptDisable;
    tSLInformation.WriteWlanPin = sWriteWlanPin;

    //init asynchronous events callback
    tSLInformation.sWlanCB= sWlanCB;

    // By default TX Complete events are routed to host too
    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;
    tSLInformation.pucReceivedData = (unsigned char     *)pvBuffer;

    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
//!
//
//*****************************************************************************

#ifdef __ENABLE_MULTITHREADED_SUPPORT__
void c_wlan_start(unsigned short usPatchesAvailableAtHost)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
void wlan_start(unsigned short usPatchesAvailableAtHost)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{

    unsigned long ulSpiIRQState;

    tSLInformation.NumberOfSentPackets = 0;
    tSLInformation.NumberOfReleasedPackets = 0;
    tSLInformation.usRxEventOpcode = 0;
    tSLInformation.usNumberOfFreeBuffers = 0;
    tSLInformation.usSlBufferLength = 0;
    tSLInformation.usBufferSize = 0;
    tSLInformation.usRxDataPending = 0;
    tSLInformation.slTransmitDataError = 0;
    tSLInformation.usEventOrDataReceived = 0;
    tSLInformation.pucReceivedData = 0;

    // Allocate the memory for the RX/TX data transactions
    tSLInformation.pucTxCommandBuffer = (unsigned char *)wlan_tx_buffer;

    // init spi
    SpiOpen(SpiReceiveHandler);

    // Check the IRQ line
    ulSpiIRQState = tSLInformation.ReadWlanInterruptPin();

    // ASIC 1273 chip enable: toggle WLAN EN line
    tSLInformation.WriteWlanPin( WLAN_ENABLE );

    if (ulSpiIRQState)
    {
        // wait till the IRQ line goes low
        while(tSLInformation.ReadWlanInterruptPin() != 0)
        {
        }
    }
    else
    {
        // Wait till the IRQ line goes high and then low.
        while(tSLInformation.ReadWlanInterruptPin() == 0)
        {
        }

        while(tSLInformation.ReadWlanInterruptPin() != 0)
        {
        }
    }

    SimpleLink_Init_Start(usPatchesAvailableAtHost);

    // Read Buffer's size and finish
    hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0);
    SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0);
}


//*****************************************************************************
//
//!  wlan_stop
//!
//!  @param         none
//!
//!  @return        none
//!
//!  @brief         Stop WLAN device by putting it into reset state.
//!
//!  @sa            wlan_start
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
void c_wlan_stop(void)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
void wlan_stop(void)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    // ASIC 1273 chip disable
    tSLInformation.WriteWlanPin( WLAN_DISABLE );

    // Wait till IRQ line goes high...
    while(tSLInformation.ReadWlanInterruptPin() == 0)
    {
    }

    // Free the used by WLAN Driver memory
    if (tSLInformation.pucTxCommandBuffer)
    {
        tSLInformation.pucTxCommandBuffer = 0;
    }

    SpiClose();
}


//*****************************************************************************
//
//!  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
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len,
                    unsigned char *bssid, unsigned char *key, long key_len)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len,
                  unsigned char *bssid, unsigned char *key, long key_len)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;
    unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};

    ret     = EFAIL;
    ptr     = tSLInformation.pucTxCommandBuffer;
    args    = (ptr + HEADERS_SIZE_CMD);

    // Fill in command buffer
    args = UINT32_TO_STREAM(args, 0x0000001c);
    args = UINT32_TO_STREAM(args, ssid_len);
    args = UINT32_TO_STREAM(args, ulSecType);
    args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
    args = UINT32_TO_STREAM(args, key_len);
    args = UINT16_TO_STREAM(args, 0);

    // padding shall be zeroed
    if(bssid)
    {
        ARRAY_TO_STREAM(args, bssid, ETH_ALEN);
    }
    else
    {
        ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
    }

    ARRAY_TO_STREAM(args, ssid, ssid_len);

    if(key_len && key)
    {
        ARRAY_TO_STREAM(args, key, key_len);
    }

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN +
                                     ssid_len + key_len - 1);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret);
    errno = ret;

    return(ret);
}
#else
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_connect(char *ssid, long ssid_len)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_connect(char *ssid, long ssid_len)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;
    unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};

    ret     = EFAIL;
    ptr     = tSLInformation.pucTxCommandBuffer;
    args    = (ptr + HEADERS_SIZE_CMD);

    // Fill in command buffer
    args = UINT32_TO_STREAM(args, 0x0000001c);
    args = UINT32_TO_STREAM(args, ssid_len);
    args = UINT32_TO_STREAM(args, 0);
    args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
    args = UINT32_TO_STREAM(args, 0);
    args = UINT16_TO_STREAM(args, 0);

    // padding shall be zeroed
    ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
    ARRAY_TO_STREAM(args, ssid, ssid_len);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN +
                                     ssid_len  - 1);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret);
    errno = ret;

    return(ret);
}
#endif

//*****************************************************************************
//
//!  wlan_disconnect
//!
//!  @return    0 disconnected done, other CC3000 already disconnected
//!
//!  @brief      Disconnect connection from AP.
//!
//!  @sa         wlan_connect
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_disconnect(void)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_disconnect(void)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;

    hci_command_send(HCI_CMND_WLAN_DISCONNECT, ptr, 0);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_DISCONNECT, &ret);
    errno = ret;

    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
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
                                        unsigned long ulShouldUseFastConnect,
                                        unsigned long ulUseProfiles)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
                                        unsigned long ulShouldUseFastConnect,
                                        unsigned long ulUseProfiles)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);

    // Fill in HCI packet structure
    args = UINT32_TO_STREAM(args, should_connect_to_open_ap);
    args = UINT32_TO_STREAM(args, ulShouldUseFastConnect);
    args = UINT32_TO_STREAM(args, ulUseProfiles);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY,
                    ptr, WLAN_SET_CONNECTION_POLICY_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, &ret);

    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.
//!			   Important Note: Smartconfig process (in unencrypted mode)
//!			   stores the profile internally with priority 1, so changing
//!			   priorities when adding new profiles should be done with extra care
//!  @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, index (1-7) of the stored profile 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
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_add_profile(unsigned long ulSecType,
                                        unsigned char* ucSsid,
                                        unsigned long ulSsidLen,
                                        unsigned char *ucBssid,
                                        unsigned long ulPriority,
                                        unsigned long ulPairwiseCipher_Or_TxKeyLen,
                                        unsigned long ulGroupCipher_TxKeyIndex,
                                        unsigned long ulKeyMgmt,
                                        unsigned char* ucPf_OrKey,
                                        unsigned long ulPassPhraseLen)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_add_profile(unsigned long ulSecType,
                                        unsigned char* ucSsid,
                                        unsigned long ulSsidLen,
                                        unsigned char *ucBssid,
                                        unsigned long ulPriority,
                                        unsigned long ulPairwiseCipher_Or_TxKeyLen,
                                        unsigned long ulGroupCipher_TxKeyIndex,
                                        unsigned long ulKeyMgmt,
                                        unsigned char* ucPf_OrKey,
                                        unsigned long ulPassPhraseLen)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    unsigned short arg_len;
    long ret;
    unsigned char *ptr;
    long i = 0;
    unsigned char *args;
    unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    args = UINT32_TO_STREAM(args, ulSecType);

    // Setup arguments in accordance with the security type
    switch (ulSecType)
    {
        //OPEN
        case WLAN_SEC_UNSEC:
        {
            args = UINT32_TO_STREAM(args, 0x00000014);
            args = UINT32_TO_STREAM(args, ulSsidLen);
            args = UINT16_TO_STREAM(args, 0);
            if(ucBssid)
            {
                ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, ulPriority);
            ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);

            arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ulSsidLen;
        }
        break;

        //WEP
        case WLAN_SEC_WEP:
        {
            args = UINT32_TO_STREAM(args, 0x00000020);
            args = UINT32_TO_STREAM(args, ulSsidLen);
            args = UINT16_TO_STREAM(args, 0);
            if(ucBssid)
            {
                ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, ulPriority);
            args = UINT32_TO_STREAM(args, 0x0000000C + ulSsidLen);
            args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen);
            args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex);
            ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);

            for(i = 0; i < 4; i++)
            {
                unsigned char *p = &ucPf_OrKey[i * ulPairwiseCipher_Or_TxKeyLen];

                ARRAY_TO_STREAM(args, p, ulPairwiseCipher_Or_TxKeyLen);
            }

            arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ulSsidLen +
                ulPairwiseCipher_Or_TxKeyLen * 4;

        }
        break;

        //WPA
        //WPA2
        case WLAN_SEC_WPA:
        case WLAN_SEC_WPA2:
        {
            args = UINT32_TO_STREAM(args, 0x00000028);
            args = UINT32_TO_STREAM(args, ulSsidLen);
            args = UINT16_TO_STREAM(args, 0);
            if(ucBssid)
            {
                ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, ulPriority);
            args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen);
            args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex);
            args = UINT32_TO_STREAM(args, ulKeyMgmt);
            args = UINT32_TO_STREAM(args, 0x00000008 + ulSsidLen);
            args = UINT32_TO_STREAM(args, ulPassPhraseLen);
            ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);
            ARRAY_TO_STREAM(args, ucPf_OrKey, ulPassPhraseLen);

            arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ulSsidLen + ulPassPhraseLen;
        }

        break;

        //
        // An unrecognized security type was detected. Return an error.
        //
        default:
        {
            return(-1);
        }
    }

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE,
        ptr, arg_len);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret);

    return(ret);
}
#else
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_add_profile(unsigned long ulSecType,
                                        unsigned char* ucSsid,
                                        unsigned long ulSsidLen,
                                        unsigned char *ucBssid,
                                        unsigned long ulPriority,
                                        unsigned long ulPairwiseCipher_Or_TxKeyLen,
                                        unsigned long ulGroupCipher_TxKeyIndex,
                                        unsigned long ulKeyMgmt,
                                        unsigned char* ucPf_OrKey,
                                        unsigned long ulPassPhraseLen)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_add_profile(unsigned long ulSecType,
                                        unsigned char* ucSsid,
                                        unsigned long ulSsidLen,
                                        unsigned char *ucBssid,
                                        unsigned long ulPriority,
                                        unsigned long ulPairwiseCipher_Or_TxKeyLen,
                                        unsigned long ulGroupCipher_TxKeyIndex,
                                        unsigned long ulKeyMgmt,
                                        unsigned char* ucPf_OrKey,
                                        unsigned long ulPassPhraseLen)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    return -1;
}
#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
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_ioctl_del_profile(unsigned long ulIndex)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_ioctl_del_profile(unsigned long ulIndex)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);

    // Fill in HCI packet structure
    args = UINT32_TO_STREAM(args, ulIndex);
    ret = EFAIL;

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_DEL_PROFILE,
        ptr, WLAN_DEL_PROFILE_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret);

    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
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_ioctl_get_scan_results(unsigned long ulScanTimeout,
                                   unsigned char *ucResults)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout,
                                   unsigned char *ucResults)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    unsigned char *ptr;
    unsigned char *args;

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, ulScanTimeout);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS,
        ptr, WLAN_GET_SCAN_RESULTS_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, ucResults);

    return(0);
}
#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
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime,
                                  unsigned long uiMaxDwellTime, unsigned long uiNumOfProbeRequests,
                                  unsigned long uiChannelMask, long iRSSIThreshold,
                                  unsigned long uiSNRThreshold, unsigned long uiDefaultTxPower,
                                  unsigned long *aiIntervalList)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime,
                                  unsigned long uiMaxDwellTime, unsigned long uiNumOfProbeRequests,
                                  unsigned long uiChannelMask, long iRSSIThreshold,
                                  unsigned long uiSNRThreshold, unsigned long uiDefaultTxPower,
                                  unsigned long *aiIntervalList)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    unsigned long  uiRes;
    unsigned char *ptr;
    unsigned char *args;

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, 36);
    args = UINT32_TO_STREAM(args, uiEnable);
    args = UINT32_TO_STREAM(args, uiMinDwellTime);
    args = UINT32_TO_STREAM(args, uiMaxDwellTime);
    args = UINT32_TO_STREAM(args, uiNumOfProbeRequests);
    args = UINT32_TO_STREAM(args, uiChannelMask);
    args = UINT32_TO_STREAM(args, iRSSIThreshold);
    args = UINT32_TO_STREAM(args, uiSNRThreshold);
    args = UINT32_TO_STREAM(args, uiDefaultTxPower);
    ARRAY_TO_STREAM(args, aiIntervalList, sizeof(unsigned long) *
                                    SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM,
        ptr, WLAN_SET_SCAN_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, &uiRes);

    return(uiRes);
}
#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.
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_set_event_mask(unsigned long ulMask)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_set_event_mask(unsigned long ulMask)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;


    if ((ulMask & HCI_EVNT_WLAN_TX_COMPLETE) == HCI_EVNT_WLAN_TX_COMPLETE)
    {
        tSLInformation.InformHostOnTxComplete = 0;

        // Since an event is a virtual event - i.e. it is not coming from CC3000
        // there is no need to send anything to the device if it was an only event
        if (ulMask == HCI_EVNT_WLAN_TX_COMPLETE)
        {
            return 0;
        }

        ulMask &= ~HCI_EVNT_WLAN_TX_COMPLETE;
        ulMask |= HCI_EVNT_WLAN_UNSOL_BASE;
    }
    else
    {
        tSLInformation.InformHostOnTxComplete = 1;
    }

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);

    // Fill in HCI packet structure
    args = UINT32_TO_STREAM(args, ulMask);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_EVENT_MASK,
        ptr, WLAN_SET_MASK_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_EVENT_MASK, &ret);

    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
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_ioctl_statusget(void)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_ioctl_statusget(void)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;

    hci_command_send(HCI_CMND_WLAN_IOCTL_STATUSGET,
        ptr, 0);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_STATUSGET, &ret);

    return(ret);
}
#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
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_wlan_smart_config_start(unsigned long algoEncryptedFlag)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long wlan_smart_config_start(unsigned long algoEncryptedFlag)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr;
    unsigned char *args;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);

    // Fill in HCI packet structure
    args = UINT32_TO_STREAM(args, algoEncryptedFlag);
    ret = EFAIL;

    hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, ptr,
                                     WLAN_SMART_CONFIG_START_PARAMS_LEN);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, &ret);

    return(ret);
}
Beispiel #18
0
long netapp_arp_flush(void)
{
  int8_t scRet;
  uint8_t *ptr;


  cc3000_lib_lock();

  scRet = EFAIL;
  ptr = tSLInformation.pucTxCommandBuffer;

  /* Initiate a HCI command */

  hci_command_send(HCI_NETAPP_ARP_FLUSH, ptr, 0);

  /* Wait for command complete event */

  SimpleLinkWaitEvent(HCI_NETAPP_ARP_FLUSH, &scRet);

  cc3000_lib_unlock();

  return scRet;
}
Beispiel #19
0
INT32 listen(INT32 sd, INT32 backlog)
{
	INT32 ret;
	UINT8 *ptr, *args;

	ret = EFAIL;
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (ptr + HEADERS_SIZE_CMD);

	// Fill in temporary command buffer
	args = UINT32_TO_STREAM(args, sd);
	args = UINT32_TO_STREAM(args, backlog);

	// Initiate a HCI command
	hci_command_send(HCI_CMND_LISTEN,
			ptr, SOCKET_LISTEN_PARAMS_LEN);

	// Since we are in blocking state - wait for event complete
	SimpleLinkWaitEvent(HCI_CMND_LISTEN, &ret);
	errno = ret;

	return(ret);
}
Beispiel #20
0
int 
gethostbyname(char * hostname, unsigned short usNameLen, 
							unsigned long* out_ip_addr)
{
    cc3000_check_irq_pin();
	tBsdGethostbynameParams ret;
	unsigned char *ptr, *args;
	
	errno = EFAIL;
	
	if (usNameLen > HOSTNAME_MAX_LENGTH)
	{
		return errno;
	}
	
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (ptr + SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE);
	
	// Fill in HCI packet structure
	args = UINT32_TO_STREAM(args, 8);
	args = UINT32_TO_STREAM(args, usNameLen);
	ARRAY_TO_STREAM(args, hostname, usNameLen);
	
	// Initiate a HCI command
	hci_command_send(HCI_CMND_GETHOSTNAME, ptr, SOCKET_GET_HOST_BY_NAME_PARAMS_LEN
									 + usNameLen - 1);
	
	// Since we are in blocking state - wait for event complete
	SimpleLinkWaitEvent(HCI_EVNT_BSD_GETHOSTBYNAME, &ret);
	
	errno = ret.retVal;
	
	(*((long*)out_ip_addr)) = ret.outputAddress;
	
	return (errno);
	
}
Beispiel #21
0
//*****************************************************************************
//
//! 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 c_accept(long sd, sockaddr *addr, socklen_t *addrlen)
{
  long ret;
  uint8_t *args;
  tBsdReturnParams tAcceptReturnArguments;

  ret = EFAIL;
  args = hci_get_cmd_buffer();

  // Fill in temporary command buffer
  args = UINT32_TO_STREAM(args, sd);

  // Initiate a HCI command
  hci_command_send(HCI_CMND_ACCEPT, SOCKET_ACCEPT_PARAMS_LEN,
      HCI_CMND_ACCEPT, &tAcceptReturnArguments);

  // need specify return parameters!!!
  memcpy(addr, &tAcceptReturnArguments.tSocketAddress, ASIC_ADDR_LEN);
  *addrlen = ASIC_ADDR_LEN;
  errno = tAcceptReturnArguments.iStatus;
  ret = errno;

  return(ret);
}
Beispiel #22
0
    /* wait in busy loop */
    do
    {
        // In case last transmission failed then we will return the last failure
        // reason here.
        // Note that the buffer will not be allocated in this case
        if (tSLInformation.slTransmitDataError != 0)
        {
            errno = tSLInformation.slTransmitDataError;
            tSLInformation.slTransmitDataError = 0;
            return errno;
        }

        if(SOCKET_STATUS_ACTIVE != get_socket_active_status(sd))
            return -1;
    } while(0 == tSLInformation.usNumberOfFreeBuffers);

    tSLInformation.usNumberOfFreeBuffers--;

    return 0;
#else

    // In case last transmission failed then we will return the last failure
    // reason here.
    // Note that the buffer will not be allocated in this case
    if (tSLInformation.slTransmitDataError != 0)
    {
        errno = tSLInformation.slTransmitDataError;
        tSLInformation.slTransmitDataError = 0;
        return errno;
    }
    if(SOCKET_STATUS_ACTIVE != get_socket_active_status(sd))
        return -1;

    //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)
    {
        return -2;
    }
    else
    {
        tSLInformation.usNumberOfFreeBuffers--;
        return 0;
    }
#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.
//
//*****************************************************************************

#ifdef __ENABLE_MULTITHREADED_SUPPORT__
int c_socket(long domain, long type, long protocol)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
int socket(long domain, long type, long protocol)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr, *args;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in HCI packet structure
    args = UINT32_TO_STREAM(args, domain);
    args = UINT32_TO_STREAM(args, type);
    args = UINT32_TO_STREAM(args, protocol);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_SOCKET, ptr, SOCKET_OPEN_PARAMS_LEN);

    // Since we are in blocking state - wait for event complete
    SimpleLinkWaitEvent(HCI_CMND_SOCKET, &ret);

    // Process the event
    errno = ret;

    set_socket_active_status(ret, SOCKET_STATUS_ACTIVE);

    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.
//
//*****************************************************************************

#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_closesocket(long sd)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long closesocket(long sd)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr, *args;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in HCI packet structure
    args = UINT32_TO_STREAM(args, sd);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_CLOSE_SOCKET,
                                     ptr, SOCKET_CLOSE_PARAMS_LEN);

    // Since we are in blocking state - wait for event complete
    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
    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
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_accept(long sd, sockaddr *addr, socklen_t *addrlen)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long accept(long sd, sockaddr *addr, socklen_t *addrlen)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr, *args;
    tBsdReturnParams tAcceptReturnArguments;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, sd);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_ACCEPT,
                                     ptr, SOCKET_ACCEPT_PARAMS_LEN);

    // Since we are in blocking state - wait for event complete
    SimpleLinkWaitEvent(HCI_CMND_ACCEPT, &tAcceptReturnArguments);


    // need specify return parameters!!!
    memcpy(addr, &tAcceptReturnArguments.tSocketAddress, ASIC_ADDR_LEN);
    *addrlen = ASIC_ADDR_LEN;
    errno = tAcceptReturnArguments.iStatus;
    ret = errno;

    // if succeeded, iStatus = new socket descriptor. otherwise - error number
    if(M_IS_VALID_SD(ret))
    {
        set_socket_active_status(ret, SOCKET_STATUS_ACTIVE);
    }
    else
    {
        set_socket_active_status(sd, SOCKET_STATUS_INACTIVE);
    }

    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
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_bind(long sd, const sockaddr *addr, long addrlen)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long bind(long sd, const sockaddr *addr, long addrlen)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr, *args;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    addrlen = ASIC_ADDR_LEN;

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, sd);
    args = UINT32_TO_STREAM(args, 0x00000008);
    args = UINT32_TO_STREAM(args, addrlen);
    ARRAY_TO_STREAM(args, ((unsigned char *)addr), addrlen);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_BIND,
                                     ptr, SOCKET_BIND_PARAMS_LEN);

    // Since we are in blocking state - wait for event complete
    SimpleLinkWaitEvent(HCI_CMND_BIND, &ret);

    errno = ret;

    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
//
//*****************************************************************************
#ifdef __ENABLE_MULTITHREADED_SUPPORT__
long c_listen(long sd, long backlog)
#else /* __ENABLE_MULTITHREADED_SUPPORT__ */
long listen(long sd, long backlog)
#endif /* __ENABLE_MULTITHREADED_SUPPORT__ */
{
    long ret;
    unsigned char *ptr, *args;

    ret = EFAIL;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, sd);
    args = UINT32_TO_STREAM(args, backlog);

    // Initiate a HCI command
    hci_command_send(HCI_CMND_LISTEN,
                                     ptr, SOCKET_LISTEN_PARAMS_LEN);

    // Since we are in blocking state - wait for event complete
    SimpleLinkWaitEvent(HCI_CMND_LISTEN, &ret);
    errno = ret;

    return(ret);
}
Beispiel #23
0
//*****************************************************************************
//
//!  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.
//*****************************************************************************
long c_netapp_ping_send(
    uint32_t *ip,
    uint32_t ulPingAttempts,
    uint32_t ulPingSize,
    uint32_t ulPingTimeout)
{
    signed char scRet;
    uint8_t *args;

    scRet = EFAIL;
    args = hci_get_cmd_buffer();

    // Fill in temporary command buffer
    args = UINT32_TO_STREAM(args, *ip);
    args = UINT32_TO_STREAM(args, ulPingAttempts);
    args = UINT32_TO_STREAM(args, ulPingSize);
    args = UINT32_TO_STREAM(args, ulPingTimeout);

    // Initiate a HCI command
    hci_command_send(HCI_NETAPP_PING_SEND, NETAPP_PING_SEND_PARAMS_LEN,
        HCI_NETAPP_PING_SEND, &scRet);

    return(scRet);
}
Beispiel #24
0
int
setsockopt(long sd, long level, long optname, const void *optval,
					 socklen_t optlen)
{
    cc3000_check_irq_pin();
	int ret;
	unsigned char *ptr, *args;
	
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (ptr + HEADERS_SIZE_CMD);
	
	// Fill in temporary command buffer
	args = UINT32_TO_STREAM(args, sd);
	args = UINT32_TO_STREAM(args, level);
	args = UINT32_TO_STREAM(args, optname);
	args = UINT32_TO_STREAM(args, 0x00000008);
	args = UINT32_TO_STREAM(args, optlen);
	ARRAY_TO_STREAM(args, ((unsigned char *)optval), optlen);
	
	// Initiate a HCI command
	hci_command_send(HCI_CMND_SETSOCKOPT,
									 ptr, SOCKET_SET_SOCK_OPT_PARAMS_LEN  + optlen);
	
	// Since we are in blocking state - wait for event complete
	SimpleLinkWaitEvent(HCI_CMND_SETSOCKOPT, &ret);
	
	if (ret >= 0)
	{
		return (0);
	}
	else
	{
		errno = ret;
		return ret;
	}
}
Beispiel #25
0
//*****************************************************************************
//
//!  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)
{
    cc3000_check_irq_pin();
	unsigned char *ptr, *args;
	tBsdReadReturnParams tSocketReadEvent;
	
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (ptr + HEADERS_SIZE_CMD);
	
	// Fill in HCI packet structure
	args = UINT32_TO_STREAM(args, sd);
	args = UINT32_TO_STREAM(args, len);
	args = UINT32_TO_STREAM(args, flags);
	
	// Generate the read command, and wait for the 
	hci_command_send(opcode,  ptr, SOCKET_RECV_FROM_PARAMS_LEN);
	
	// Since we are in blocking state - wait for event complete
	SimpleLinkWaitEvent(opcode, &tSocketReadEvent);
	
	// In case the number of bytes is more then zero - read data
	if (tSocketReadEvent.iNumberOfBytes > 0)
	{
		// Wait for the data in a synchronous way. Here we assume that the bug is 
		// big enough to store also parameters of receive from too....
		SimpleLinkWaitData(buf, (unsigned char *)from, (unsigned char *)fromlen);
	}
	


	errno = tSocketReadEvent.iNumberOfBytes;

	return(tSocketReadEvent.iNumberOfBytes);
}
Beispiel #26
0
int
select(long nfds, TICC3000fd_set *readsds, TICC3000fd_set *writesds, TICC3000fd_set *exceptsds, 
       struct timeval *timeout)
{
	unsigned char *ptr, *args;
	tBsdSelectRecvParams tParams;
	unsigned long is_blocking;
	
	if( timeout == NULL)
	{
		is_blocking = 1; /* blocking , infinity timeout */
	}
	else
	{
		is_blocking = 0; /* no blocking, timeout */
	}
	
	// Fill in HCI packet structure
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (ptr + HEADERS_SIZE_CMD);
	
	// Fill in temporary command buffer
	args = UINT32_TO_STREAM(args, nfds);
	args = UINT32_TO_STREAM(args, 0x00000014);
	args = UINT32_TO_STREAM(args, 0x00000014);
	args = UINT32_TO_STREAM(args, 0x00000014);
	args = UINT32_TO_STREAM(args, 0x00000014);
	args = UINT32_TO_STREAM(args, is_blocking);
	args = UINT32_TO_STREAM(args, ((readsds) ? *(unsigned long*)readsds : 0));
	args = UINT32_TO_STREAM(args, ((writesds) ? *(unsigned long*)writesds : 0));
	args = UINT32_TO_STREAM(args, ((exceptsds) ? *(unsigned long*)exceptsds : 0));
	
	if (timeout)
	{
		if ( 0 == timeout->tv_sec && timeout->tv_usec < 
				SELECT_TIMEOUT_MIN_MICRO_SECONDS)
		{
			timeout->tv_usec = SELECT_TIMEOUT_MIN_MICRO_SECONDS;
		}
		args = UINT32_TO_STREAM(args, timeout->tv_sec);
		args = UINT32_TO_STREAM(args, timeout->tv_usec);
	}
	
	// Initiate a HCI command
	hci_command_send(HCI_CMND_BSD_SELECT, ptr, SOCKET_SELECT_PARAMS_LEN);
	
	// Since we are in blocking state - wait for event complete
	SimpleLinkWaitEvent(HCI_EVNT_SELECT, &tParams);
	
	// Update actually read FD
	if (tParams.iStatus >= 0)
	{
		if (readsds)
		{
			memcpy(readsds, &tParams.uiRdfd, sizeof(tParams.uiRdfd));
		}
		
		if (writesds)
		{
			memcpy(writesds, &tParams.uiWrfd, sizeof(tParams.uiWrfd)); 
		}
		
		if (exceptsds)
		{
			memcpy(exceptsds, &tParams.uiExfd, sizeof(tParams.uiExfd)); 
		}
		
		return(tParams.iStatus);
		
	}
	else
	{
		errno = tParams.iStatus;
		return(-1);
	}
}
Beispiel #27
0
//*****************************************************************************
//
//!  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.
//!
//*****************************************************************************
void c_netapp_ipconfig(netapp_ipconfig_args_t* ipconfig)
{
  // Initiate a HCI command
  hci_command_send(HCI_NETAPP_IPCONFIG, 0,
      HCI_NETAPP_IPCONFIG, ipconfig );
}
Beispiel #28
0
void
wlan_start(unsigned short usPatchesAvailableAtHost)
{
	unsigned long ulSpiIRQState;
	
	tSLInformation.NumberOfSentPackets = 0;
	tSLInformation.NumberOfReleasedPackets = 0;
        
        tSLInformation.usRxEventOpcode = 0;
	tSLInformation.usNumberOfFreeBuffers = 0;
	tSLInformation.usSlBufferLength = 0;
	tSLInformation.usBufferSize = 0;
	tSLInformation.usRxDataPending = 0;
        
	tSLInformation.slTransmitDataError = 0;
	tSLInformation.usEventOrDataReceived = 0;
        
        tSLInformation.pucReceivedData = 0;

    //
	// Allocate the memory for the RX/TX data transactions
	//
	//tSLInformation.pucTxCommandBuffer = (unsigned char *)wlan_tx_buffer;
    TXPtr = (char *)TX_START_ADD;
    tSLInformation.pucTxCommandBuffer = (unsigned char *)TXPtr;

	//
	// init spi
	//
	SpiOpen(SpiReceiveHandler);

	//
	// Check the IRQ line
	//
	ulSpiIRQState = tSLInformation.ReadWlanInterruptPin();
	
    //
    // ASIC 1273 chip enable: toggle WLAN EN line
    //
    tSLInformation.WriteWlanPin( WLAN_ENABLE );

	if (ulSpiIRQState)
	{
		//
		// wait till the IRQ line goes low
		//
		while(tSLInformation.ReadWlanInterruptPin() != 0)
		{
		}
	}
	else
	{
		//
		// wait till the IRQ line goes high and than low
		//
		while(tSLInformation.ReadWlanInterruptPin() == 0)
		{
		}

		while(tSLInformation.ReadWlanInterruptPin() != 0)
		{
		}
	}
	
	SimpleLink_Init_Start(usPatchesAvailableAtHost);

	// Read Buffer's size and finish
	hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0);
	SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0);
}
Beispiel #29
0
long
wlan_add_profile(unsigned long ulSecType,
                 unsigned char* ucSsid,
                 unsigned long ulSsidLen,
                 unsigned char *ucBssid,
                 unsigned long ulPriority,
                 unsigned long ulPairwiseCipher_Or_TxKeyLen,
                 unsigned long ulGroupCipher_TxKeyIndex,
                 unsigned long ulKeyMgmt,
                 unsigned char* ucPf_OrKey,
                 unsigned long ulPassPhraseLen)
{
    unsigned short arg_len;
    long ret;
    unsigned char *ptr;
    long i = 0;
    unsigned char *args;
    unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};

    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + HEADERS_SIZE_CMD);

    args = UINT32_TO_STREAM(args, ulSecType);

    // Setup arguments in accordance with the security type
    switch (ulSecType)
    {
    //OPEN
    case WLAN_SEC_UNSEC:
    {
        args = UINT32_TO_STREAM(args, 0x00000014);
        args = UINT32_TO_STREAM(args, ulSsidLen);
        args = UINT16_TO_STREAM(args, 0);
        if(ucBssid)
        {
            ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
        }
        else
        {
            ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
        }
        args = UINT32_TO_STREAM(args, ulPriority);
        ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);

        arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ulSsidLen;
    }
    break;

    //WEP
    case WLAN_SEC_WEP:
    {
        args = UINT32_TO_STREAM(args, 0x00000020);
        args = UINT32_TO_STREAM(args, ulSsidLen);
        args = UINT16_TO_STREAM(args, 0);
        if(ucBssid)
        {
            ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
        }
        else
        {
            ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
        }
        args = UINT32_TO_STREAM(args, ulPriority);
        args = UINT32_TO_STREAM(args, 0x0000000C + ulSsidLen);
        args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen);
        args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex);
        ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);

        for(i = 0; i < 4; i++)
        {
            unsigned char *p = &ucPf_OrKey[i * ulPairwiseCipher_Or_TxKeyLen];

            ARRAY_TO_STREAM(args, p, ulPairwiseCipher_Or_TxKeyLen);
        }

        arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ulSsidLen +
                  ulPairwiseCipher_Or_TxKeyLen * 4;

    }
    break;

    //WPA
    //WPA2
    case WLAN_SEC_WPA:
    case WLAN_SEC_WPA2:
    {
        args = UINT32_TO_STREAM(args, 0x00000028);
        args = UINT32_TO_STREAM(args, ulSsidLen);
        args = UINT16_TO_STREAM(args, 0);
        if(ucBssid)
        {
            ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
        }
        else
        {
            ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
        }
        args = UINT32_TO_STREAM(args, ulPriority);
        args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen);
        args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex);
        args = UINT32_TO_STREAM(args, ulKeyMgmt);
        args = UINT32_TO_STREAM(args, 0x00000008 + ulSsidLen);
        args = UINT32_TO_STREAM(args, ulPassPhraseLen);
        ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);
        ARRAY_TO_STREAM(args, ucPf_OrKey, ulPassPhraseLen);

        arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ulSsidLen + ulPassPhraseLen;
    }

    break;
    }

    // Initiate a HCI command
    hci_command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE,
                     ptr, arg_len);

    // Wait for command complete event
    SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret);

    return(ret);
}