示例#1
0
/*---------------------------------------------------------------------------
 * USBTRAN_BufferAvailable() 
 *
 */
static void USBTRAN_BufferAvailable(HciBufFlags buffFlag)
{
    switch (buffFlag & 0x0E) {
    case HCI_BUFTYPE_EVENT:
        /* Point to our state context */
        if (USTRAN(rxContext[EVENT_STATE].state) == USB_RXS_GET_BUFFER) {
            /* We needed a buffer, one is now free */
            bt_trace(TRACE_GROUP_1,USBTRAN_EVENT_BUFFER_NOW_AVAILABLE);
            notifyEvent();
        }
        break;
    case HCI_BUFTYPE_ACL_DATA:
        /* Point to our state context */
        if (USTRAN(rxContext[ACL_STATE]).state == USB_RXS_GET_BUFFER) {
            /* We needed a buffer, one is now free */
            bt_trace(TRACE_GROUP_1,USBTRAN_ACL_BUFFER_NOW_AVAILABLE);
            notifyReadAcl();
        }
        break;
#if (BT_SCO_HCI_DATA == XA_ENABLED) && (NUM_SCO_CONNS > 0)
    case HCI_BUFTYPE_SCO_DATA:
        /* Point to our state context */
        if (USTRAN(rxContext[SCO_STATE]).state == USB_RXS_GET_BUFFER) {
            /* We needed a buffer, one is now free */
            bt_trace(TRACE_GROUP_1,USBTRAN_SCO_BUFFER_NOW_AVAILABLE);
            notifyReadSco();
        }
        break;
#endif
    }
}
示例#2
0
/*****************************************************************************
 * FUNCTION
 *  ME_RemoveEIRServiceClass
 * DESCRIPTION
 *  
 * PARAMETERS
 *  service_class       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void ME_RemoveEIRServiceClass(U16 service_class)
{
    U8 index;

    bt_trace(TRACE_GROUP_1, BTLOG_EIR_REGISTRATION_SDP_FOR_UPPER_LAYER_SERVICE_CLASSx04X, service_class);
    for (index = 0; index < MAX_EIR_SDP_SIZE; index++)
    {
        if (MEC(eirSdpCtx)[index].used != 0)
        {
            if (MEC(eirSdpCtx)[index].service_class == service_class)
            {
                bt_trace(
                    TRACE_GROUP_1,
                    BTLOG_RECORD_INDEXx0D_SERVICE_CLASSx04X,
                    index,
                    MEC(eirSdpCtx)[index].service_class);
                if(MEC(eirSdpCtx)[index].counter == 0)
                {
                    Assert(0);
                }
                MEC(eirSdpCtx)[index].counter--;
                if (MEC(eirSdpCtx)[index].counter == 0)
                {
                    MEC(eirSdpCtx)[index].service_class = 0;
                    MEC(eirSdpCtx)[index].used = 0;
                    MEC(eirRecordUpdated) = 1;
                }
                break;
            }
        }
    }
    ME_StartWriteEIR();

}
示例#3
0
void l2capTesterInit(void)
{
    if(L2CAPTS(testing_enabled) == TRUE)
    {
        Report(("L2CAP already init"));
        return;
    }
    bt_trace(BT_TRACE_G1_PROTOCOL, BT_L2CAPTS_INIT);
    L2CAPTS(Protocol).callback = l2capTesterL2Callback;
    L2CAPTS(Protocol).psm = BT_PSM_TESTING;
    L2CAPTS(Protocol).localMtu = (L2CAP_MTU - 5);
    L2CAPTS(Protocol).minRemoteMtu = 23 + 5;
    L2CAPTS(Protocol).authorizedSetting = FALSE;    
#if L2CAP_FLOW_NON_BASIC_MODE == XA_ENABLED
    L2CAPTS(Protocol).inLinkMode = L2CAPTS(Protocol).outLinkMode = L2MODE_BASIC;
#endif /* L2CAP_FLOW_NON_BASIC_MODE == XA_ENABLED */
    L2CAPTS(testing_enabled) = TRUE;
    if (L2CAP_RegisterPsm(&(L2CAPTS(Protocol))) != BT_STATUS_SUCCESS) {
        /* Unable to register */
        bt_trace(BT_TRACE_G1_PROTOCOL, BT_L2CAPTS_UNABLEREG);
    }

