SESSION_RESULT allocate_handler(U16 startid, U16 endid, EventCallback callback, Session_Handler **handler) { SESSION_RESULT sret = SR_NOERROR; Session_Handler *shandler = NULL; if (NULL == callback) { return SR_E_INVALID_PARAM; } shandler = (Session_Handler *)malloc(sizeof(Session_Handler)); if (NULL == shandler) { return SR_E_RESOURCE; } InitializeListEntry(&shandler->node); shandler->start_session_Id = (startid < endid) ? startid : endid; shandler->end_session_Id = (startid < endid) ? endid : startid; shandler->callback = callback; shandler->identify = get_handler_identify(); *handler = shandler; return SR_NOERROR; }
BOOL btadp_jsr82_session_add_task(BT_ADP_JSR82_SESSION *session, BT_JSR82_TASK_CODE code, void *context) { BT_Jsr82_Task *task = NULL; if (NULL == session || BT_ADP_JSR82_STATE_IDLE == session->conn_state) { return FALSE; } if (session->pending_task_num == 0xFF) { OS_Report("[JSR82] task list is full"); return FALSE; } task = (BT_Jsr82_Task *)malloc (sizeof(BT_Jsr82_Task)); if (NULL == task) { return FALSE; } memset(task, 0x0, sizeof(BT_Jsr82_Task)); task->code = code; task->context = context; session_mutex_lock(session->mutex); InitializeListEntry(&task->node); InsertTailList(&session->pending_task, &task->node); session->pending_task_num ++; session_mutex_unlock(session->mutex); return TRUE; }
void BT_Gatt_HandleConnected(BtRemoteDevice *link) { U8 i=0; for(i=0; i< MAX_GATT_CON_NO; i++) { if ((GATTC(conn)[i].state == GATT_CONN_STATE_CONNECTED) && (GATTC(conn)[i].link == link)) { return; } } for(i=0; i< MAX_GATT_CON_NO; i++) { if (GATTC(conn)[i].state == GATT_CONN_STATE_IDLE) { OS_MemSet( (U8 *)&GATTC(conn)[i], 0, sizeof(GATTC(conn)[i]) ); GATTC(conn)[i].state = GATT_CONN_STATE_CONNECTED; GATTC(conn)[i].link = link; InitializeListEntry(&GATTC(conn)[i].mtuOp.op.node); InitializeListHead(&GATTC(conn)[i].gattRequestOpList); InitializeListHead(&GATTC(conn)[i].gattNotificationOpList); InitializeListHead(&GATTC(conn)[i].gattIndicationOpList); if(ME_GetDeviceType(&link->bdAddr) == BT_DEV_TYPE_LE) GATTC(conn)[i].att_mtu = MAX_ATT_RX_MTU_BLE; else GATTC(conn)[i].att_mtu = MAX_ATT_RX_MTU_BREDR; GATTC(conn)[i].mtuOp.op.opType = BOP_NOP; GATTC(conn)[i].disconnectTimerValue = MAX_GATT_DISCONNECT_TIMEOUT_VALUE; BT_Gatt_ResetDisconnectTimer(&GATTC(conn)[i]); return; } } }
/*--------------------------------------------------------------------------- * RemoveEntryList() *--------------------------------------------------------------------------- * * Synopsis: Remove the given entry from the list. * * Return: void * */ void RemoveEntryList(ListEntry* entry) { //Assert(IsListCircular(entry)); entry->Blink->Flink = entry->Flink; entry->Flink->Blink = entry->Blink; //Assert(IsListCircular(entry->Blink)); InitializeListEntry(entry); }
/***************************************************************************** * FUNCTION * PrxAttDB_Registration * DESCRIPTION * * PARAMETERS * void * RETURNS * *****************************************************************************/ U8 PrxAttDB_Registration(void) { BtStatus status; status = IasActivateService(); if(status == BT_STATUS_SUCCESS) { InitializeListEntry(&(IasAlertLevelHandle.node)); IasAlertLevelHandle.callback = ProximityImmAlertLevel; IasRegisterAttdbCallback(ATT_HANDLE_IA_CHARACTERISTIC_ALERT_LEVEL_VALUE, &(IasAlertLevelHandle)); } status = TpsActivateService(); if(status == BT_STATUS_SUCCESS) { InitializeListEntry(&(TpsTxPowerDatabaseHandle.node)); TpsTxPowerDatabaseHandle.callback = BtPrxLocalTxPowerDatabase; TpsRegisterAttdbCallback(ATT_HANDLE_TP_CHARACTERISTIC_TX_POWER_LEVEL_VALUE, &(TpsTxPowerDatabaseHandle)); } status = LlsActivateService(); if(status == BT_STATUS_SUCCESS) { Report(("Return status 1")); InitializeListEntry(&(LlsLinkLostAlertHandle.node)); Report(("Return status 2")); LlsLinkLostAlertHandle.callback = ProximityLinkLossAlert; Report(("Return status 3")); LlsRegisterAttdbCallback(ATT_HANDLE_LL_CHARACTERISTIC_ALERT_LEVEL_VALUE, &(LlsLinkLostAlertHandle)); Report(("Return status 4")); } Report(("Return status:%d",status)); return (U8)status; }
void L2capTesterSetSecurity(U8 level) { #ifdef __BT_2_1_SIMPLE_PAIRING__ BtStatus status; if (IsListEmpty(&(L2CAPTS(secRecord).node))) { Report(("L2cap tester list empty")); InitializeListEntry(&(L2CAPTS(secRecord).node)); } else { Report(("L2cap tester list not empty")); SEC_Unregister(&L2CAPTS(secRecord)); InitializeListEntry(&(L2CAPTS(secRecord).node)); } L2CAPTS(secRecord).id = SEC_L2CAP_ID; L2CAPTS(secRecord).channel = BT_PSM_TESTING; L2CAPTS(secRecord).level = BSL_AUTHENTICATION_IN | BSL_AUTHENTICATION_OUT; switch(level) { case BT_SEC_MED: L2CAPTS(secRecord).level_type = BT_SEC_MED; break; case BT_SEC_HIGH: L2CAPTS(secRecord).level_type = BT_SEC_HIGH; break; case BT_SEC_LOW: L2CAPTS(secRecord).level_type = BT_SEC_LOW; break; } status = SEC_RegisterRecord(&L2CAPTS(secRecord)); Report(("SEC_RegisterRecord Status:%02x",status)); #endif }
static BtStatus _time_gatt_notify_value(TimePacket *pkt, U16 value_handle, U16 size, U8 *data) { BtGattOp *gatt_op = &pkt->gatt_op; TimeSTransport *pChnl = (TimeSTransport *) pkt->chnl; btmtk_os_memset((U8 *) gatt_op, 0, sizeof(gatt_op)); InitializeListEntry(&gatt_op->op.node); gatt_op->apCb = time_gatt_notify_value_callback; pkt->success_flag = 0; pkt->gatt_params.vno.handle = value_handle; pkt->gatt_params.vno.size = size; pkt->gatt_params.vno.data = data; gatt_op->parms.p.valueNotifications = &pkt->gatt_params.vno; return BT_GATT_Notifications(pChnl->handler.bdc->link, gatt_op); }
static BtStatus _time_gatt_read_characteristic_descriptor(TimePacket *pkt, U16 desc_handle) { BtGattOp *gatt_op = &pkt->gatt_op; TimeCTransport *pChnl = (TimeCTransport *) pkt->chnl; OS_Report("[Time] %s(), handle: %d", __FUNCTION__, desc_handle); btmtk_os_memset((U8 *) gatt_op, 0, sizeof(BtGattOp)); InitializeListEntry(&gatt_op->op.node); gatt_op->apCb = time_gatt_ap_callback; pkt->success_flag = 0; pkt->gatt_params.rds.handle = desc_handle; gatt_op->parms.p.readCharDescriptors = &pkt->gatt_params.rds; return BT_GATT_ReadCharacteristicDescriptors(pChnl->handler.remDev, gatt_op); }
static BtStatus _time_gatt_discovery_characteristic_descriptors( TimePacket *pkt, U16 start, U16 end) { BtGattOp *gatt_op = &pkt->gatt_op; TimeCTransport *pChnl = (TimeCTransport *) pkt->chnl; OS_Report("[Time] %s(), handle range: %d to %d", __FUNCTION__, start, end); btmtk_os_memset((U8 *) gatt_op, 0, sizeof(BtGattOp)); InitializeListEntry(&gatt_op->op.node); gatt_op->apCb = time_gatt_ap_callback; pkt->success_flag = 0; pkt->gatt_params.dds.startHandle = start; pkt->gatt_params.dds.endHandle = end; gatt_op->parms.p.allCharDescriptors= &pkt->gatt_params.dds; return BT_GATT_DiscoveryAllCharacteristicDescriptors(pChnl->handler.remDev, gatt_op); }
BtStatus _time_gatt_write_without_response(TimePacket *pkt, U16 char_handle) { BtGattOp *gatt_op = &pkt->gatt_op; TimeCTransport *pChnl = (TimeCTransport *) pkt->chnl; U8 value = (U8) pkt->value; OS_Report("[Time] %s(), handle: %d", __FUNCTION__, char_handle); btmtk_os_memset((U8 *) gatt_op, 0, sizeof(BtGattOp)); InitializeListEntry(&gatt_op->op.node); gatt_op->apCb = time_gatt_ap_callback; pkt->success_flag = 0; pkt->gatt_params.wch_wo_rsp.handle = char_handle; pkt->gatt_params.wch_wo_rsp.size = 1; pkt->gatt_params.wch_wo_rsp.data = &value; gatt_op->parms.p.writeWithoutResponse = &pkt->gatt_params.wch_wo_rsp; return BT_GATT_WriteWithoutResponse(pChnl->handler.remDev, gatt_op); }
static BtStatus _time_gatt_discovery_characteristic_by_uuid( TimePacket *pkt, U16 uuid, U16 start, U16 end) { BtGattOp *gatt_op = &pkt->gatt_op; TimeCTransport *pChnl = (TimeCTransport *) pkt->chnl; OS_Report("[Time] %s(), uuid: %x, handle range: %d to %d", __FUNCTION__, uuid, start, end); btmtk_os_memset((U8 *) gatt_op, 0, sizeof(BtGattOp)); InitializeListEntry(&gatt_op->op.node); gatt_op->apCb = time_gatt_ap_callback; pkt->success_flag = 0; pkt->gatt_params.dch_uuid.startHandle = start; pkt->gatt_params.dch_uuid.endHandle = end; pkt->gatt_params.dch_uuid.type = 0x02; pkt->gatt_params.dch_uuid.uuid16[0] = uuid & 0xff; pkt->gatt_params.dch_uuid.uuid16[1] = uuid >> 8; gatt_op->parms.p.charByUUID = &pkt->gatt_params.dch_uuid; return BT_GATT_DiscoveryCharacteristicByUUID(pChnl->handler.remDev, gatt_op); }
void GATT_HandleOperationLinkDisconnected(BtRemoteDevice *link) { BtGattConn *conn; conn = BT_Gatt_GetConCtx(link); if(conn->gattRequestCurOp !=0) { conn->gattRequestHandler(3, link); conn->gattRequestHandler = 0; conn->gattRequestCurOp = 0; } while(!IsListEmpty(&conn->gattRequestOpList)) { conn->gattRequestCurOp = (BtOperation*) RemoveHeadList(&conn->gattRequestOpList); InitializeListEntry(&(conn->gattRequestCurOp->node)); switch (conn->gattRequestCurOp->opType) { case BT_GATT_OPERATOR_EXCHANGE_MTU: conn->gattRequestHandler = GattHandleExchangeMTUOp; break; case BT_GATT_OPERATOR_DISCOVERY_ALL_PRIMARY_SERVICE: conn->gattRequestHandler = GattHandleDiscoveryAllPrimaryServiceOp; break; case BT_GATT_OPERATOR_DISCOVERY_PRIMARY_SERVICE_BY_UUID: conn->gattRequestHandler = GattHandleDiscoveryPrimaryServiceByUUIDOp; break; case BT_GATT_OPERATOR_FIND_INCLUDE_SERVICE: conn->gattRequestHandler = GattHandleFindIncludeServiceOp; break; case BT_GATT_OPERATOR_DISCOVERY_ALL_CHAR_OF_SERVICE: conn->gattRequestHandler = GattHandleDiscoveryAllCharOfServiceOp; break; case BT_GATT_OPERATOR_DISCOVERY_CHAR_BY_UUID: conn->gattRequestHandler = GattHandleDiscoveryCharByUUIDOp; break; case BT_GATT_OPERATOR_DISCOVERY_ALL_CHAR_DESCRIPTOR: conn->gattRequestHandler = GattHandleDiscoveryAllCharDescriptorOp; break; case BT_GATT_OPERATOR_READ_CHAR_VALUE: conn->gattRequestHandler = GattHandleReadCharValueOp; break; case BT_GATT_OPERATOR_READ_USING_CHAR_UUID: conn->gattRequestHandler = GattHandleReadUsingCharUUIDOp; break; case BT_GATT_OPERATOR_READ_LONG_CHAR_VALUE: conn->gattRequestHandler = GattHandleReadLongCharValueOp; break; case BT_GATT_OPERATOR_READ_MULTIPLE_CHAR_VALUE: conn->gattRequestHandler = GattHandleReadMultipleCharValueOp; break; case BT_GATT_OPERATOR_WRITE_CHAR_VALUE: conn->gattRequestHandler = GattHandleWriteCharValueOp; break; case BT_GATT_OPERATOR_WRITE_LONG_CHAR_VALUE: conn->gattRequestHandler = GattHandleWriteLongCharValueOp; break; case BT_GATT_OPERATOR_RELIABLEWRITES: conn->gattRequestHandler = GattHandleReliableWriteOp; break; case BT_GATT_OPERATOR_READ_CHAR_DESCRIPTORS: conn->gattRequestHandler = GattHandleReadCharDescriptorOp; break; case BT_GATT_OPERATOR_READ_LONG_CHAR_DESCRIPTORS: conn->gattRequestHandler = GattHandleReadLongCharDescriptorOp; break; case BT_GATT_OPERATOR_WRITE_CHAR_DESCRIPTORS: conn->gattRequestHandler = GattHandleWriteCharDescriptorOp; break; case BT_GATT_OPERATOR_WRITE_LONG_CHAR_DESCRIPTORS: conn->gattRequestHandler = GattHandleWriteLongCharDescriptorOp; break; } conn->gattRequestHandler(BT_GATT_OP_LINK_DISCONNECTED, link); } if(conn->gattNotificationCurOp !=0) { conn->gattNotificationHandler(3, link); conn->gattNotificationHandler = 0; conn->gattNotificationCurOp = 0; } while(!IsListEmpty(&conn->gattNotificationOpList)) { conn->gattNotificationCurOp = (BtOperation*) RemoveHeadList(&conn->gattNotificationOpList); InitializeListEntry(&(conn->gattNotificationCurOp->node)); switch (conn->gattNotificationCurOp->opType) { case BT_GATT_OPERATOR_NOTIFICATIONS: conn->gattNotificationHandler = GattHandleNotificationOp; break; case BT_GATT_OPERATOR_WRITE_WITHOUT_RESPONSE: conn->gattNotificationHandler = GattHandleWriteWithoutResponseOp; break; case BT_GATT_OPERATOR_SIGNED_WRITE_WITHOUT_RESPONSE: conn->gattNotificationHandler = GattHandleSignedWriteWithoutResponseOp; break; } conn->gattNotificationHandler(BT_GATT_OP_LINK_DISCONNECTED, link); } if(conn->gattIndicationCurOp !=0) { conn->gattIndicationHandler(3, link); conn->gattIndicationHandler = 0; conn->gattIndicationCurOp = 0; } while(!IsListEmpty(&conn->gattIndicationOpList)) { conn->gattIndicationCurOp = (BtOperation*) RemoveHeadList(&conn->gattIndicationOpList); InitializeListEntry(&(conn->gattIndicationCurOp->node)); switch (conn->gattIndicationCurOp->opType) { case BT_GATT_OPERATOR_INDICATIONS: conn->gattIndicationHandler = GattHandleIndicationsOp; break; } conn->gattIndicationHandler(BT_GATT_OP_LINK_DISCONNECTED, link); } }
void GATT_HandleOperation(BtRemoteDevice *link) { BtGattConn *conn; #if 0 // QDAY: remove this for testing if(link->authState != BAS_AUTHENTICATED) { Report(("ATT link wait for authentication")); AttStartAuthentication(link); return; } #endif conn = BT_Gatt_GetConCtx(link); BT_Gatt_ResetDisconnectTimer(conn); OS_Report("GATT_HandleOperation(): gattRequestCurOp=0x%x", conn->gattRequestCurOp); if (conn->gattRequestCurOp) OS_Report("GATT_HandleOperation(): old 0x%x", conn->gattRequestCurOp->opType); if ((conn->gattRequestCurOp == 0) && (!IsListEmpty(&conn->gattRequestOpList))) { conn->gattRequestCurOp = (BtOperation*) RemoveHeadList(&conn->gattRequestOpList); InitializeListEntry(&(conn->gattRequestCurOp->node)); OS_Report("GATT_HandleOperation(): 0x%x", conn->gattRequestCurOp->opType); switch (conn->gattRequestCurOp->opType) { case BT_GATT_OPERATOR_EXCHANGE_MTU: conn->gattRequestHandler = GattHandleExchangeMTUOp; break; case BT_GATT_OPERATOR_DISCOVERY_ALL_PRIMARY_SERVICE: conn->gattRequestHandler = GattHandleDiscoveryAllPrimaryServiceOp; break; case BT_GATT_OPERATOR_DISCOVERY_PRIMARY_SERVICE_BY_UUID: conn->gattRequestHandler = GattHandleDiscoveryPrimaryServiceByUUIDOp; break; case BT_GATT_OPERATOR_FIND_INCLUDE_SERVICE: conn->gattRequestHandler = GattHandleFindIncludeServiceOp; break; case BT_GATT_OPERATOR_DISCOVERY_ALL_CHAR_OF_SERVICE: conn->gattRequestHandler = GattHandleDiscoveryAllCharOfServiceOp; break; case BT_GATT_OPERATOR_DISCOVERY_CHAR_BY_UUID: conn->gattRequestHandler = GattHandleDiscoveryCharByUUIDOp; break; case BT_GATT_OPERATOR_DISCOVERY_ALL_CHAR_DESCRIPTOR: conn->gattRequestHandler = GattHandleDiscoveryAllCharDescriptorOp; break; case BT_GATT_OPERATOR_READ_CHAR_VALUE: conn->gattRequestHandler = GattHandleReadCharValueOp; break; case BT_GATT_OPERATOR_READ_USING_CHAR_UUID: conn->gattRequestHandler = GattHandleReadUsingCharUUIDOp; break; case BT_GATT_OPERATOR_READ_LONG_CHAR_VALUE: conn->gattRequestHandler = GattHandleReadLongCharValueOp; break; case BT_GATT_OPERATOR_READ_MULTIPLE_CHAR_VALUE: conn->gattRequestHandler = GattHandleReadMultipleCharValueOp; break; case BT_GATT_OPERATOR_WRITE_CHAR_VALUE: conn->gattRequestHandler = GattHandleWriteCharValueOp; break; case BT_GATT_OPERATOR_WRITE_LONG_CHAR_VALUE: conn->gattRequestHandler = GattHandleWriteLongCharValueOp; break; case BT_GATT_OPERATOR_RELIABLEWRITES: conn->gattRequestHandler = GattHandleReliableWriteOp; break; case BT_GATT_OPERATOR_EXEC_WRITES: conn->gattRequestHandler = GattHandleExecWriteOp; break; case BT_GATT_OPERATOR_READ_CHAR_DESCRIPTORS: conn->gattRequestHandler = GattHandleReadCharDescriptorOp; break; case BT_GATT_OPERATOR_READ_LONG_CHAR_DESCRIPTORS: conn->gattRequestHandler = GattHandleReadLongCharDescriptorOp; break; case BT_GATT_OPERATOR_WRITE_CHAR_DESCRIPTORS: conn->gattRequestHandler = GattHandleWriteCharDescriptorOp; break; case BT_GATT_OPERATOR_WRITE_LONG_CHAR_DESCRIPTORS: conn->gattRequestHandler = GattHandleWriteLongCharDescriptorOp; break; case BT_GATT_OPERATOR_READ_BY_TYPE: conn->gattRequestHandler = GattHandleReadByTypeOp; break; } conn->gattRequestHandler(BT_GATT_OP_START, link); } if ((conn->gattNotificationCurOp == 0) && (!IsListEmpty(&conn->gattNotificationOpList))) { conn->gattNotificationCurOp = (BtOperation*) RemoveHeadList(&conn->gattNotificationOpList); InitializeListEntry(&(conn->gattNotificationCurOp->node)); switch (conn->gattNotificationCurOp->opType) { case BT_GATT_OPERATOR_NOTIFICATIONS: conn->gattNotificationHandler = GattHandleNotificationOp; break; case BT_GATT_OPERATOR_WRITE_WITHOUT_RESPONSE: conn->gattNotificationHandler = GattHandleWriteWithoutResponseOp; break; case BT_GATT_OPERATOR_SIGNED_WRITE_WITHOUT_RESPONSE: conn->gattNotificationHandler = GattHandleSignedWriteWithoutResponseOp; break; } conn->gattNotificationHandler(BT_GATT_OP_START, link); } if ((conn->gattIndicationCurOp == 0) && (!IsListEmpty(&conn->gattIndicationOpList))) { conn->gattIndicationCurOp = (BtOperation*) RemoveHeadList(&conn->gattIndicationOpList); InitializeListEntry(&(conn->gattIndicationCurOp->node)); switch (conn->gattIndicationCurOp->opType) { case BT_GATT_OPERATOR_INDICATIONS: conn->gattIndicationHandler = GattHandleIndicationsOp; break; } conn->gattIndicationHandler(BT_GATT_OP_START, link); } }