Exemplo n.º 1
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);
}
Exemplo n.º 2
0
//*****************************************************************************
//
//!  simple_link_send
//!
//!  @param sd       socket handle
//!  @param buf      write buffer
//!  @param len      buffer length
//!  @param flags    On this version, this parameter is not supported
//!  @param to       pointer to an address structure indicating destination
//!                  address
//!  @param tolen    destination address structure size
//!
//!  @return         Return the number of bytes transmitted, or -1 if an error
//!                  occurred, or -2 in case there are no free buffers available
//!                 (only when SEND_NON_BLOCKING is enabled)
//!
//!  @brief          This function is used to transmit a message to another
//!                  socket
//
//*****************************************************************************
int
simple_link_send(long sd, const void *buf, long len, long flags,
              const sockaddr *to, long tolen, long opcode)
{    
	unsigned char uArgSize,  addrlen;
	unsigned char *ptr, *pDataPtr, *args;
	unsigned long addr_offset;
	int res;
        tBsdReadReturnParams tSocketSendEvent;
	
	// Check the bsd_arguments
	if (0 != (res = HostFlowControlConsumeBuff(sd)))
	{
		return res;
	}
	
	//Update the number of sent packets
	tSLInformation.NumberOfSentPackets++;
	
	// Allocate a buffer and construct a packet and send it over spi
	ptr = tSLInformation.pucTxCommandBuffer;
	args = (ptr + HEADERS_SIZE_DATA);
	
	// Update the offset of data and parameters according to the command
	switch(opcode)
	{ 
	case HCI_CMND_SENDTO:
		{
			addr_offset = len + sizeof(len) + sizeof(len);
			addrlen = 8;
			uArgSize = SOCKET_SENDTO_PARAMS_LEN;
			pDataPtr = ptr + HEADERS_SIZE_DATA + SOCKET_SENDTO_PARAMS_LEN;
			break;
		}
		
	case HCI_CMND_SEND:
		{
			tolen = 0;
			to = NULL;
			uArgSize = HCI_CMND_SEND_ARG_LENGTH;
			pDataPtr = ptr + HEADERS_SIZE_DATA + HCI_CMND_SEND_ARG_LENGTH;
			break;
		}
		
	default:
		{
			break;
		}
	}
	
	// Fill in temporary command buffer
	args = UINT32_TO_STREAM(args, sd);
	args = UINT32_TO_STREAM(args, uArgSize - sizeof(sd));
	args = UINT32_TO_STREAM(args, len);
	args = UINT32_TO_STREAM(args, flags);
	
	if (opcode == HCI_CMND_SENDTO)
	{
		args = UINT32_TO_STREAM(args, addr_offset);
		args = UINT32_TO_STREAM(args, addrlen);
	}
	
	// Copy the data received from user into the TX Buffer
	ARRAY_TO_STREAM(pDataPtr, ((unsigned char *)buf), len);
	
	// In case we are using SendTo, copy the to parameters
	if (opcode == HCI_CMND_SENDTO)
	{	
		ARRAY_TO_STREAM(pDataPtr, ((unsigned char *)to), tolen);
	}
	
	// Initiate a HCI command
	hci_data_send(opcode, ptr, uArgSize, len,(unsigned char*)to, tolen);
        
         if (opcode == HCI_CMND_SENDTO)
            SimpleLinkWaitEvent(HCI_EVNT_SENDTO, &tSocketSendEvent);
         else
            SimpleLinkWaitEvent(HCI_EVNT_SEND, &tSocketSendEvent);
	
	return	(len);
}
Exemplo n.º 3
0
/*******************************************************************************
 **
 ** Function        btusb_lite_hci_event_filter
 **
 ** Description     Filter HCI Events received from BT Controller.
 **
 ** Returns         status: <> 0 if the event must be send to user space (BSA)
 **                         0 if the event is handled
 **
 *******************************************************************************/