#if L2CAP_NUM_GROUPS > 0
    L2CAPTS(tsgroup).psm = BT_PSM_TCS_CORDLESS;
    L2CAPTS(tsgroup).callback = L2Group_Event;
    L2CAPTS(tsgroup).maxMembers = 2;
    L2CAP_RegisterGroup(&L2CAPTS(tsgroup), &L2CAPTS(groupId));
#endif
}
示例#4
0
/*****************************************************************************
 * FUNCTION
 *  AvctpMsgHandleCommand
 * DESCRIPTION
 *  Handle a command.
 * PARAMETERS
 *  chnl        [IN]        
 *  parms       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void AvctpMsgHandleCommand(AvctpChannel *chnl, AvcCallbackParms *parms)
{
    AvctpCallbackParms info;
    kal_trace( BT_TRACE_G8_AVRCP, BT_AVCTP_MSG_HANDLE_COMMAND, parms->pktType, parms->rxId);

    if (parms->rxId != SC_AV_REMOTE_CONTROL)
    {
        bt_trace(TRACE_GROUP_1, AVCTP_INVALID_PROFILE_ID);
        chnl->rspPacket.msgType = AVC_MSG_TYPE_REJECT;
        chnl->rspPacket.txId = parms->rxId;
        chnl->rspPacket.txIdSize = 2;
        chnl->rspPacket.txData = 0;
        chnl->rspPacket.txDataLen = 0;
        chnl->rspPacket.useMsgHdr = FALSE;
        /*
         * There's no frame to send along; completion of this message
         * should not be indicated back to the app
         */
        chnl->curFrame = 0;
        chnl->rxState = AVCTP_MSG_RXSTATE_IGNORE;
        AssertEval(AVC_SendStart(&chnl->avcChnl, &chnl->rspPacket) == BT_STATUS_PENDING);
        return;
    }

    if (parms->pktType == AVC_PACKET_TYPE_START || parms->pktType == AVC_PACKET_TYPE_SINGLE)
    {

        if ( BT_PSM_AVCTP== chnl->channelType && parms->len < 3) // AV13 channeltype is AVCTP psm
        {
            bt_trace(TRACE_GROUP_1, AVCTP_MISSING_PARAMETERS_DISCONNECTING);
            (void)AvctpDisconnect(&chnl->conn);
            return;
        }

        if( BT_PSM_AVCTP_BROWSING != chnl->channelType ){ 
            // Parse the av/c header
            /* Move channel state into COMMAND-processing */
            chnl->state = AVCTP_CHAN_STATE_COMMAND;

            /* Decode parameters buffer AV/C header */
            chnl->rx.cmdFrame.ctype = parms->data[0] & 0x0f;
            chnl->rx.cmdFrame.subunitType = parms->data[1] >> 3;
            chnl->rx.cmdFrame.subunitId = parms->data[1] & 0x07;
            chnl->rx.cmdFrame.opcode = parms->data[2];
            
            chnl->rx.cmdFrame.operands = parms->data + 3;
            chnl->rx.cmdFrame.operandLen = parms->len - 3;
            chnl->rx.cmdFrame.more = (parms->pktType == AVC_PACKET_TYPE_START);
            chnl->rx.cmdFrame.transId = parms->transid;
            
#ifdef __AVCTP_TESTER_
            chnl->rxRawData = parms->data;
            chnl->rxRawLength = parms->len;
            chnl->rxRawType = parms->pktType;
#endif /* __AVCTP_TESTER_ */ 
        }else{
示例#5
0
/*****************************************************************************
 * FUNCTION
 *  SM_SendPairRsp
 * DESCRIPTION
 *  Send SMP pairing response
 * PARAMETERS
 *  remDev         [IN]
 *  presData       [OUT]
 *  ioCapability   [IN]
 *  oobFlag        [IN]
 *  bondFlag       [IN]
 *  MITMProtect    [IN]
 *  maxKeySize     [IN]
 *  iKeyDist       [IN]
 *  rKeyDist       [IN]
 * RETURNS
 *  BtStatus
 *****************************************************************************/
BtStatus SM_SendPairRsp(BtRemoteDevice *remDev,
                        U8 *presData,
                        SmIOCapability ioCapability, 
                        SmOOBFlag oobFlag, 
                        SmBondingFlag bondFlag, 
                        BOOL MITMProtect, 
                        U8 maxKeySize,
                        SmKeyDistribute iKeyDist,
                        SmKeyDistribute rKeyDist)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();
    
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENDPAIRRSP, ioCapability, oobFlag, bondFlag, MITMProtect, maxKeySize, iKeyDist, rKeyDist);
    Assert(remDev != NULL);
    Assert(presData != NULL);
    packet->data[i++] = SMC_PAIR_RSP;
    packet->data[i++] = ioCapability;
    packet->data[i++] = oobFlag;
    packet->data[i++] = (MITMProtect == TRUE) ? ((1 << 2) | bondFlag) : bondFlag;
    packet->data[i++] = maxKeySize;
    packet->data[i++] = iKeyDist;
    packet->data[i++] = rKeyDist;
    packet->dataLen = i;
    if (presData)
    {
        OS_MemCopy(presData, packet->data, 7);
        bt_parm_trace(7, presData);
    }

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#6
0
BtStatus SM_CalcPairConfirm(BtRemoteDevice *remDev, U8 *tk, U8 *rand, U8 *preq, U8 *pres, LeAddrType iat, LeAddrType rat, BD_ADDR ia, BD_ADDR ra)
{
    U8 p1[16] = {0};
    U8 iat1 = iat & 0x01;
    U8 rat1 = rat & 0x01;

    Assert (smpCntx.smConfirmOps.remDev == NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_CALCPAIRCONFIRM, iat, rat);
    bt_parm_trace(16, tk);
    bt_parm_trace(16, rand);
    bt_parm_trace(7, preq);
    bt_parm_trace(7, pres);
    BTBMDumpBdAddr(ia.addr);
    BTBMDumpBdAddr(ra.addr);

    smpCntx.smConfirmOps.remDev = remDev;
    smpCntx.smConfirmOps.encryptCount = 0;


    OS_MemCopy(smpCntx.smConfirmOps.k, tk, 16);
    /* p2 = (MSB)padding || ia || ra */
    OS_MemCopy((U8 *)&smpCntx.smConfirmOps.p2, ra.addr, 6);
    OS_MemCopy(&smpCntx.smConfirmOps.p2[6], ia.addr, 6);

    /* p1 = (MSB)pres || preq || rat1 || iat1 */
    p1[0] = iat1;
    p1[1] = rat1;
    OS_MemCopy(&p1[2], preq, 7);
    OS_MemCopy(&p1[9], pres, 7);

    /* r OXR p1 */
    SM_util_128bit_XOR(p1, p1, rand);
    return LeHciAES128Encrypt(SM_CalcPairConfirm_FSM, tk, p1);
}
示例#7
0
static void SM_CalcPairConfirm_FSM(const BtEvent *event)
{
    BtEvent newEvent;
    bt_trace(TRACE_FUNC, BT_SMP_SM_CALCPAIRCONFIRMFSM, smpCntx.smConfirmOps.encryptCount, event->errCode);
    switch (smpCntx.smConfirmOps.encryptCount)
    {
    case 0:
        if (event->errCode == HC_STATUS_SUCCESS)
        {
            smpCntx.smConfirmOps.encryptCount++;
            SM_util_128bit_XOR(smpCntx.smConfirmOps.p2, smpCntx.smConfirmOps.p2, (U8 *)event->p.smEncryptResponse.EncryptData);
            LeHciAES128Encrypt(SM_CalcPairConfirm_FSM, smpCntx.smConfirmOps.k, smpCntx.smConfirmOps.p2);
            break;
        }
        /* fall-through */
    case 1:
        newEvent.errCode = event->errCode;
        newEvent.eType = BTEVENT_LE_SM_RESULT;
        newEvent.p.smConfirmResponse.remDev = smpCntx.smConfirmOps.remDev;
        OS_MemCopy(newEvent.p.smConfirmResponse.ConfirmValue, event->p.smEncryptResponse.EncryptData, SM_CONFIRM_VALUE_LENGTH);
        SM_LinkCallback(smpCntx.smConfirmOps.remDev, &newEvent);
        OS_MemSet((U8 *)&smpCntx.smConfirmOps, 0x00, sizeof(sm_confirm_op));
        break;
    }
}
示例#8
0
/*****************************************************************************
 * FUNCTION
 *  TimerFired
 * DESCRIPTION
 *  Called by the OS layer to indicate that the system timer fired.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void TimerFired(void)
{
    /* The EVM_Process thread looks for specific expired timers */
    bt_trace(BT_TRACE_G1_PROTOCOL, BTLOG_BTTIMEOUT_TIMERFIRED);
    OS_ResetTimerId();
    OS_NotifyEvm();
}
示例#9
0
U8 L2CA_DisconnectReq(L2capDisconnectRequest *parms)
{
    BtStatus status = BT_STATUS_SUCCESS;
    
    bt_trace(BT_TRACE_G1_PROTOCOL, BT_L2CAPTS_DISCONNECTREQ);
    status = L2CAP_DisconnectReq(parms->cid);
    return status;
}
示例#10
0
/*---------------------------------------------------------------------------
 * USBTRAN_Shutdown() 
 *      
 * Requires:
 *     
 * Parameters:
 *    
 * Returns:
 */
