Exemplo n.º 1
0
//*****************************************************************************
//
//!  nvmem_read
//!
//!  @param  ulFileId   nvmem file id:\n
//!                     NVMEM_NVS_FILEID, NVMEM_NVS_SHADOW_FILEID,
//!                     NVMEM_WLAN_CONFIG_FILEID, NVMEM_WLAN_CONFIG_SHADOW_FILEID,
//!                     NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID,
//!                     NVMEM_MAC_FILEID, NVMEM_FRONTEND_VARS_FILEID,
//!                     NVMEM_IP_CONFIG_FILEID, NVMEM_IP_CONFIG_SHADOW_FILEID,
//!                     NVMEM_BOOTLOADER_SP_FILEID, NVMEM_RM_FILEID,
//!                     and user files 12-15.
//!  @param  ulLength    number of bytes to read
//!  @param  ulOffset    ulOffset in file from where to read
//!  @param  buff        output buffer pointer
//!
//!  @return       number of bytes read, otherwise error.
//!
//!  @brief       Reads data from the file referred by the ulFileId parameter.
//!               Reads data from file ulOffset till length. Err if the file can't
//!               be used, is invalid, or if the read is out of bounds.
//!
//*****************************************************************************
signed long c_nvmem_read(uint32_t ulFileId, uint32_t ulLength,
                         uint32_t ulOffset, uint8_t *buff)
{
    uint8_t ucStatus = 0xFF;
    uint8_t *args;
    hci_data_read_params_t params;

    args = hci_get_cmd_buffer();

    // 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, NVMEM_READ_PARAMS_LEN,
                     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

    params.fromlen = NULL;
    params.from = NULL;
    params.buf = buff;
    hci_wait_for_data(&params);

    return ucStatus;
}
Exemplo n.º 2
0
//*****************************************************************************
//
//!  netapp_dhcp
//!
//!  @param  aucIP               device mac address, 6 bytes. Saved: yes
//!  @param  aucSubnetMask       device mac address, 6 bytes. Saved: yes
//!  @param  aucDefaultGateway   device mac address, 6 bytes. Saved: yes
//!  @param  aucDNSServer        device mac address, 6 bytes. Saved: yes
//!
//!  @return       return on success 0, otherwise error.
//!
//!  @brief       netapp_dhcp is used to configure the network interface,
//!               static or dynamic (DHCP).\n In order to activate DHCP mode,
//!               aucIP, aucSubnetMask, aucDefaultGateway must be 0.
//!               The default mode of CC3000 is DHCP mode.
//!               Note that the configuration is saved in non volatile memory
//!               and thus preserved over resets.
//!
//! @note         If the mode is altered a reset of CC3000 device is required
//!               in order to apply changes.\nAlso note that asynchronous event
//!               of DHCP_EVENT, which is generated when an IP address is
//!               allocated either by the DHCP server or due to static
//!               allocation is generated only upon a connection to the
//!               AP was established.
//!
//*****************************************************************************
long c_netapp_dhcp(
    uint32_t *aucIP,
    uint32_t *aucSubnetMask,
    uint32_t *aucDefaultGateway,
    uint32_t *aucDNSServer)
{
    signed char scRet;
    uint8_t *args;

    scRet = EFAIL;
    args = hci_get_cmd_buffer();

    // Fill in temporary command buffer
    ARRAY_TO_STREAM(args, aucIP, 4);
    ARRAY_TO_STREAM(args, aucSubnetMask, 4);
    ARRAY_TO_STREAM(args, aucDefaultGateway, 4);
    args = UINT32_TO_STREAM(args, 0);
    ARRAY_TO_STREAM(args, aucDNSServer, 4);

    // Initiate a HCI command
    hci_command_send(HCI_NETAPP_DHCP, NETAPP_DHCP_PARAMS_LEN,
        HCI_NETAPP_DHCP, &scRet);

    return(scRet);
}
Exemplo n.º 3
0
//*****************************************************************************
//
//! setsockopt
//!
//!  @param[in]   sd          socket handle
//!  @param[in]   level       defines the protocol level for this option
//!  @param[in]   optname     defines the option name to Interrogate
//!  @param[in]   optval      specifies a value for the option
//!  @param[in]   optlen      specifies the length of the option value
//!  @return    On success, zero is returned. On error, -1 is returned
//!
//!  @brief  set socket options
//!          This function manipulate the options associated with a socket.
//!          Options may exist at multiple protocol levels; they are always
//!          present at the uppermost socket level.
//!          When manipulating socket options the level at which the option
//!          resides and the name of the option must be specified.
//!          To manipulate options at the socket level, level is specified as
//!          SOL_SOCKET. To manipulate options at any other level the protocol
//!          number of the appropriate protocol controlling the option is
//!          supplied. For example, to indicate that an option is to be
//!          interpreted by the TCP protocol, level should be set to the
//!          protocol number of TCP;
//!          The parameters optval and optlen are used to access optval -
//!          use for setsockopt(). For getsockopt() they identify a buffer
//!          in which the value for the requested option(s) are to
//!          be returned. For getsockopt(), optlen is a value-result
//!          parameter, initially containing the size of the buffer
//!          pointed to by option_value, and modified on return to
//!          indicate the actual size of the value returned. If no option
//!          value is to be supplied or returned, option_value may be NULL.
//!
//!  @Note   On this version the following two socket options are enabled:
//!              The only protocol level supported in this version
//!          is SOL_SOCKET (level).
//!            1. SOCKOPT_RECV_TIMEOUT (optname)
//!               SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout
//!           in milliseconds.
//!             In that case optval should be pointer to uint32_t.
//!            2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on
//!           or off.
//!             In that case optval should be SOCK_ON or SOCK_OFF (optval).
//!
//!  @sa getsockopt
//
//*****************************************************************************
int
c_setsockopt(long sd, long level, long optname, const void *optval, socklen_t optlen)
{
  int ret;
  uint8_t *args;

  args = hci_get_cmd_buffer();

  // 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, ((uint8_t *)optval), optlen);

  // Initiate a HCI command
  hci_command_send(HCI_CMND_SETSOCKOPT, SOCKET_SET_SOCK_OPT_PARAMS_LEN  + optlen,
      HCI_CMND_SETSOCKOPT, &ret);

  if (ret >= 0) {
    return (0);
  }
  else {
    errno = ret;
    return (errno);
  }
}
Exemplo n.º 4
0
//*****************************************************************************
//
//!  netapp_timeout_values
//!
//!  @param  aucDHCP    DHCP lease time request, also impact
//!                     the DHCP renew timeout. Range: [0-0xffffffff] seconds,
//!                     0 or 0xffffffff == infinity lease timeout.
//!                     Resolution:10 seconds. Influence: only after
//!                     reconnecting to the AP.
//!                     Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds.
//!                     The parameter is saved into the CC3000 NVMEM.
//!                     The default value on CC3000 is 14400 seconds.
//!
//!  @param  aucARP     ARP refresh timeout, if ARP entry is not updated by
//!                     incoming packet, the ARP entry will be  deleted by
//!                     the end of the timeout.
//!                     Range: [0-0xffffffff] seconds, 0 == infinity ARP timeout
//!                     Resolution: 10 seconds. Influence: on runtime.
//!                     Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds
//!                     The parameter is saved into the CC3000 NVMEM.
//!                     The default value on CC3000 is 3600 seconds.
//!
//!  @param  aucKeepalive   Keepalive event sent by the end of keepalive timeout
//!                         Range: [0-0xffffffff] seconds, 0 == infinity timeout
//!                         Resolution: 10 seconds.
//!                         Influence: on runtime.
//!                         Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec
//!                         The parameter is saved into the CC3000 NVMEM.
//!                         The default value on CC3000 is 10 seconds.
//!
//!  @param  aucInactivity   Socket inactivity timeout, socket timeout is
//!                          refreshed by incoming or outgoing packet, by the
//!                          end of the socket timeout the socket will be closed
//!                          Range: [0-0xffffffff] sec, 0 == infinity timeout.
//!                          Resolution: 10 seconds. Influence: on runtime.
//!                          Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec
//!                          The parameter is saved into the CC3000 NVMEM.
//!                          The default value on CC3000 is 60 seconds.
//!
//!  @return       return on success 0, otherwise error.
//!
//!  @brief       Set new timeout values. Function set new timeout values for:
//!               DHCP lease timeout, ARP  refresh timeout, keepalive event
//!               timeout and socket inactivity timeout
//!
//! @note         If a parameter set to non zero value which is less than 20s,
//!               it will be set automatically to 20s.
//!
//*****************************************************************************
long c_netapp_timeout_values(
    uint32_t *aucDHCP,
    uint32_t *aucARP,
    uint32_t *aucKeepalive,
    uint32_t *aucInactivity)
{
    signed char scRet;
    uint8_t *args;

    scRet = EFAIL;
    args = hci_get_cmd_buffer();

    // 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, NETAPP_SET_TIMER_PARAMS_LEN,
        HCI_NETAPP_SET_TIMERS, &scRet);

    return(scRet);
}
Exemplo n.º 5
0
//*****************************************************************************
//
//! getsockopt
//!
//!  @param[in]   sd          socket handle
//!  @param[in]   level       defines the protocol level for this option
//!  @param[in]   optname     defines the option name to Interrogate
//!  @param[out]   optval      specifies a value for the option
//!  @param[out]   optlen      specifies the length of the option value
//!  @return    On success, zero is returned. On error, -1 is returned
//!
//!  @brief  set socket options
//!          This function manipulate the options associated with a socket.
//!          Options may exist at multiple protocol levels; they are always
//!          present at the uppermost socket level.
//!          When manipulating socket options the level at which the option
//!          resides and the name of the option must be specified.
//!          To manipulate options at the socket level, level is specified as
//!          SOL_SOCKET. To manipulate options at any other level the protocol
//!          number of the appropriate protocol controlling the option is
//!          supplied. For example, to indicate that an option is to be
//!          interpreted by the TCP protocol, level should be set to the
//!          protocol number of TCP;
//!          The parameters optval and optlen are used to access optval -
//!          use for setsockopt(). For getsockopt() they identify a buffer
//!          in which the value for the requested option(s) are to
//!          be returned. For getsockopt(), optlen is a value-result
//!          parameter, initially containing the size of the buffer
//!          pointed to by option_value, and modified on return to
//!          indicate the actual size of the value returned. If no option
//!          value is to be supplied or returned, option_value may be NULL.
//!
//!  @Note   On this version the following two socket options are enabled:
//!              The only protocol level supported in this version
//!          is SOL_SOCKET (level).
//!            1. SOCKOPT_RECV_TIMEOUT (optname)
//!               SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout
//!           in milliseconds.
//!             In that case optval should be pointer to uint32_t.
//!            2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on
//!           or off.
//!             In that case optval should be SOCK_ON or SOCK_OFF (optval).
//!
//!  @sa setsockopt
//
//*****************************************************************************
int c_getsockopt(long sd, long level, long optname, void *optval,
                         socklen_t *optlen)
{
  uint8_t *args;
  tBsdGetSockOptReturnParams  tRetParams;

  args = hci_get_cmd_buffer();

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

  // Initiate a HCI command
  hci_command_send(HCI_CMND_GETSOCKOPT, SOCKET_GET_SOCK_OPT_PARAMS_LEN,
      HCI_CMND_GETSOCKOPT, &tRetParams);

  if (((signed char)tRetParams.iStatus) >= 0) {
    *optlen = 4;
    memcpy(optval, tRetParams.ucOptValue, 4);
    return (0);
  }
  else {
    errno = tRetParams.iStatus;
    return (errno);
  }
}
Exemplo n.º 6
0
//*****************************************************************************
//
//! gethostbyname
//!
//!  @param[in]   hostname     host name
//!  @param[in]   usNameLen    name length
//!  @param[out]  out_ip_addr  This parameter is filled in with host IP address.
//!                            In case that host name is not resolved,
//!                            out_ip_addr is zero.
//!  @return    On success, positive is returned. On error, negative is returned
//!
//!  @brief  Get host IP by name. Obtain the IP Address of machine on network,
//!          by its name.
//!
//!  @note  On this version, only blocking mode is supported. Also note that
//!          the function requires DNS server to be configured prior to its usage.
//
//*****************************************************************************
int
c_gethostbyname(const char * hostname, uint16_t usNameLen, uint32_t* out_ip_addr)
{
  tBsdGethostbynameParams ret;
  uint8_t *args;

  errno = EFAIL;

  if (usNameLen > HOSTNAME_MAX_LENGTH) {
    return errno;
  }

  args = hci_get_cmd_buffer();

  // 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, SOCKET_GET_HOST_BY_NAME_PARAMS_LEN + usNameLen - 1,
      HCI_EVNT_BSD_GETHOSTBYNAME, &ret);

  errno = ret.retVal;

  (*((long*)out_ip_addr)) = ret.outputAddress;

  return (errno);
}
Exemplo n.º 7
0
//*****************************************************************************
//
//! select
//!
//!  @param[in]   nfds       the highest-numbered file descriptor in any of the
//!                           three sets, plus 1.
//!  @param[out]   writesds   socket descriptors list for write monitoring
//!  @param[out]   readsds    socket descriptors list for read monitoring
//!  @param[out]   exceptsds  socket descriptors list for exception monitoring
//!  @param[in]   timeout     is an upper bound on the amount of time elapsed
//!                           before select() returns. Null means infinity
//!                           timeout. The minimum timeout is 5 milliseconds,
//!                          less than 5 milliseconds will be set
//!                           automatically to 5 milliseconds.
//!  @return    On success, select() returns the number of file descriptors
//!             contained in the three returned descriptor sets (that is, the
//!             total number of bits that are set in readfds, writefds,
//!             exceptfds) which may be zero if the timeout expires before
//!             anything interesting  happens.
//!             On error, -1 is returned.
//!                   *readsds - return the sockets on which Read request will
//!                              return without delay with valid data.
//!                   *writesds - return the sockets on which Write request
//!                                 will return without delay.
//!                   *exceptsds - return the sockets which closed recently.
//!
//!  @brief  Monitor socket activity
//!          Select allow a program to monitor multiple file descriptors,
//!          waiting until one or more of the file descriptors become
//!         "ready" for some class of I/O operation
//!
//!  @Note   If the timeout value set to less than 5ms it will automatically set
//!          to 5ms to prevent overload of the system
//!
//!  @sa socket
//
//*****************************************************************************
int c_select(long nfds, wfd_set *readsds, wfd_set *writesds,
    wfd_set *exceptsds, struct timeval *timeout)
{
  uint8_t *args;
  tBsdSelectRecvParams tParams;
  uint32_t is_blocking;

  if( timeout == NULL) {
    is_blocking = 1; /* blocking , infinity timeout */
  }
  else {
    is_blocking = 0; /* no blocking, timeout */
  }

  // Fill in HCI packet structure
  args = hci_get_cmd_buffer();

  // 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) ? *(uint32_t*)readsds : 0));
  args = UINT32_TO_STREAM(args, ((writesds) ? *(uint32_t*)writesds : 0));
  args = UINT32_TO_STREAM(args, ((exceptsds) ? *(uint32_t*)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, SOCKET_SELECT_PARAMS_LEN,
      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);
  }
}
Exemplo n.º 8
0
//*****************************************************************************
//
//!  netapp_set_debug_level
//!
//!  @param[in]      level    debug level. Bitwise [0-8],
//!                         0(disable)or 1(enable).\n Bitwise map: 0 - Critical
//!                         message, 1 information message, 2 - core messages, 3 -
//!                         HCI messages, 4 - Network stack messages, 5 - wlan
//!                         messages, 6 - wlan driver messages, 7 - epprom messages,
//!                         8 - general messages. Default: 0x13f. Saved: no
//!
//!  @return  On success, zero is returned. On error, -1 is returned
//!
//!  @brief   Debug messages sent via the UART debug channel, this function
//!              enable/disable the debug level
//!
//*****************************************************************************
long c_netapp_set_debug_level(uint32_t ulLevel)
{
  signed char scRet;
  uint8_t *args;

  scRet = EFAIL;
  args = hci_get_cmd_buffer();

  args = UINT32_TO_STREAM(args, ulLevel);

  hci_command_send(HCI_NETAPP_SET_DEBUG_LEVEL, NETAPP_SET_DEBUG_LEVEL_PARAMS_LEN,
      HCI_NETAPP_SET_DEBUG_LEVEL, &scRet);

  return(scRet);
}
Exemplo n.º 9
0
//*****************************************************************************
//
//!  nvmem_create_entry
//!
//!  @param       ulFileId    nvmem file Id:\n
//!                           * NVMEM_AES128_KEY_FILEID: 12
//!                           * NVMEM_SHARED_MEM_FILEID: 13
//!                           * and fileIDs 14 and 15
//!  @param       ulNewLen    entry ulLength
//!
//!  @return       on success 0, error otherwise.
//!
//!  @brief      Create new file entry and allocate space on the NVMEM.
//!              Applies only to user files.
//!              Modify the size of file.
//!              If the entry is unallocated - allocate it to size
//!              ulNewLen (marked invalid).
//!              If it is allocated then deallocate it first.
//!              To just mark the file as invalid without resizing -
//!              set ulNewLen=0.
//!
//*****************************************************************************
signed long c_nvmem_create_entry(uint32_t ulFileId, uint32_t ulNewLen)
{
    uint8_t *args;
    uint16_t retval;

    args = hci_get_cmd_buffer();

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

    // Initiate a HCI command
    hci_command_send(HCI_CMND_NVMEM_CREATE_ENTRY, NVMEM_CREATE_PARAMS_LEN,
                     HCI_CMND_NVMEM_CREATE_ENTRY, &retval);

    return(retval);
}
Exemplo n.º 10
0
long c_closesocket(long sd)
{
  long ret;
  uint8_t *args;

  ret = EFAIL;
  args = hci_get_cmd_buffer();

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

  // Initiate a HCI command
  hci_command_send(HCI_CMND_CLOSE_SOCKET, SOCKET_CLOSE_PARAMS_LEN,
      HCI_CMND_CLOSE_SOCKET, &ret);
  errno = ret;

  return(ret);
}
Exemplo n.º 11
0
//*****************************************************************************
//
//! listen
//!
//!  @param[in]   sd      socket descriptor (handle)
//!  @param[in]  backlog  specifies the listen queue depth. On this version
//!                       backlog is not supported.
//!  @return    On success, zero is returned. On error, -1 is returned.
//!
//!  @brief  listen for connections on a socket
//!          The willingness to accept incoming connections and a queue
//!          limit for incoming connections are specified with listen(),
//!          and then the connections are accepted with accept.
//!          The listen() call applies only to sockets of type SOCK_STREAM
//!          The backlog parameter defines the maximum length the queue of
//!          pending connections may grow to.
//!
//! @sa     socket ; accept ; bind
//!
//! @note   On this version, backlog is not supported
//
//*****************************************************************************
long c_listen(long sd, long backlog)
{
  long ret;
  uint8_t *args;

  ret = EFAIL;
  args = hci_get_cmd_buffer();

  // 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, SOCKET_LISTEN_PARAMS_LEN,
      HCI_CMND_LISTEN, &ret);
  errno = ret;

  return(ret);
}
Exemplo n.º 12
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
//
//*****************************************************************************
static int
simple_link_recv(long sd, void *buf, long len, long flags, sockaddr *from,
                socklen_t *fromlen, long opcode)
{
  int ret;
  uint8_t *args;
  tBsdReadReturnParams tSocketReadEvent;

  args = hci_get_cmd_buffer();

  // 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,  SOCKET_RECV_FROM_PARAMS_LEN,
      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....
    hci_data_read_params_t params;
    params.from = from;
    params.fromlen = fromlen;
    params.buf = buf;
    hci_wait_for_data(&params);
    errno = 0;
    ret = tSocketReadEvent.iNumberOfBytes;
  }
  else if (tSocketReadEvent.iNumberOfBytes == 0) {
    errno = EAGAIN;
    ret = -1;
  }
  else {
    ret = errno = tSocketReadEvent.iNumberOfBytes;
  }

  return ret;
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
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);
}
Exemplo n.º 16
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);
}