//--------------------------------------------------------------------------------------------------
static void StopCellularNetwork
(
    void
)
{
    le_onoff_t  radioState;
    le_result_t result;

    result=le_mrc_GetRadioPower(&radioState);
    if ((result == LE_OK) && (radioState == LE_OFF))
    {
        return;
    }
    else
    {
        // Try to shutdown the radio anyway
        le_mrc_SetRadioPower(LE_OFF);

        // Set a timer that gets the current position.
        le_timer_Ref_t stopCellNetTimer = le_timer_Create("StopCellNetTimer");
        le_clk_Time_t interval = {5, 0}; // 5 seconds

        if ( (le_timer_SetHandler(stopCellNetTimer, StopCellNetTimerHandler) != LE_OK) ||
             (le_timer_SetRepeat(stopCellNetTimer, 0) != LE_OK) ||
             (le_timer_SetInterval(stopCellNetTimer, interval) != LE_OK) ||
             (le_timer_Start(stopCellNetTimer) != LE_OK) )
        {
            LE_ERROR("Could not start the StopCellNet timer!");
        }
    }
}
示例#2
0
//--------------------------------------------------------------------------------------------------
static void ResetClientWatchdog
(
    int32_t timeout ///< [IN] The timeout to reset the watchdog timer to (in milliseconds).
)
{
    le_clk_Time_t timeoutValue;
    WatchdogObj_t* watchDogPtr = GetClientWatchdogPtr();
    if (watchDogPtr != NULL)
    {
        le_timer_Stop(watchDogPtr->timer);
        if (timeout == TIMEOUT_KICK)
        {
            timeoutValue = watchDogPtr->kickTimeoutInterval;
        }
        else
        {
            timeoutValue = MakeTimerInterval(timeout);
        }

        if (timeout != LE_WDOG_TIMEOUT_NEVER)
        {
            // timer should be stopped here so this should never fail
            // testing
            LE_ASSERT(LE_OK == le_timer_SetInterval(watchDogPtr->timer, timeoutValue));
            le_timer_Start(watchDogPtr->timer);
        }
        else
        {
            LE_DEBUG("Timeout set to NEVER!");
        }
    }
}
示例#3
0
int mqttClient_subscribe(mqttClient_t* clientData, const char* topicFilter, mqttClient_QoS_e qos, mqttClient_msgHndlr_f messageHandler)
{ 
  int rc = LE_OK;  
    
  LE_ASSERT(clientData);
  LE_ASSERT(topicFilter);

  if (!clientData->session.isConnected)
  {
    LE_WARN("not connected");
    goto cleanup;
  }

  MQTTString topic = MQTTString_initializer;
  topic.cstring = (char *)topicFilter;
  int len = MQTTSerialize_subscribe(clientData->session.tx.buf, sizeof(clientData->session.tx.buf), 0, mqttClient_getNextPacketId(clientData), 1, &topic, (int*)&qos);
  if (len <= 0)
  {
    LE_ERROR("MQTTSerialize_subscribe() failed(%d)", len);
    rc = LE_BAD_PARAMETER;
    goto cleanup;
  }

  int i;
  for (i = 0; i < MQTT_CLIENT_MAX_MESSAGE_HANDLERS; ++i)
  {
    if (!clientData->msgHndlrs[i].topicFilter)
    {
      LE_DEBUG("call msg handler('%s')", topicFilter);
      clientData->msgHndlrs[i].topicFilter = topicFilter;
      clientData->msgHndlrs[i].fp = messageHandler;
      break;
    }
  }

  if (i == MQTT_CLIENT_MAX_MESSAGE_HANDLERS)
  {
    LE_ERROR("no empty msg handlers");
    rc = LE_BAD_PARAMETER;
  }

  rc = mqttClient_write(clientData, len);
  if (rc)
  {
    LE_ERROR("mqttClient_write() failed(%d)", rc); 
    goto cleanup;             
  }

  rc = le_timer_Start(clientData->session.cmdTimer);
  if (rc)
  {
    LE_ERROR("le_timer_Start() failed(%d)", rc);
    goto cleanup;
  }
        
cleanup:
  return rc;
}
//--------------------------------------------------------------------------------------------------
static void StartCellularNetwork
(
    void
)
{
    le_onoff_t  radioState;
    le_result_t result;

    result=le_mrc_GetRadioPower(&radioState);
    if ((result == LE_OK) && (radioState == LE_ON))
    {
        // Load SIM configuration from secure storage
        le_sim_Id_t simSelected = le_sim_GetSelectedCard();

        if (le_sim_IsPresent(simSelected))
        {
            LoadSimFromSecStore(simSelected);
        }

        // Notify the applications even if the SIM is absent
        GetAndSendCellNetStateEvent();
    }
    else
    {
        // Try to power ON the radio anyway
        le_mrc_SetRadioPower(LE_ON);

        // Set a timer that gets the current position.
        le_timer_Ref_t startCellNetTimer = le_timer_Create("StartCellNetTimer");
        le_clk_Time_t interval = {15, 0}; // 15 seconds

        if ( (le_timer_SetHandler(startCellNetTimer, StartCellNetTimerHandler) != LE_OK) ||
             (le_timer_SetRepeat(startCellNetTimer, 0) != LE_OK) ||
             (le_timer_SetInterval(startCellNetTimer, interval) != LE_OK) ||
             (le_timer_Start(startCellNetTimer) != LE_OK) )
        {
            LE_ERROR("Could not start the StartCellNet timer!");
        }
    }
}
示例#5
0
static int mqttClient_sendConnect(mqttClient_t* clientData, MQTTPacket_connectData* connectData)
{
  int rc = LE_OK;

  LE_ASSERT(clientData);
  LE_ASSERT(connectData);

  if (clientData->session.isConnected)
  {
    LE_WARN("already connected"); 
    goto cleanup;
  } 
    
  int len = MQTTSerialize_connect(clientData->session.tx.buf, sizeof(clientData->session.tx.buf), connectData);
  if (len <= 0)
  {
    LE_ERROR("MQTTSerialize_connect() failed(%d)", len);
    rc = len;
    goto cleanup;
  }

  LE_DEBUG("<--- CONNECT");
  rc = mqttClient_write(clientData, len);
  if (rc)
  {  
    LE_ERROR("mqttClient_write() failed(%d)", rc);
    goto cleanup;
  } 

  rc = le_timer_Start(clientData->session.cmdTimer);
  if (rc)
  {
    LE_ERROR("le_timer_Start() failed(%d)", rc);
    goto cleanup;
  }

cleanup:
  return rc;
}
示例#6
0
int mqttClient_unsubscribe(mqttClient_t* clientData, const char* topicFilter)
{   
  MQTTString topic = MQTTString_initializer;
  int rc = LE_OK;
       
  LE_ASSERT(clientData);

  if (!clientData->session.isConnected)
  {
    LE_WARN("not connected");
    goto cleanup;
  }
    
  topic.cstring = (char *)topicFilter;
  int len = MQTTSerialize_unsubscribe(clientData->session.tx.buf, sizeof(clientData->session.tx.buf), 0, mqttClient_getNextPacketId(clientData), 1, &topic);
  if (len <= 0)
  {
    LE_ERROR("MQTTSerialize_unsubscribe() failed(%d)", len);
    rc = LE_BAD_PARAMETER;
    goto cleanup;
  }

  rc = mqttClient_write(clientData, len);
  if (rc)
  { 
    LE_ERROR("mqttClient_write() failed(%d)", rc);
    goto cleanup; 
  }
 
  rc = le_timer_Start(clientData->session.cmdTimer);
  if (rc)
  {
    LE_ERROR("le_timer_Start() failed(%d)", rc);
    goto cleanup;
  }

cleanup:
  return rc;
}
示例#7
0
//--------------------------------------------------------------------------------------------------
static void MyCallEventHandler
(
    le_mcc_CallRef_t  callRef,
    le_mcc_Event_t callEvent,
    void* contextPtr
)
{
    le_result_t         res;
    static bool firstConnectCall = true;

    LE_INFO("MCC TEST: New Call event: %d for Call %p", callEvent, callRef);

    if (callEvent == LE_MCC_EVENT_ALERTING)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_EVENT_ALERTING.");
        if (firstConnectCall)
        {
            LE_INFO("---!!!! PLEASE CHECK ON THE REMOTE SIDE IF THE PHONE NUMBER IS %s !!!!---",
                            ((ClirStatus == LE_ON) ? "HIDED" : "DISPLAYED"));
            LE_INFO("---!!!! PLEASE HANG UP ON THE REMOTE SIDE !!!!---");
        }
    }
    else if (callEvent == LE_MCC_EVENT_CONNECTED)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_EVENT_CONNECTED.");
        if (firstConnectCall)
        {
            LE_INFO("---!!!! PLEASE TERMINATE THE CALL on THE REMOTE SIDE !!!!---");
            firstConnectCall = false;
        }
    }
    else if (callEvent == LE_MCC_EVENT_TERMINATED)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_EVENT_TERMINATED.");
        le_mcc_TerminationReason_t term = le_mcc_GetTerminationReason(callRef);
        int32_t code = le_mcc_GetPlatformSpecificTerminationCode(callRef);
        switch(term)
        {
            case LE_MCC_TERM_NETWORK_FAIL:
                LE_ERROR("Termination reason is LE_MCC_TERM_NETWORK_FAIL");
                exit(EXIT_FAILURE);
                break;

            case LE_MCC_TERM_UNASSIGNED_NUMBER:
                LE_ERROR("Termination reason is LE_MCC_TERM_UNASSIGNED_NUMBER");
                exit(EXIT_FAILURE);
                break;

            case LE_MCC_TERM_USER_BUSY:
                LE_ERROR("Termination reason is LE_MCC_TERM_USER_BUSY");
                exit(EXIT_FAILURE);
                break;

            case LE_MCC_TERM_LOCAL_ENDED:
                LE_INFO("Termination reason is LE_MCC_TERM_LOCAL_ENDED");
                LE_INFO("mccTest Sequence SUCCESS");
                LE_INFO("mccTest test exit");
                le_mcc_Delete(callRef);
                exit(EXIT_SUCCESS);
                break;

            case LE_MCC_TERM_REMOTE_ENDED:
                LE_INFO("Termination reason is LE_MCC_TERM_REMOTE_ENDED");
                LE_INFO("---!!!! PLEASE CREATE AN INCOMING CALL !!!!---");
                break;

            case LE_MCC_TERM_UNDEFINED:
                LE_ERROR("Termination reason is LE_MCC_TERM_UNDEFINED");
                LE_ERROR("---!!!! PLEASE CREATE AN INCOMING CALL !!!!---");
                break;

            default:
                LE_ERROR("Termination reason is %d", term);
                exit(EXIT_FAILURE);
                break;
        }
        LE_INFO("Termination code is 0x%X", code);

        if (HangUpTimer)
        {
            le_timer_Stop(HangUpTimer);
        }
    }
    else if (callEvent == LE_MCC_EVENT_INCOMING)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_EVENT_INCOMING.");
        res = le_mcc_Answer(callRef);
        if (res == LE_OK)
        {
            LE_INFO("Check MyCallEventHandler passed, I answered the call");
            LE_INFO("All calls will be hung-up in 10 seconds");
            LE_ASSERT(le_timer_Start(HangUpTimer) == LE_OK);
        }
        else
        {
            LE_ERROR("Check MyCallEventHandler failed to answer the call.");
        }
    }
    else if (callEvent == LE_MCC_EVENT_ORIGINATING)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_EVENT_ORIGINATING.");
    }
    else if (callEvent == LE_MCC_EVENT_SETUP)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_EVENT_SETUP.");
    }
    else
    {
        LE_ERROR("Check MyCallEventHandler failed, unknowm event %d.", callEvent);
    }
}
示例#8
0
//--------------------------------------------------------------------------------------------------
ni_IteratorRef_t ni_CreateIterator
(
    le_msg_SessionRef_t sessionRef,  ///< [IN] The user session this request occured on.
    tu_UserRef_t userRef,            ///< [IN] Create the iterator for this user.
    tdb_TreeRef_t treeRef,           ///< [IN] The tree to create the iterator with.
    ni_IteratorType_t type,          ///< [IN] The type of iterator we are creating, read or write?
    const char* initialPathPtr       ///< [IN] The node to move to in the specified tree.
)
//--------------------------------------------------------------------------------------------------
{
    LE_ASSERT(treeRef != NULL);

    // Allocate the object and setup it's initial properties.
    ni_IteratorRef_t iteratorRef = le_mem_ForceAlloc(IteratorPoolRef);

    iteratorRef->creationTime = le_clk_GetRelativeTime();
    iteratorRef->sessionRef = sessionRef;
    iteratorRef->userRef = userRef;
    iteratorRef->treeRef = treeRef;
    iteratorRef->type = type;
    iteratorRef->reference = NULL;
    iteratorRef->isClosed = false;
    iteratorRef->isTerminated = false;

    // Setup the timeout timer for this transaction, if it's been configured.
    time_t configTimeout = ic_GetTransactionTimeout();

    if (configTimeout > 0)
    {
        le_clk_Time_t timeout = { configTimeout, 0 };
        iteratorRef->timerRef = le_timer_Create("Transaction Timer");

        LE_ASSERT(le_timer_SetInterval(iteratorRef->timerRef, timeout) == LE_OK);
        LE_ASSERT(le_timer_SetHandler(iteratorRef->timerRef, OnTransactionTimeout) == LE_OK);
        LE_ASSERT(le_timer_SetContextPtr(iteratorRef->timerRef, iteratorRef) == LE_OK);

        LE_ASSERT(le_timer_Start(iteratorRef->timerRef) == LE_OK);
    }
    else
    {
        iteratorRef->timerRef = NULL;
    }

    // If this is a write iterator, then shadow the tree instead of accessing it directly.
    if (iteratorRef->type == NI_WRITE)
    {
        iteratorRef->treeRef = tdb_ShadowTree(iteratorRef->treeRef);
    }

    // Get the root node of the requested tree, or if this is a write iterator...  Get the shadowed
    // root node of the tree.
    iteratorRef->currentNodeRef = tdb_GetRootNode(iteratorRef->treeRef);
    iteratorRef->pathIterRef = le_pathIter_CreateForUnix("/");


    LE_DEBUG("Created a new %s iterator object <%p> for user %u (%s) on tree %s.",
             TypeString(type),
             iteratorRef,
             tu_GetUserId(userRef),
             tu_GetUserName(userRef),
             tdb_GetTreeName(treeRef));

     // If we were given an initial path, go to it now.  Otherwise stay on the root node.
    if (initialPathPtr)
    {
        ni_GoToNode(iteratorRef, initialPathPtr);
    }

    // Update the tree so that it can keep track of this iterator.
    tdb_RegisterIterator(treeRef, iteratorRef);

    // All done.
    return iteratorRef;
}
示例#9
0
static int mqttClient_connect(mqttClient_t* clientData)
{
  struct sockaddr_in address;
  struct addrinfo *result = NULL;
  struct addrinfo hints = {0, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0, NULL, NULL, NULL};  
  int rc = LE_OK;

  LE_ASSERT(clientData);

  if (clientData->session.sock != MQTT_CLIENT_INVALID_SOCKET)
  {
    LE_WARN("socket already connected");
    goto cleanup;
  }

  rc = getaddrinfo(clientData->session.config.brokerUrl, NULL, &hints, &result);
  if (rc)
  {
    LE_ERROR("getaddrinfo() failed(%d)", rc);
    goto cleanup;
  }
	
  struct addrinfo* res = result;
  while (res)
  {
    if (res->ai_family == AF_INET)
    {
      result = res;
      break;
    }
			
    res = res->ai_next;
  }

  if (result->ai_family == AF_INET)
  {
    address.sin_port = htons(clientData->session.config.portNumber);
    address.sin_family = AF_INET;
    address.sin_addr = ((struct sockaddr_in*)(result->ai_addr))->sin_addr;
  }
  else
  {
    LE_ERROR("find IP('%s') failed", clientData->session.config.brokerUrl);
    rc = LE_FAULT;
    goto cleanup;
  }

  clientData->session.sock = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
  if (clientData->session.sock == -1)
  {
    LE_ERROR("socket() failed(%d)", errno);
    rc = clientData->session.sock;
    goto cleanup;
  }

  clientData->session.sockFdMonitor = le_fdMonitor_Create(MQTT_CLIENT_SOCKET_MONITOR_NAME, clientData->session.sock, mqttClient_socketFdEventHandler, POLLIN | POLLOUT);
  if (!clientData->session.sockFdMonitor)
  {
    LE_ERROR("le_fdMonitor_Create() failed");
    rc = LE_FAULT;
    goto cleanup;
  }

  le_fdMonitor_SetContextPtr(clientData->session.sockFdMonitor, clientData);

  clientData->session.tx.ptr = clientData->session.tx.buf;
  clientData->session.rx.ptr = clientData->session.rx.buf;

  rc = connect(clientData->session.sock, (struct sockaddr*)&address, sizeof(address));
  if (rc == -1)
  {
    rc = le_timer_Start(clientData->session.connTimer);
    if (rc)
    {
      LE_ERROR("le_timer_Start() failed(%d)", rc);
      goto cleanup;
    }

    if (errno != EINPROGRESS)
    {
      LE_ERROR("connect() failed(%d)", errno);
      rc = LE_FAULT;
      goto cleanup;
    }

    LE_DEBUG("connecting('%s')", clientData->session.config.brokerUrl);
    rc = LE_OK;
    goto cleanup;
  }

  LE_DEBUG("connected('%s')", clientData->session.config.brokerUrl);

cleanup:
  freeaddrinfo(result);

  if (rc && (clientData->session.sock != MQTT_CLIENT_INVALID_SOCKET))
  {
    int err = mqttClient_close(clientData);
    if (err)
    {
      LE_ERROR("mqttClient_close() failed(%d)", err);
      goto cleanup;
    }
  }

  return rc;
}
示例#10
0
//--------------------------------------------------------------------------------------------------
static void MyCallEventHandler(le_mcc_call_ObjRef_t  callRef, le_mcc_call_Event_t callEvent, void* contextPtr)
{
    le_result_t         res;

    LE_INFO("MCC TEST: New Call event: %d for Call %p", callEvent, callRef);

    if (callEvent == LE_MCC_CALL_EVENT_ALERTING)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_CALL_EVENT_ALERTING.");
    }
    else if (callEvent == LE_MCC_CALL_EVENT_CONNECTED)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_CALL_EVENT_CONNECTED.");
    }
    else if (callEvent == LE_MCC_CALL_EVENT_TERMINATED)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_CALL_EVENT_TERMINATED.");
        le_mcc_call_TerminationReason_t term = le_mcc_call_GetTerminationReason(callRef);
        switch(term)
        {
            case LE_MCC_CALL_TERM_NETWORK_FAIL:
                LE_INFO("Termination reason is LE_MCC_CALL_TERM_NETWORK_FAIL");
                break;

            case LE_MCC_CALL_TERM_BAD_ADDRESS:
                LE_INFO("Termination reason is LE_MCC_CALL_TERM_BAD_ADDRESS");
                break;

            case LE_MCC_CALL_TERM_BUSY:
                LE_INFO("Termination reason is LE_MCC_CALL_TERM_BUSY");
                break;

            case LE_MCC_CALL_TERM_LOCAL_ENDED:
                LE_INFO("Termination reason is LE_MCC_CALL_TERM_LOCAL_ENDED");
                break;

            case LE_MCC_CALL_TERM_REMOTE_ENDED:
                LE_INFO("Termination reason is LE_MCC_CALL_TERM_REMOTE_ENDED");
                break;

            case LE_MCC_CALL_TERM_NOT_DEFINED:
                LE_INFO("Termination reason is LE_MCC_CALL_TERM_NOT_DEFINED");
                break;

            default:
                LE_INFO("Termination reason is %d", term);
                break;
        }
        le_mcc_call_Delete(callRef);
        if (HangUpTimer)
        {
            le_timer_Stop(HangUpTimer);
        }
    }
    else if (callEvent == LE_MCC_CALL_EVENT_INCOMING)
    {
        LE_INFO("Check MyCallEventHandler passed, event is LE_MCC_CALL_EVENT_INCOMING.");
        res = le_mcc_call_Answer(callRef);
        if (res == LE_OK)
        {
            LE_INFO("Check MyCallEventHandler passed, I answered the call");
            LE_INFO("All calls will be hung-up in 10 seconds");
            LE_ASSERT(le_timer_Start(HangUpTimer) == LE_OK);
        }
        else
        {
            LE_INFO("Check MyCallEventHandler failed to answer the call.");
        }
    }
    else
    {
        LE_INFO("Check MyCallEventHandler failed, unknowm event.");
    }
}