BtStatus USBTRAN_Shutdown(void)
{
    bt_trace(TRACE_GROUP_1,TRANS_SHUTDOWN);

    //USB_Deinit();

    return BT_STATUS_SUCCESS;
} /* USBTRAN_Shutdown() */
示例#11
0
BtStatus SM_Rand(BtRemoteDevice *remDev, U8 len)
{
    bt_trace(TRACE_FUNC, BT_SMP_SM_RAND, len);
    Assert(smpCntx.smRandOps.remDev == NULL);
    smpCntx.smRandOps.remDev = remDev;
    smpCntx.smRandOps.randLen = len;
    smpCntx.smRandOps.randCount = 0;
    return LeHciRand(SM_Rand_FSM);
}
示例#12
0
// add by stanley : 2006-0719
void L2CA_TesterDisconnect(U8 cid)
{
    L2capDisconnectRequest parms;
    if(cid == 0x00)
        parms.cid = L2CAPTS(cid);
    else
        parms.cid = cid;
    bt_trace(TRACE_GROUP_1,L2CAP_TESTER_DISCONN_REQ);
    L2CA_DisconnectReq(&parms);
}
示例#13
0
void L2CA_GroupDataReq(void)
{
    bt_trace(TRACE_GROUP_1,L2CAP_GROUP_DATA_REQUEST);
    L2CAPTS(btp).flags = BTP_FLAG_INUSE;
    L2CAPTS(btp).headerLen = 0;
    memset( (U8 *)L2CAPTS(common_data), 0x55, 10);
    L2CAPTS(btp).data = (U8 *)L2CAPTS(common_data);
    L2CAPTS(btp).dataLen = 10;
    L2CAPTS(btp).priority_type = BTP_FLAG_LOW_PRIPORTY ;    
    L2CAP_SendData(L2CAPTS(groupId), &L2CAPTS(btp));
}
示例#14
0
void AtDebugOut(XaBufferDesc *Input)
{
    const U8 *buffer, *p;
    U16       len;
    U16       po;

    p = buffer = Input->buff + Input->readOffset;
    len = Input->writeOffset - Input->readOffset;

    po = 0;
    while (p < buffer+len) {

        /* Dumps the data in basic ASCII dump format */
        po = 0;
        while (po < LINE_WIDTH) {
            if (p+po < buffer+len)
            {
                bt_trace(TRACE_GROUP_1,BTBT_DEBUGx02X , p[po]);
            }
            else ;
            if (++po == LINE_WIDTH/2) ;
        }
        ;

        po = 0;
        while (po < LINE_WIDTH) {
            if (p+po < buffer+len)
            {
                bt_trace(TRACE_GROUP_1,x1C , ((p[po] >= ' ' && p[po] <= '~') ? p[po] : '.'));
            }
            else break;
            po++;
        }

        ;
        p += po;
    }
}
示例#15
0
BtStatus SM_SendSecurityReq(BtRemoteDevice *remDev, SmBondingFlag bondFlag, BOOL MITMProtect)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();

    Assert(remDev != NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENDSECURITYREQ, bondFlag, MITMProtect);
    packet->data[i++] = SMC_SECURITY_REQ;
    packet->data[i++] = (MITMProtect == TRUE) ? ((1 << 2) | bondFlag) : bondFlag;
    packet->dataLen = i;

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#16
0
/*****************************************************************************
 * FUNCTION
 *  SM_SendPairFailed
 * DESCRIPTION
 *  Send SMP pairing failed response
 * PARAMETERS
 *  remDev         [IN]
 *  reason         [IN]
 * RETURNS
 *  BtStatus
 *****************************************************************************/
