コード例 #1
0
static void m_adv_report_generate (uint8_t * const pkt)
{
  bool has_data = false;
  nrf_report_t report;
  btle_ev_param_le_advertising_report_t *adv_report = &report.event.params.le_advertising_report_event;
  
  /* Validate the RSSI value. It is 7 bits, so a value above 0x7F is invalid */
  if (m_rssi > 0x7F)
  {
    return;
  }

  report.event.event_code = BTLE_EVENT_LE_ADVERTISING_REPORT;
  report.event.opcode = BTLE_CMD_NONE;
  
  switch (pkt[0] & 0x0F)
  {
    case PACKET_TYPE_ADV_IND:
      has_data = true;
      adv_report->event_type = BTLE_REPORT_TYPE_ADV_IND;
      break;

    case PACKET_TYPE_ADV_SCAN_IND:
      adv_report->event_type = BTLE_REPORT_TYPE_ADV_SCAN_IND;
      break;

    case PACKET_TYPE_ADV_DIRECT_IND:
      has_data = false;
      adv_report->event_type = BTLE_REPORT_TYPE_ADV_DIRECT_IND;
      break;

    case PACKET_TYPE_ADV_NONCONN_IND:
      has_data = true;
      adv_report->event_type = BTLE_REPORT_TYPE_ADV_NONCONN_IND;
      
      break;
    
    case PACKET_TYPE_SCAN_RSP:
      has_data = true;
      adv_report->event_type = BTLE_REPORT_TYPE_SCAN_RSP;
      break;
    
    default:
      return;
  }
  
  report.valid_packets = m_packets_valid;
  report.invalid_packets = m_packets_invalid;
  memcpy (adv_report->address, &pkt[3], BTLE_DEVICE_ADDRESS__SIZE);
  adv_report->address_type = pkt[1] & 0x01 ? BTLE_ADDR_TYPE_RANDOM : BTLE_ADDR_TYPE_PUBLIC;
  adv_report->rssi = m_rssi;
  
  if (has_data)
  {
    adv_report->length_data = (pkt[2] & 0xFC) - BTLE_DEVICE_ADDRESS__SIZE;
    memcpy(adv_report->report_data, &pkt[9], BTLE_ADVERTISING_DATA__SIZE);
  }
  
  nrf_report_disp_dispatch (&report);
}
/**
* Get data from rx-buffer and dispatch scan req event
*/
static __INLINE void scan_req_evt_dispatch(void)
{
#if 1
	/* prepare scan req report */
	nrf_report_t scan_req_report;
	
	/* packet counters */
	scan_req_report.valid_packets = packet_count_valid;
	scan_req_report.invalid_packets = packet_count_invalid;
	 
	/* event details */
	scan_req_report.event.event_code = BTLE_VS_EVENT_NRF_LL_EVENT_SCAN_REQ_REPORT;
	scan_req_report.event.opcode			= BTLE_CMD_NONE;
	
	scan_addr_get(&scan_req_report.event.params.nrf_scan_req_report_event.address_type, 
									scan_req_report.event.params.nrf_scan_req_report_event.address);
	
	periph_radio_rssi_read(&(scan_req_report.event.params.nrf_scan_req_report_event.rssi));
	periph_radio_channel_get(&(scan_req_report.event.params.nrf_scan_req_report_event.channel));
	
	/* send scan req event to user space */
	nrf_report_disp_dispatch(&scan_req_report);
#endif
}
コード例 #3
0
static void m_adv_report_generate (uint8_t * const pkt)
{
  bool has_data = false;
  nrf_report_t report;
  btle_ev_param_le_advertising_report_t *adv_report = &report.event.params.le_advertising_report_event;
  
  /* Validate the RSSI value. It is 7 bits, so a value above 0x7F is invalid */
  if (m_rssi > 0x7F)
  {
    return;
  }

  report.event.event_code = BTLE_EVENT_LE_ADVERTISING_REPORT;
  report.event.opcode = BTLE_CMD_NONE;
  
  switch (pkt[0] & 0x0F)
  {
    case PACKET_TYPE_ADV_IND:
      has_data = true;
      adv_report->event_type = BTLE_REPORT_TYPE_ADV_IND;
      break;

    case PACKET_TYPE_ADV_SCAN_IND:
      has_data = true;
      adv_report->event_type = BTLE_REPORT_TYPE_ADV_SCAN_IND;
      break;

    case PACKET_TYPE_ADV_DIRECT_IND:
      has_data = false;
      adv_report->event_type = BTLE_REPORT_TYPE_ADV_DIRECT_IND;
      break;

    case PACKET_TYPE_ADV_NONCONN_IND:
      has_data = true;
      adv_report->event_type = BTLE_REPORT_TYPE_ADV_NONCONN_IND;
      
      break;
    
    case PACKET_TYPE_SCAN_RSP:
      has_data = true;
      adv_report->event_type = BTLE_REPORT_TYPE_SCAN_RSP;
      break;
    
    default:
      return;
  }
  
  report.valid_packets = m_packets_valid;
  report.invalid_packets = m_packets_invalid;
  memcpy (adv_report->address, &pkt[3], BTLE_DEVICE_ADDRESS__SIZE);
  


  #define BIT_6                               0x40 /**< The value of bit 6 */
  #define UL_PDU_DD_HEADER_OFFSET             0
  #define UL_PDU_DD_SENDER_PADD_OFFSET        UL_PDU_DD_HEADER_OFFSET   /* Called TxAdd in the spec */
  #define UL_PDU_DD_SENDER_PADD_MASK          BIT_6
  #define UL_PDU_DD_SENDER_PADD_SHIFT         6
  
  adv_report->address_type = (pkt[UL_PDU_DD_SENDER_PADD_OFFSET] & UL_PDU_DD_SENDER_PADD_MASK) >> UL_PDU_DD_SENDER_PADD_SHIFT;
  adv_report->rssi = m_rssi;
  
  adv_report->length_data = (adv_report->length_data       ) - BTLE_DEVICE_ADDRESS__SIZE;
  if (adv_report->length_data > 0x1F)
    return;
  adv_report->length_data  = 0;

  if (has_data)
  {
    adv_report->length_data = (adv_report->length_data       ) - BTLE_DEVICE_ADDRESS__SIZE;
    if (adv_report->length_data > 0x1F)
      return;
    memcpy(adv_report->report_data, &pkt[9], BTLE_ADVERTISING_DATA__SIZE);
  }
  adv_report->num_reports = 1;
  nrf_report_disp_dispatch (&report);
}