Exemplo n.º 1
0
/*******************************************************************************
**
** Function         DIS_SrInit
**
** Description      Initialize the Device Information Service Server.
**
*******************************************************************************/
tDIS_STATUS DIS_SrInit (tDIS_ATTR_MASK dis_attr_mask)
{
    tBT_UUID          uuid = {LEN_UUID_16, {UUID_SERVCLASS_DEVICE_INFO}};
    UINT16            i = 0;
    tGATT_STATUS      status;
    tDIS_DB_ENTRY        *p_db_attr = &dis_cb.dis_attr[0];

    if (dis_cb.enabled)
    {
        GATT_TRACE_ERROR("DIS already initalized");
        return DIS_SUCCESS;
    }

    memset(&dis_cb, 0, sizeof(tDIS_CB));

    dis_cb.service_handle = GATTS_CreateService (srvc_eng_cb.gatt_if , &uuid, 0, DIS_MAX_ATTR_NUM, TRUE);

    if (dis_cb.service_handle == 0)
    {
        GATT_TRACE_ERROR("Can not create service, DIS_Init failed!");
        return GATT_ERROR;
    }
    dis_cb.max_handle = dis_cb.service_handle + DIS_MAX_ATTR_NUM;

    while (dis_attr_mask != 0 && i < DIS_MAX_CHAR_NUM)
    {
        /* add Manufacturer name
        */
        uuid.uu.uuid16 = p_db_attr->uuid = dis_attr_uuid[i];
        p_db_attr->handle  = GATTS_AddCharacteristic(dis_cb.service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ);
        GATT_TRACE_DEBUG ("DIS_SrInit:  handle of new attribute 0x%04 = x%d", uuid.uu.uuid16, p_db_attr->handle  );
        p_db_attr ++;
        i ++;
        dis_attr_mask >>= 1;
    }

    /* start service
    */
    status = GATTS_StartService (srvc_eng_cb.gatt_if, dis_cb.service_handle, GATT_TRANSPORT_LE_BR_EDR);

    dis_cb.enabled = TRUE;

    return (tDIS_STATUS) status;
}
/*******************************************************************************
**
** Function         btm_ble_att_db_init
**
** Description      GAP ATT database initalization.
**
** Returns          void.
**
*******************************************************************************/
void gap_attr_db_init(void)
{
    tBT_UUID        app_uuid = {LEN_UUID_128,{0}};
    tBT_UUID        uuid     = {LEN_UUID_16,{UUID_SERVCLASS_GAP_SERVER}};
    UINT16          service_handle;
    tGAP_ATTR       *p_db_attr = &gap_cb.gatt_attr[0];
    tGATT_STATUS    status;

    /* Fill our internal UUID with a fixed pattern 0x82 */
    memset (&app_uuid.uu.uuid128, 0x82, LEN_UUID_128);
    memset(gap_cb.gatt_attr, 0, sizeof(tGAP_ATTR) *GAP_MAX_CHAR_NUM);

    gap_cb.gatt_if = GATT_Register(&app_uuid, &gap_cback);

    GATT_StartIf(gap_cb.gatt_if);

    /* Create a GAP service */
    service_handle = GATTS_CreateService (gap_cb.gatt_if, &uuid, 0, GAP_MAX_ATTR_NUM, TRUE);

    GAP_TRACE_EVENT ("gap_attr_db_init service_handle = %d", service_handle);

    /* add Device Name Characteristic
    */
    uuid.len = LEN_UUID_16;
    uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_DEVICE_NAME;
    p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ);
    p_db_attr ++;

    /* add Icon characteristic
    */
    uuid.uu.uuid16   = p_db_attr->uuid = GATT_UUID_GAP_ICON;
    p_db_attr->handle = GATTS_AddCharacteristic(service_handle,
                                                &uuid,
                                                GATT_PERM_READ,
                                                GATT_CHAR_PROP_BIT_READ);
    p_db_attr ++;

#if BTM_PERIPHERAL_ENABLED == TRUE       /* Only needed for peripheral testing */
    /* add preferred connection parameter characteristic
    */
    uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_PREF_CONN_PARAM;
    p_db_attr->attr_value.conn_param.int_max = GAP_PREFER_CONN_INT_MAX; /* 6 */
    p_db_attr->attr_value.conn_param.int_min = GAP_PREFER_CONN_INT_MIN; /* 0 */
    p_db_attr->attr_value.conn_param.latency = GAP_PREFER_CONN_LATENCY; /* 0 */
    p_db_attr->attr_value.conn_param.sp_tout = GAP_PREFER_CONN_SP_TOUT; /* 2000 */
    p_db_attr->handle = GATTS_AddCharacteristic(service_handle,
                                                &uuid,
                                                GATT_PERM_READ,
                                                GATT_CHAR_PROP_BIT_READ);
    p_db_attr ++;
#endif

    /* start service now */
    memset (&app_uuid.uu.uuid128, 0x81, LEN_UUID_128);

    status = GATTS_StartService(gap_cb.gatt_if, service_handle, GAP_TRANSPORT_SUPPORTED );

    GAP_TRACE_EVENT ("GAP App gatt_if: %d  s_hdl = %d start_status=%d",
                      gap_cb.gatt_if, service_handle, status);



}