BtStatus SM_SendPairFailed(BtRemoteDevice *remDev, SmPairFailReason reason)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();

    Assert(remDev != NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENDPAIRFAILED, reason);

    packet->data[i++] = SMC_PAIR_FAILED;
    packet->data[i++] = reason;
    packet->dataLen = i;

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#17
0
U8 L2capSendData(void)
{
    BtStatus status;
    
    bt_trace(BT_TRACE_G1_PROTOCOL, BT_L2CAPTS_SENDDATAREQ);
    L2CAPTS(btp).flags = BTP_FLAG_INUSE;
    L2CAPTS(btp).headerLen = 0;
    memset( (U8 *)L2CAPTS(common_data), 0x55, sizeof(L2CAPTS(common_data)));
    
    L2CAPTS(btp).data = (U8 *)L2CAPTS(common_data);
    L2CAPTS(btp).dataLen = sizeof(L2CAPTS(common_data));
    L2CAPTS(btp).priority_type = BTP_FLAG_HIGH_PRIPORTY ;    
    status = L2CAP_SendData(L2CAPTS(cid), &L2CAPTS(btp));
    return status;
}
示例#18
0
SmPairModel SM_GetPairModelByIo(SmIOCapability initiator, SmIOCapability responder)
{
    bt_trace(TRACE_FUNC, BT_SMP_SM_GETPAIRMODELBYIO, initiator, responder);
    if (initiator == SM_IO_CAPABILITY_NO_INPUT_NO_OUTPUT || responder == SM_IO_CAPABILITY_NO_INPUT_NO_OUTPUT)
    {
        return SM_MODEL_JUST_WORK;
    }
    else if ((initiator == SM_IO_CAPABILITY_DISPLAY_ONLY || initiator == SM_IO_CAPABILITY_DISPLAY_YESNO) &&
             (responder == SM_IO_CAPABILITY_DISPLAY_ONLY || responder == SM_IO_CAPABILITY_DISPLAY_YESNO))
    {
        return SM_MODEL_JUST_WORK;
    }
    else
    {
        return SM_MODEL_PASSKEY_ENTRY;
    }
}
示例#19
0
/*****************************************************************************
 * FUNCTION
 *  SM_SendPairRandom
 * DESCRIPTION
 *  Send SMP pairing random value
 * PARAMETERS
 *  remDev         [IN]
 *  random         [IN]
 * RETURNS
 *  BtStatus
 *****************************************************************************/