int btusb_lite_hci_event_filter(struct btusb *p_dev, UINT8 *p_data, int length)
{
#if 0
    BT_HDR *p_msg;
    UINT8 *p;
    UINT16 size;
#endif

    /* Check if HCI is over IPC */
    if (btusb_lite_is_hci_over_ipc(p_dev) == 0)
    {
        /* If it is not, the event have to be sent through regular HCI */
        return 1;
    }

    /* Check if the Event is a NumberOfCompletePacket Event */
    if (btusb_lite_hci_nocp_event_hdlr(p_dev, p_data, length) == 0)
    {
        return 0;  /* Do not Send this event to user space (we handled it) */
    }

    /* TODO: check if CSB VSE */

    return 1;

#if 0

    /* Add size of both UIPC Length and Event header */
    size = length + sizeof(UINT16) + sizeof(UINT16);

    /* Get a buffer from the pool */
    p_msg = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + size);
    if(unlikely(p_msg == NULL))
    {
        BTUSB_ERR("Unable to get GKI buffer\n");
        return 0;
    }

    if (unlikely(dbgflags & BTUSB_GKI_CHK_MSG) &&
        unlikely(GKI_buffer_status(p_msg) != BUF_STATUS_UNLINKED))
    {
        BTUSB_ERR("buffer != BUF_STATUS_UNLINKED 0x%p\n", p_msg);
        return;
    }

    p_msg->offset = 0;
    p_msg->event = 0;
    p_msg->len = size;

    p = (UINT8 *)(p_msg + 1) + p_msg->offset;

    UINT16_TO_STREAM(p, length + sizeof(UINT16));   /* UIPC Length */
    UINT16_TO_STREAM(p, BT_EVT_TO_BTU_HCI_EVT);     /* UIPC Event */
    UINT8_TO_STREAM(p, hci_event);  /* Write back the HCI Event (we already read it) */
    ARRAY_TO_STREAM(p, p_data, length - 1);         /* Copy Event data */

    /* Send message to User Space */
    btusb_lite_ipc_sent_to_user(p_dev, p_msg);

    return 0;   /* Event handled by the Stack Lite. No need to send it to HCI */
