Exemplo n.º 1
0
void BleServiceDbLoadRecord(void)
{
    if (BleDbCtx(loadCount) == 0)

    {
        Report(("[BleDB] Loading record..."));

//        kal_trace(BT_TRACE_BLE_PROFILES, BLEDB_LOADRECORD);

        BT_GattRegisterConnectedEvent(&BleDbCtx(gattHandler), BleServiceDbGattEventCallback);

        BleDbCtx(bondingHandler).callback = BleServiceDbBondingCb;
        ATTDB_RegisterBondStatus(&BleDbCtx(bondingHandler));

        if (btmtk_fs_is_dir_exist((const U8*)BLE_SERVICE_DATABASE_FILE))
        {
            S32 fd;
            S32 pos_current;
            S32 pos_end;
            ble_service_db *db_node;
            
            fd = btmtk_fs_open((const U8*)BLE_SERVICE_DATABASE_FILE, BTMTK_FS_READ_ONLY);
            if (fd < 0)
            {
                // file is not exist
                goto exit;
            }

            pos_end = btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_END);
            pos_current = btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_BEGIN);

            while (pos_current < pos_end)
            {
                db_node = (ble_service_db *)get_ctrl_buffer(sizeof(ble_service_db));
                OS_MemSet((U8 *)db_node, 0, sizeof(ble_service_db));
                
                btmtk_fs_read(fd, (U8 *)db_node + sizeof(ListEntry), sizeof(ble_service_db) - sizeof(ListEntry));
                pos_current += (sizeof(ble_service_db) - sizeof(ListEntry));

                InsertTailList(&BleDbCtx(servicedbList), &db_node->node);
            }
            btmtk_fs_close(fd);
        }
    }

exit:
    BleDbCtx(loadCount)++;
}
Exemplo n.º 2
0
BtStatus FMP_Register(FmpCallback callback, FmpServiceTypeFlag service_flag)
{
    BtStatus status = BT_STATUS_FAILED;

    OS_LockStack();

    if ((service_flag & FMP_SERVICE_TYPE_LOCATOR_FLAG) &&
	((FMP(service_flag) & FMP_SERVICE_TYPE_LOCATOR_FLAG) == 0))
    {
        status = BT_STATUS_SUCCESS;		
    }

    if ((service_flag & FMP_SERVICE_TYPE_TARGET_FLAG) &&
	((FMP(service_flag) & FMP_SERVICE_TYPE_TARGET_FLAG) == 0))
    {
        status = FmpAttDB_Registration();
    }

    if (status == BT_STATUS_SUCCESS)
    {
        if (FMP(service_flag) == 0)
        {
            /* register the GATT callback to handle connection */
            BT_GattRegisterConnectedEvent(&(FMP(gatt_handler)), FmpGattEventCallback);

            /* register bond callback to obtain bond status */
            FMP(bond_handler).callback = FmpBondingCallback;
            ATTDB_RegisterBondStatus(&FMP(bond_handler));

            FMP(fmp_callback) = callback;
        }
        FMP(service_flag) |= service_flag;
    }

    OS_UnlockStack();
    return status;	
}