BtStatus SM_SendPairRandom(BtRemoteDevice *remDev, U8 *random)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();

    Assert(remDev != NULL);
    Assert(random != NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENDPAIRRANDOM);
    bt_parm_trace(SM_RANDOM_VALUE_LENGTH, random);

    packet->data[i++] = SMC_PAIR_RANDOM;
    OS_MemCopy(packet->data + 1, random, SM_RANDOM_VALUE_LENGTH);
    packet->dataLen = 1 + SM_RANDOM_VALUE_LENGTH;

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#20
0
BtStatus SM_SendIdentityInfo(BtRemoteDevice *remDev, U8 *irk)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();

    Assert(remDev != NULL);
    Assert(irk != NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENDIDENTITYINFO);
    bt_parm_trace(SM_IRK_VALUE_LENGTH, irk);

    packet->data[i++] = SMC_IDEN_INFO;
    OS_MemCopy(packet->data + 1, irk, SM_IRK_VALUE_LENGTH);
    packet->dataLen = i + SM_IRK_VALUE_LENGTH;

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#21
0
BtStatus SM_SendIdentityAddrInfo(BtRemoteDevice *remDev, LeAddrType addrType, BD_ADDR bdAddr)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();

    Assert(remDev != NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENDIDENTITYADDRINFO, 
             addrType, bdAddr.addr[0], bdAddr.addr[1], bdAddr.addr[2], bdAddr.addr[3], bdAddr.addr[4], bdAddr.addr[5]);

    packet->data[i++] = SMC_IDEN_ADDR_INFO;
    packet->data[i++] = addrType;
    OS_MemCopy(packet->data + i, bdAddr.addr, BD_ADDR_SIZE);
    packet->dataLen = i + BD_ADDR_SIZE;

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#22
0
BtStatus SM_SendSigningInfo(BtRemoteDevice *remDev, U8 *csrk)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();

    Assert(remDev != NULL);
    Assert(csrk != NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENDSIGNINGINFO);
    bt_parm_trace(SM_CSRK_VALUE_LENGTH, csrk);

    packet->data[i++] = SMC_SIGN_INFO;
    OS_MemCopy(packet->data + 1, csrk, SM_CSRK_VALUE_LENGTH);
    packet->dataLen = i + SM_CSRK_VALUE_LENGTH;

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#23
0
U8 meUtilWriteEirBLEServiceList(U8 *buf, U8 bufLen)
{
    U8 offset = 0, recNum = 0, index;
    U8 uuid_list[MAX_EIR_SDP_SIZE * 2], len = 0;
        
    if (bufLen >= 4)
    {
        for (index = 0; index < MAX_EIR_SDP_SIZE; index++)
        {
            if (MEC(eirSdpCtx)[index].used != 0)
            {
                OS_Report("UUID=0x%x",MEC(eirSdpCtx)[index].service_class);
                if(SdpIsBLEService(MEC(eirSdpCtx)[index].service_class))
                {
                    recNum++;
                    StoreLE16(&uuid_list[len], MEC(eirSdpCtx)[index].service_class);
                    len += 2;
                }
            }
        }

        if (recNum)
        {
            if (len + 2 > bufLen)
            {
                /* EIR UUID is not completed */
                len = bufLen - 2;
                recNum = len / 2;
                buf[1] = BT_EIR_SERVICE_CLASS_16UUID_MORE;
            }
            else
            {
                /* EIR UUID is completed */
                buf[1] = BT_EIR_SERVICE_CLASS_16UUID_COMPLETE;
            }
            bt_trace(TRACE_GROUP_1, BTLOG_EIRRECORDNUMxD, recNum);
            buf[0] = len + 1;
            offset += 2;
            OS_MemCopy(buf + offset, uuid_list, len);
            offset += len;
        }
    }
    Assert (offset <= bufLen);
    return offset;
}
示例#24
0
BtStatus SM_CalcSTK(BtRemoteDevice *remDev, U8 *tk, U8 *srand, U8 *mrand)
{
    U8 r[16] = {0};

    Assert (smpCntx.smCalcSTKOps == NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_CALCSTK);
    bt_parm_trace(16, tk);
    bt_parm_trace(8, srand);  /* r1 */
    bt_parm_trace(8, mrand);  /* r2 */

    smpCntx.smCalcSTKOps = remDev;

    /* r = (MSB)r1 || r2 */
    OS_MemCopy(r, mrand, 8);
    OS_MemCopy(&r[8], srand, 8);
    
    return LeHciAES128Encrypt(SM_CalcSTK_FSM, tk, r);
}
示例#25
0
/*****************************************************************************
 * FUNCTION
 *  SM_SendEncryptInfo
 * DESCRIPTION
 *  Send SMP pairing encryption long term key information
 * PARAMETERS
 *  remDev         [IN]
 *  ltk            [IN]
 * RETURNS
 *  BtStatus
 *****************************************************************************/
