Example #1
0
/************************************************************************************
 * @fn          initializeConnection
 *
 * @brief       Initialize some elements of a Connection table entry.
 *
 * input parameters
 * @param   pCInfo  - pointer to Connection Table entry to initialize. The file
 *                    scope variable holding the next link ID value is also updated.
 *
 * output parameters
 * @param   pCInfo  - certain elements are set to specific values.
 *
 *
 * @return   void
 */
static void initializeConnection(connInfo_t *pCInfo)
{
  linkID_t *locLID = &sPersistInfo.nextLinkID;
  uint8_t   tmp;

    /* this element will be populated during the exchange with the peer. */
  pCInfo->portTx = 0;

  pCInfo->connState  =  CONNSTATE_CONNECTED;
  pCInfo->thisLinkID = *locLID;

  /* Generate the next Link ID. This isn't foolproof. If the count wraps
   * we can end up with confusing duplicates. We can protect aginst using
   * one that is already in use but we can't protect against a stale Link ID
   * remembered by an application that doesn't know its connection has been
   * torn down. The test for 0 will hopefully never be true (indicating a wrap).
   */
  (*locLID)++;

  while (!*locLID || (*locLID == SMPL_LINKID_USER_UUD) || map_lid2idx(*locLID, &tmp))
  {
    (*locLID)++;
  }

  return;
}
Example #2
0
/******************************************************************************
 * @fn          nwk_getConnInfo
 *
 * @brief       Return the connection info structure to which the input Link ID maps.
 *
 * input parameters
 * @param   port    - port for which mapping desired
 *
 * output parameters
 *
 * @return   pointer to connInfo_t structure found. NULL if no mapping
 *           found or entry not valid.
 */
connInfo_t *nwk_getConnInfo(linkID_t linkID)
{
  uint8_t idx, rc;

  rc = map_lid2idx(linkID, &idx);

  return (rc && sConTable.connStruct[idx].isValid) ? &sConTable.connStruct[idx] : (connInfo_t *)0;
}
Example #3
0
/******************************************************************************
 * @fn          nwk_getConnInfo
 *
 * @brief       Return the connection info structure to which the input Link ID maps.
 *
 * input parameters
 * @param   port    - port for which mapping desired
 *
 * output parameters
 *
 * @return   pointer to connInfo_t structure found. NULL if no mapping
 *           found or entry not valid.
 */
connInfo_t *nwk_getConnInfo(linkID_t linkID)
{
  uint8_t idx, rc;

  rc = map_lid2idx(linkID, &idx);

  return (rc && (CONNSTATE_CONNECTED == sPersistInfo.connStruct[idx].connState)) ? &sPersistInfo.connStruct[idx] : (connInfo_t *)0;
}
Example #4
0
void nwkGetRemotePeerAddr(linkID_t sLinkId, addr_t *peerAddr)
{
  uint8_t index;
 
  if(map_lid2idx(sLinkId, &index))
  {
    memcpy(peerAddr->addr, sPersistInfo.connStruct[index].peerAddr, NET_ADDR_SIZE);
  }
}
Example #5
0
/******************************************************************************
 * @fn          nwk_getNextConnection
 *
 * @brief       Return the next free connection structure if on is available.
 *
 * input parameters
 *
 * output parameters
 *      The returned structure has the Rx port number populated based on the
 *      free strucure found. This is the port queried when the app wants to
 *      do a receive.
 *
 * @return   pointer to the new connInfo_t structure. NULL if there is
 *           no room in connection structure array.
 */
connInfo_t *nwk_getNextConnection()
{
  uint8_t i;

  for (i=0; i<SYS_NUM_CONNECTIONS; ++i)
  {
    if (sConTable.connStruct[i].isValid)
    {
      continue;
    }
    break;
  }

  if (SYS_NUM_CONNECTIONS == i)
  {
    return (connInfo_t *)0;
  }

  /* this element will be populated during the exchange with the peer. */
  sConTable.connStruct[i].portTx = 0;

  sConTable.connStruct[i].isValid    = 1;
  sConTable.connStruct[i].thisLinkID = sNextLinkID;

  /* Generate the next Link ID. This isn't foolproof. If the count wraps
   * we can end up wthh confusing duplicates. We can protect aginst using
   * one that is already in use but we can't protect against a stale Link ID
   * remembered by an application that doesn't know its connection has been
   * torn down. The test for 0 will hopefully never be true (indicating a wrap).
   */
  sNextLinkID++;
  while (!sNextLinkID || (sNextLinkID == SMPL_LINKID_USER_UUD) || map_lid2idx(sNextLinkID, &i))
  {
    sNextLinkID++;
  }

  return &sConTable.connStruct[i];
}