Exemplo n.º 1
0
long
hash_string( char * s )
{
    long k;
    int block_count;
    
    unsigned char init[16] = 
    { 0x3d, 0x38, 0x73, 0xc2, 0xa2, 0x37, 0x1a, 0x0f,
      0xa7, 0xec, 0x87, 0x22, 0xc9, 0xb8, 0x57, 0xab
    } ;

    union
    {
        long k[4];
        unsigned char array[16];
    } output;

    if (!*s)
        block_count = 0;
    else
    {
        block_count = ( (strlen( s ) - 1 ) / 16 ) +1;
        if (block_count > 16)
            block_count = 16;
    }

    hash128 (block_count, s, init, output.array);
    
    k = ( output.k[0] ^ output.k[1] ^ output.k[2] ^ output.k[3] );
    return k;
}
Exemplo n.º 2
0
static void ble_stack_init(void)
{
  uint32_t err_code;
  ble_gap_conn_sec_mode_t sec_mode;
  uint8_t* tstr;
  uint8_t cksum;
  int i;
  
  // Initialize the SoftDevice handler module.
	if(BOARD_CONFIG_VALUE_ENABLE == UICR_board_config_information->LFCLKSRC_EN)
	{//user config
		SOFTDEVICE_HANDLER_INIT(UICR_board_config_information->LFCLKSRC, false);
	}
	else
	{//default
		SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_16000MS_CALIBRATION, false);
	}
	
  // Enable BLE stack 
  ble_enable_params_t ble_enable_params;
  memset(&ble_enable_params, 0, sizeof(ble_enable_params));
  ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
  ble_enable_params.gatts_enable_params.attr_tab_size = 512;
  err_code = sd_ble_enable(&ble_enable_params);
  APP_ERROR_CHECK(err_code);

  // Register with the SoftDevice handler module for BLE events.
  err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
  APP_ERROR_CHECK(err_code);
  
  // Register with the SoftDevice handler module for BLE events.
  err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
  APP_ERROR_CHECK(err_code);

  sd_ble_gap_address_get(&base_addr);
  hash128(base_addr.addr, 6, device_id);

  base_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;

  tstr = __TIME__;
  cksum = 0;
  for (i=0; i<strlen(__TIME__); i++) {
      cksum += tstr[i];
  }

  base_addr.addr[0] += cksum;
  sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &base_addr);

  BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

  err_code = sd_ble_gap_device_name_set(&sec_mode,
                                        (const uint8_t *)device_name,
                                        strlen(device_name));
  APP_ERROR_CHECK(err_code);
}
Exemplo n.º 3
0
 static uint64_t hash(const CacheItem& data) {
     return hash128(&data, sizeof(CacheItem::key));
 }