BtStatus SM_SendEncryptInfo(BtRemoteDevice *remDev, U8 *ltk)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();

    Assert(remDev != NULL);
    Assert(ltk != NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENDENCRYPTINFO);
    bt_parm_trace(SM_LTK_VALUE_LENGTH, ltk);
    Report(("UPF Debug LTK Send to Remote Side"));
    Report(("UPF Debug LTK LSB->MSB:%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x",
        ltk[0],ltk[1],ltk[2],ltk[3],ltk[4],ltk[5],ltk[6],ltk[7]));
    Report(("UPF Debug LTK LSB->MSB:%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x",
        ltk[8],ltk[9],ltk[10],ltk[11],ltk[12],ltk[13],ltk[14],ltk[15]));

    packet->data[i++] = SMC_ENCRYPT_INFO;
    OS_MemCopy(packet->data + 1, ltk, SM_LTK_VALUE_LENGTH);
    packet->dataLen = 1 + SM_LTK_VALUE_LENGTH;

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#26
0
void l2capTesterGroupCmgrCallback(CmgrHandler *cHandler, 
                      CmgrEvent Event, 
                      BtStatus Status)
{
    L2capChannelId l2ChannelId;
    BtStatus status;
    
    switch (Event) 
    {
        case CMEVENT_DATA_LINK_CON_CNF:
            if (Status == BT_STATUS_SUCCESS) 
            {
                bt_trace(TRACE_GROUP_1,ACL_LINK_CREATE_SUCCESSFULLY);
                L2CAP_GroupAddMember(L2CAPTS(groupId), &(cHandler->bdc->link->bdAddr));
            }
            break;
        case CMEVENT_DATA_LINK_DIS:
            L2CAP_GroupRemoveMember(L2CAPTS(groupId), &cHandler->bdc->link->bdAddr);
            cHandler->bdc =0;
            break;
    }
}
示例#27
0
static void SM_Rand_FSM(const BtEvent *event)
{
    BtEvent newEvent;
    bt_trace(TRACE_FUNC, BT_SMP_SM_RANDFSM, smpCntx.smRandOps.randLen, smpCntx.smRandOps.randCount);
    bt_parm_trace(8, (U8 *)event->p.smRand64Response.randValue64);
    if(smpCntx.smRandOps.randLen == 16)
    {
        switch (smpCntx.smRandOps.randCount)
        {
        case 0:
            if (event->errCode == HC_STATUS_SUCCESS)
            {
                smpCntx.smRandOps.randCount++;
                OS_MemCopy((U8 *)smpCntx.smRandOps.tmpRandValue, (U8 *)event->p.smRand64Response.randValue64, SM_RAND_VALUE_LENGTH);
                LeHciRand(SM_Rand_FSM);
                return;
            }
        case 1:
            if (event->errCode == HC_STATUS_SUCCESS)
            {
                U8 tmp[SM_RAND_VALUE_LENGTH];
                OS_MemCopy(tmp, event->p.smRand64Response.randValue64, SM_RAND_VALUE_LENGTH);
                OS_MemCopy(newEvent.p.smRand128Response.randValue128, smpCntx.smRandOps.tmpRandValue, SM_RAND_VALUE_LENGTH);
                OS_MemCopy(newEvent.p.smRand128Response.randValue128 + SM_RAND_VALUE_LENGTH, tmp, SM_RAND_VALUE_LENGTH);
                break;
            }
        }
        newEvent.p.smRand128Response.remDev = smpCntx.smRandOps.remDev;
    }
    else
    {
        newEvent.p.smRand64Response.remDev = smpCntx.smRandOps.remDev;
    }
    newEvent.eType = BTEVENT_LE_SM_RESULT;
    newEvent.errCode = event->errCode;
    SM_LinkCallback(smpCntx.smRandOps.remDev, &newEvent);
    OS_MemSet((U8 *)&smpCntx.smRandOps, 0x00, sizeof(sm_rand_op));
 }
