コード例 #1
0
ファイル: gzp_host.c プロジェクト: amurlynx/rf-nordic
void gzp_host_execute()
{
  uint8_t rx_pipe;
  uint8_t payload_length;
  uint8_t rx_payload[GZLL_MAX_FW_PAYLOAD_LENGTH];

  gzp_address_exchanged_f = false;

  rx_pipe = gzll_get_rx_data_ready_pipe_number();

  if((rx_pipe == GZP_PAIRING_PIPE) || ((rx_pipe == GZP_DATA_PIPE) && (gzp_encrypted_user_data_length == 0)))
  {
    gzll_rx_fifo_read(rx_payload, &payload_length, NULL);

    switch(rx_payload[0])
    {
      case GZP_CMD_HOST_ADDRESS_REQ:
        gzp_process_address_req(rx_payload);
        break;

      #ifndef GZP_CRYPT_DISABLE

      case GZP_CMD_HOST_ID_REQ:
        gzp_process_id_req(rx_payload);
        break;
      case GZP_CMD_HOST_ID_FETCH:
        gzp_process_id_fetch(rx_payload);
        break;
      case GZP_CMD_KEY_UPDATE_PREPARE:
        gzp_process_key_update_prepare();
        break;
      case GZP_CMD_KEY_UPDATE:
        gzp_process_key_update(rx_payload);
        break;
      case GZP_CMD_ENCRYPTED_USER_DATA:
        gzp_process_encrypted_user_data(rx_payload, payload_length);
        break;

      #endif

      case GZP_CMD_FETCH_RESP:
      default:
        break;
    }
  }

  // Restart reception if "not proximity backoff" period has elapsed
  if(gzll_get_state() == GZLL_IDLE)
  {
    gzll_set_param(GZLL_PARAM_RX_TIMEOUT, 0);
    if(gzp_pairing_enabled_f)
    {
      gzll_set_param(GZLL_PARAM_RX_PIPES, gzll_get_param(GZLL_PARAM_RX_PIPES) | (1 << GZP_PAIRING_PIPE));
    }
    gzll_rx_start();
  }

  #ifndef GZP_CRYPT_DISABLE
  gzp_session_counter_inc();
  #endif
}
コード例 #2
0
ファイル: nrf_gzp_host.c プロジェクト: 1072258106/duband
void gzp_host_execute()
{
  bool gzp_packet_received = false;
  uint32_t payload_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;
  uint8_t rx_payload[NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH];

  gzp_address_exchanged_f = false;

  if(nrf_gzll_get_rx_fifo_packet_count(GZP_PAIRING_PIPE) > 0)
  {    
    gzp_packet_received = nrf_gzll_fetch_packet_from_rx_fifo(GZP_PAIRING_PIPE, rx_payload, &payload_length);
  }
  
  if(!gzp_packet_received && (gzp_encrypted_user_data_length == 0))
  {
    if(nrf_gzll_get_rx_fifo_packet_count(GZP_DATA_PIPE) > 0)
    {  
      gzp_packet_received = nrf_gzll_fetch_packet_from_rx_fifo(GZP_DATA_PIPE, rx_payload, &payload_length);    
    }
  }
  
  if(gzp_packet_received)
  {
    //lint -save -esym(644,rx_payload) //may not have been initialized
    switch(rx_payload[0])
    {
      case GZP_CMD_HOST_ADDRESS_REQ:
        gzp_process_address_req(rx_payload);
        break;

      #ifndef GZP_CRYPT_DISABLE

      case GZP_CMD_HOST_ID_REQ:
        gzp_process_id_req(rx_payload);
        break;
      case GZP_CMD_HOST_ID_FETCH:
        gzp_process_id_fetch(rx_payload);
        break;
      case GZP_CMD_KEY_UPDATE_PREPARE:
        gzp_process_key_update_prepare();
        break;
      case GZP_CMD_KEY_UPDATE:
        gzp_process_key_update(rx_payload);
        break;
      case GZP_CMD_ENCRYPTED_USER_DATA:
        gzp_process_encrypted_user_data(rx_payload, payload_length);
        break;

      #endif

      case GZP_CMD_FETCH_RESP:
      default:
        break;
    }
  }

  // Restart reception if "not proximity backoff" period has elapsed
  if(!nrf_gzll_is_enabled())
  {
    gzll_set_rx_timeout(0);
      
    if(gzp_pairing_enabled_f)
    {
      (void)nrf_gzll_set_rx_pipes_enabled(nrf_gzll_get_rx_pipes_enabled() | (1 << GZP_PAIRING_PIPE));
    }
    
    gzll_rx_start();
  }

  #ifndef GZP_CRYPT_DISABLE
  gzp_session_counter_inc();
  #endif
}