#endif
}
Exemplo n.º 4
0
int32_t cc3000_wlan::add_profile(uint32_t sec_type,
                      uint8_t* ssid,
                      uint32_t ssid_length,
                      uint8_t *b_ssid,
                      uint32_t priority,
                      uint32_t pairwise_cipher_or_tx_key_len,
                      uint32_t group_cipher_tx_key_index,
                      uint32_t key_mgmt,
                      uint8_t* pf_or_key,
                      uint32_t pass_phrase_len) {
    uint16_t arg_len = 0x00;
    int32_t ret;
    uint8_t *ptr;
    int32_t i = 0;
    uint8_t *args;
    uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0};

    ptr = _simple_link.get_transmit_buffer();
    args = (ptr + HEADERS_SIZE_CMD);

    args = UINT32_TO_STREAM(args, sec_type);

    // Setup arguments in accordance with the security type
    switch (sec_type)
    {
        //OPEN
    case WLAN_SEC_UNSEC:
        {
            args = UINT32_TO_STREAM(args, 0x00000014);
            args = UINT32_TO_STREAM(args, ssid_length);
            args = UINT16_TO_STREAM(args, 0);
            if(b_ssid)
            {
                ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, priority);
            ARRAY_TO_STREAM(args, ssid, ssid_length);

            arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ssid_length;
        }
        break;

        //WEP
    case WLAN_SEC_WEP:
        {
            args = UINT32_TO_STREAM(args, 0x00000020);
            args = UINT32_TO_STREAM(args, ssid_length);
            args = UINT16_TO_STREAM(args, 0);
            if(b_ssid)
            {
                ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, priority);
            args = UINT32_TO_STREAM(args, 0x0000000C + ssid_length);
            args = UINT32_TO_STREAM(args, pairwise_cipher_or_tx_key_len);
            args = UINT32_TO_STREAM(args, group_cipher_tx_key_index);
            ARRAY_TO_STREAM(args, ssid, ssid_length);

            for(i = 0; i < 4; i++)
            {
                uint8_t *p = &pf_or_key[i * pairwise_cipher_or_tx_key_len];

                ARRAY_TO_STREAM(args, p, pairwise_cipher_or_tx_key_len);
            }

            arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ssid_length +
                pairwise_cipher_or_tx_key_len * 4;

        }
        break;

        //WPA
        //WPA2
    case WLAN_SEC_WPA:
    case WLAN_SEC_WPA2:
        {
            args = UINT32_TO_STREAM(args, 0x00000028);
            args = UINT32_TO_STREAM(args, ssid_length);
            args = UINT16_TO_STREAM(args, 0);
            if(b_ssid)
            {
                ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN);
            }
            else
            {
                ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
            }
            args = UINT32_TO_STREAM(args, priority);
            args = UINT32_TO_STREAM(args, pairwise_cipher_or_tx_key_len);
            args = UINT32_TO_STREAM(args, group_cipher_tx_key_index);
            args = UINT32_TO_STREAM(args, key_mgmt);
            args = UINT32_TO_STREAM(args, 0x00000008 + ssid_length);
            args = UINT32_TO_STREAM(args, pass_phrase_len);
            ARRAY_TO_STREAM(args, ssid, ssid_length);
            ARRAY_TO_STREAM(args, pf_or_key, pass_phrase_len);

            arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ssid_length + pass_phrase_len;
        }

        break;
    }

    // Initiate a HCI command
    _hci.command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, ptr, arg_len);

    // Wait for command complete event
    _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret);

    return(ret);
}
Exemplo n.º 5
0
//*****************************************************************************
//
//!  simple_link_send
//!
//!  @param sd       socket handle
//!  @param buf      write buffer
//!  @param len      buffer length
//!  @param flags    On this version, this parameter is not supported
//!  @param to       pointer to an address structure indicating destination
//!                  address
//!  @param tolen    destination address structure size
//!
//!  @return         Return the number of bytes transmitted, or -1 if an error
//!                  occurred, or -2 in case there are no free buffers available
//!
//!  @brief          This function is used to transmit a message to another
//!                  socket
//
//*****************************************************************************
static int
simple_link_send(long sd, const void *buf, long len, long flags,
              const sockaddr *to, long tolen, long opcode)
{
  uint8_t uArgSize,  addrlen;
  uint8_t *pDataPtr, *args;
  uint32_t addr_offset = 0;
  int res;
  tBsdReadReturnParams tSocketSendEvent;
  uint16_t rx_opcode;

  // Check the bsd_arguments
  if ((res = consume_buf(sd)) != 0)
    return res;

  // Allocate a buffer and construct a packet and send it over spi
  args = hci_get_data_buffer();

  // Update the offset of data and parameters according to the command
  switch(opcode) {
    case HCI_CMND_SENDTO:
      addr_offset = len + sizeof(len) + sizeof(len);
      addrlen = 8;
      uArgSize = SOCKET_SENDTO_PARAMS_LEN;
      pDataPtr = args + SOCKET_SENDTO_PARAMS_LEN;
      break;

    case HCI_CMND_SEND:
      tolen = 0;
      to = NULL;
      uArgSize = HCI_CMND_SEND_ARG_LENGTH;
      pDataPtr = args + HCI_CMND_SEND_ARG_LENGTH;
      break;

    default:
      return -1;
  }

  // Fill in temporary command buffer
  args = UINT32_TO_STREAM(args, sd);
  args = UINT32_TO_STREAM(args, uArgSize - sizeof(sd));
  args = UINT32_TO_STREAM(args, len);
  args = UINT32_TO_STREAM(args, flags);

  if (opcode == HCI_CMND_SENDTO) {
    args = UINT32_TO_STREAM(args, addr_offset);
    args = UINT32_TO_STREAM(args, addrlen);
  }

  // Copy the data received from user into the TX Buffer
  ARRAY_TO_STREAM(pDataPtr, ((uint8_t *)buf), len);

  // In case we are using SendTo, copy the to parameters
  if (opcode == HCI_CMND_SENDTO) {
    ARRAY_TO_STREAM(pDataPtr, ((uint8_t *)to), tolen);
  }

  if (opcode == HCI_CMND_SENDTO)
    rx_opcode = HCI_EVNT_SENDTO;
  else
    rx_opcode = HCI_EVNT_SEND;

  // Initiate a HCI command
  hci_data_send(opcode, uArgSize, len, (uint8_t*)to, tolen,
      rx_opcode, &tSocketSendEvent);

  return  (len);
}
/*******************************************************************************
**
** Function         nfc_hal_dm_set_config
**
** Description      Send NCI config items to NFCC
**
** Returns          tHAL_NFC_STATUS
**
*******************************************************************************/
tHAL_NFC_STATUS nfc_hal_dm_set_config (UINT8 tlv_size,
                                       UINT8 *p_param_tlvs,
                                       tNFC_HAL_NCI_CBACK *p_cback)
{
    UINT8  *p_buff, *p;
    UINT8  num_param = 0, param_len, rem_len, *p_tlv;
    UINT16 cmd_len = NCI_MSG_HDR_SIZE + tlv_size + 1;
    tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED;

    if ((tlv_size == 0)||(p_param_tlvs == NULL))
    {
        return status;
    }

    if ((p_buff = (UINT8 *) GKI_getbuf ((UINT16)(NCI_MSG_HDR_SIZE + tlv_size))) != NULL)
    {
        p = p_buff;

        NCI_MSG_BLD_HDR0 (p, NCI_MT_CMD, NCI_GID_CORE);
        NCI_MSG_BLD_HDR1 (p, NCI_MSG_CORE_SET_CONFIG);
        UINT8_TO_STREAM  (p, (UINT8) (tlv_size + 1));

        rem_len = tlv_size;
        p_tlv   = p_param_tlvs;
        while (rem_len > 1)
        {
            num_param++;                /* number of params */

            p_tlv ++;                   /* param type   */
            param_len = *p_tlv++;       /* param length */

            rem_len -= 2;               /* param type and length */
            if (rem_len >= param_len)
            {
                rem_len -= param_len;
                p_tlv   += param_len;   /* next param_type */

                if (rem_len == 0)
                {
                    status = HAL_NFC_STATUS_OK;
                    break;
                }
            }
            else
            {
                /* error found */
                break;
            }
        }

        if (status == HAL_NFC_STATUS_OK)
        {
            UINT8_TO_STREAM (p, num_param);
            ARRAY_TO_STREAM (p, p_param_tlvs, tlv_size);

            nfc_hal_dm_send_nci_cmd (p_buff, cmd_len, p_cback);
        }
        else
        {
            HAL_TRACE_ERROR0 ("nfc_hal_dm_set_config ():Bad TLV");
        }

        GKI_freebuf (p_buff);
    }

    return status;
}
Exemplo n.º 7
0
/*******************************************************************************
**   DIS Attributes Database Server Request callback
*******************************************************************************/
UINT8 dis_read_attr_value (UINT8 clcb_idx, UINT16 handle, tGATT_VALUE *p_value,
                           BOOLEAN is_long, tGATT_STATUS *p_status)
{
    tDIS_DB_ENTRY   *p_db_attr = dis_cb.dis_attr;
    UINT8           *p = p_value->value, i, *pp;
    UINT16          offset = p_value->offset;
    UINT8           act = SRVC_ACT_RSP;
    tGATT_STATUS    st = GATT_NOT_FOUND;
    UNUSED(clcb_idx);

    for (i = 0; i < DIS_MAX_CHAR_NUM; i ++, p_db_attr ++)
    {
        if (handle == p_db_attr->handle)
        {
            if ((p_db_attr->uuid == GATT_UUID_PNP_ID || p_db_attr->uuid == GATT_UUID_SYSTEM_ID)&&
                is_long == TRUE)
            {
                st = GATT_NOT_LONG;
                break;
            }
            st = GATT_SUCCESS;

            switch (p_db_attr->uuid)
            {
                case GATT_UUID_MANU_NAME:
                case GATT_UUID_MODEL_NUMBER_STR:
                case GATT_UUID_SERIAL_NUMBER_STR:
                case GATT_UUID_FW_VERSION_STR:
                case GATT_UUID_HW_VERSION_STR:
                case GATT_UUID_SW_VERSION_STR:
                case GATT_UUID_IEEE_DATA:
                    pp = dis_cb.dis_value.data_string[p_db_attr->uuid - GATT_UUID_MODEL_NUMBER_STR];
                    if (pp != NULL)
                    {
                        if (strlen ((char *)pp) > GATT_MAX_ATTR_LEN)
                            p_value->len = GATT_MAX_ATTR_LEN;
                        else
                            p_value->len = (UINT16)strlen ((char *)pp);
                    }
                    else
                        p_value->len = 0;

                    if (offset > p_value->len)
                    {
                        st = GATT_INVALID_OFFSET;
                        break;
                    }
                    else
                    {
                        p_value->len -= offset;
                        pp += offset;
                        ARRAY_TO_STREAM(p, pp, p_value->len);
                        GATT_TRACE_EVENT("GATT_UUID_MANU_NAME len=0x%04x", p_value->len);
                    }
                    break;

                case GATT_UUID_SYSTEM_ID:
                    UINT64_TO_STREAM(p, dis_cb.dis_value.system_id); /* int_min */
                    p_value->len = DIS_SYSTEM_ID_SIZE;
                    break;

                case  GATT_UUID_PNP_ID:
                    UINT8_TO_STREAM(p, dis_cb.dis_value.pnp_id.vendor_id_src);
                    UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.vendor_id);
                    UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.product_id);
                    UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.product_version);
                    p_value->len = DIS_PNP_ID_SIZE;
                    break;

            }
            break;
        }
    }
    *p_status = st;
    return act;
}