示例#28
0
/*****************************************************************************
 * FUNCTION
 *  SM_SendMasterIdentity
 * DESCRIPTION
 *  Send SMP pairing identity information
 * PARAMETERS
 *  remDev         [IN]
 *  ediv           [IN]
 *  rand           [IN]
 * RETURNS
 *  BtStatus
 *****************************************************************************/
BtStatus SM_SendMasterIdentity(BtRemoteDevice *remDev, U16 ediv, U64 rand)
{
    int i = 0;
    BtPacket *packet = SM_AllocCmdPkt();

    Assert(remDev != NULL);
    bt_trace(TRACE_FUNC, BT_SMP_SM_SENMASTERIDENTITY, ediv, rand);

    packet->data[i++] = SMC_MASTER_IDEN;
    StoreLE16(packet->data + i, ediv);
    i += SM_EDIV_VALUE_LENGTH;

    Report(("UPF Debug ediv Send to Remote Side:%04x", ediv));

    StoreLE64(packet->data + i, rand);
    Report(("UPF Debug rand Send to Remote Side LSB->MSB:%02x,%02x,%02x,02x,%02x,%02x,%02x,%02x",
        packet->data[i],packet->data[i+1], packet->data[i+2],packet->data[i+3],packet->data[i+4],packet->data[i+5],packet->data[i+6],packet->data[i+7]));

    i += SM_RAND_VALUE_LENGTH;
    packet->dataLen = i;

    SM_ResetTimer(remDev);
    return SM_SendL2capData(remDev, packet);
}
示例#29
0
/*---------------------------------------------------------------------------
 * notifyReadAcl() 
 *      Called from lower layer when ACL data is available for reading.
 *      
 * Requires:
 *     
 * Parameters:
 *
 * Returns:
 */
