/*************************************************************************
NAME    
    handleAttPrepareWriteCfmPrepare
    
DESCRIPTION
    This function handles Bluestack response for ATT_PREPARE_WRITE_REQ
    during Prepare Write.
    
RETURNS
    
*/
static void handleAttPrepareWriteCfmPrepare(cid_map_t *conn,
                                            ATT_PREPARE_WRITE_CFM_T *m)
{
    gatt_write_reliable_t *data = &conn->data.req.write_reliable;
    STASH(conn, stash, RELIABLE_WRITE_PREPARE);

    /* convert the data pointer */
    m->value = VmGetPointerFromHandle(m->value);
    
    if (m->result == ATT_RESULT_SUCCESS &&
        /* check that the value matches */
        (m->offset != data->offs ||
         m->size_value != data->size_value ||
         memcmp8(m->value, data->value, m->size_value)))
    {
        stash->status = gatt_status_value_mismatch;
    }
    else
    {
        stash->status = gatt_message_status(m->result);
    }

    /* send the response */
    gatt_message_send(conn, GATT_RELIABLE_WRITE_PREPARE_CFM);
    gattSetConnState(conn, NULL, gatt_ms_none);

    /* free the stored data */
    free(data->value);

    /* free the data pointer */
    free(m->value);
}
示例#2
0
static void assert_memcmp (uword iter)
{
  u8 * s, * d;
  void * s_orig, * d_orig;
  uword i;
  uword size, change;
  word res1, res2;

  for (i = 0; i < iter; i++)
    {
      size = bounded_random_u32 (&g_seed, 1, g_bytes);
      d = alloc_aligned (size, g_align, &d_orig);
      s = alloc_aligned (size, g_align, &s_orig);
      memset (d, 0xba, size);
      memset (s, 0xba, size);
      
      if (size && i % 2 == 0)
	{
	  change = bounded_random_u32 (&g_seed, 0, size - 1);
	  d[change] = 0;
	}
      
      res1 = memcmp8 (d, s, size);
      res2 = kmemcmp (d, s, size);

      if (res1 < 0)
	ASSERT (res2 < 0);
      else if (res1 > 0)
	ASSERT (res2 > 0);
      else
	ASSERT (res2 == 0);

      clib_mem_free_safe (d_orig);
      clib_mem_free_safe (s_orig);
    }

  fformat (stdout, "memcmp() validation successful!\n");
}