static BOOL notifyReadAcl(void)
{
    UsbRxStateContext  *st;
    U16 cntRead=1, len;
    BtStatus status;
    HciHandle hciConnHandle;

    /* Point to our state context */
    st = &USTRAN(rxContext[ACL_STATE]);

    /* Loop while there is data to be read */
    do {
        if (st->state == USB_RXS_GET_INIT) {
            st->headerLen = 4;

            /* Set up for the next state */
            st->ptr = st->header;
            st->maxReadLen = st->headerLen;
            st->ptr = st->header;
            st->maxReadLen = st->headerLen;
            st->state = USB_RXS_GET_HEADER;
        }

        if (st->state != USB_RXS_GET_BUFFER) {

            /* Read available data */
            cntRead = (U16)USB_ReadBulk(st->ptr, st->maxReadLen);
            Assert(cntRead >= 0);

            st->ptr += cntRead;

            /* See if enough data is available */
            if (cntRead != st->maxReadLen) {
                st->maxReadLen = (U16)(st->maxReadLen - cntRead);
                return TRUE;
            }
        }



        /* All the data for the previous state has been read, now progress
         * to the next state.
         */
        switch (st->state) {
        
        case USB_RXS_GET_HEADER:
            /* Header was read above. Go to next state. */
            st->state = USB_RXS_GET_BUFFER;
            /* drop through to next state */


        case USB_RXS_GET_BUFFER:
            len = (U16)(LEtoHost16(&(st->header[2])) + st->headerLen);
            hciConnHandle = LEtoHost16(&(st->header[0]));
            status = HCI_GetAclBuffer(&st->rxBuffHandle, 
                                      hciConnHandle, len);
            if (status == BT_STATUS_SUCCESS) {
                /* Got an ACL buffer */
                st->ptr = HCI_GetRxPtr(st->rxBuffHandle);
                st->maxReadLen = LEtoHost16(&(st->header[2]));

            } else if (status == BT_STATUS_NO_RESOURCES) {
                /* No receive buffer available */
                bt_trace(TRACE_GROUP_1,TRANS_NO_ACL_BUFFERS);
                return FALSE;
            }
            Assert(status != BT_STATUS_INVALID_PARM);

            OS_MemCopy(st->ptr, st->header, st->headerLen);

            /* Set up for next state */
            st->ptr += st->headerLen;
            st->state = USB_RXS_GET_DATA;
            break;

        case USB_RXS_GET_DATA:
            /* Pass it up */

            HCI_RxBufferInd(st->rxBuffHandle, 
                            BT_STATUS_SUCCESS);

            /* Reset to first state */
            st->state = USB_RXS_GET_INIT;
            break;

        }

    } while (cntRead);

    return TRUE;
}
示例#30
0
/*---------------------------------------------------------------------------
 * notifyEvent() 
 *      Called from lower layer when an Event packet is ready to read.
 *      
 * Requires:
 *     
 * Parameters:
 *
 * Returns:
 */
static BOOL notifyEvent(void)
{
    BtStatus          status;
    UsbRxStateContext    *st;             /* event state */
    U16               cntRead=1, len;

    /* Point to our state context */
    st = &USTRAN(rxContext[EVENT_STATE]);

    do {
        if (st->state == USB_RXS_GET_INIT) {
            st->state = USB_RXS_GET_HEADER;
            st->headerLen = 2;
            st->ptr = st->header;
            st->maxReadLen = st->headerLen;
        }

        if (st->state != USB_RXS_GET_BUFFER) {

            /* Read available data */
            cntRead = (U16)USB_ReadEvent(st->ptr, st->maxReadLen);
            Assert(cntRead >= 0);

            st->ptr += cntRead;

            /* See if enough data is available */
            if (cntRead != st->maxReadLen) {
                st->maxReadLen = (U16)(st->maxReadLen - cntRead);
                return TRUE;
            }
        }

        /* All the data for the previous state has been read, now progress
         * to the next state.
         */
        switch (st->state) {
        
        case USB_RXS_GET_HEADER:
            /* Read header above so move to next state. */
            st->state = USB_RXS_GET_BUFFER;
            /* Drop to thru to next case */

        case USB_RXS_GET_BUFFER:
            if (st->header[1]) {
                /* There are parameters */
                if (0 != (len = (U16)(st->header[1] + st->headerLen))) {
                    status = HCI_GetEventBuffer(&st->rxBuffHandle, len);
                    if (status == BT_STATUS_SUCCESS) {
                        /* Got an Event buffer */
                        st->ptr = HCI_GetRxPtr(st->rxBuffHandle);
                        st->maxReadLen = st->header[1];
                    } else {
                        /* No receive buffer available */
                        bt_trace(TRACE_GROUP_1,TRANS_NO_EVENT_BUFFERS);
                        return FALSE;
                    }
                    Assert(status == BT_STATUS_SUCCESS);
                }
            }

            OS_MemCopy(st->ptr, st->header, st->headerLen);

            /* Set up for next state */
            st->ptr += st->headerLen;
            st->state = USB_RXS_GET_DATA;
            break;

        case USB_RXS_GET_DATA:
            /* Consider all commands ack'ed */
            USTRAN(unackedCommand) = FALSE;  

            HCI_RxBufferInd(st->rxBuffHandle, 
                            BT_STATUS_SUCCESS);

            /* Reset to first state */
            st->state = USB_RXS_GET_INIT;

        }

    } while (cntRead);

    return TRUE;
}