void CWII_IPC_HLE_WiiMote::ReceiveConnectionReq(u8 _Ident, u8* _pData, u32 _Size) { l2cap_con_req_cp* pCommandConnectionReq = (l2cap_con_req_cp*)_pData; // create the channel SChannel& rChannel = m_Channel[pCommandConnectionReq->scid]; rChannel.PSM = pCommandConnectionReq->psm; rChannel.SCID = pCommandConnectionReq->scid; rChannel.DCID = pCommandConnectionReq->scid; INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] ReceiveConnectionRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident); DEBUG_LOG(WII_IPC_WIIMOTE, " PSM: 0x%04x", rChannel.PSM); DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", rChannel.SCID); DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", rChannel.DCID); // response l2cap_con_rsp_cp Rsp; Rsp.scid = rChannel.SCID; Rsp.dcid = rChannel.DCID; Rsp.result = L2CAP_SUCCESS; Rsp.status = L2CAP_NO_INFO; INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendConnectionResponse"); SendCommandToACL(_Ident, L2CAP_CONNECT_RSP, sizeof(l2cap_con_rsp_cp), (u8*)&Rsp); // update state machine /* if (rChannel.PSM == L2CAP_PSM_HID_CNTL) m_HIDControlChannel_Connected = true; else if (rChannel.PSM == L2CAP_PSM_HID_INTR) m_HIDInterruptChannel_Connected = true; */ }
void CWII_IPC_HLE_WiiMote::SendConfigurationRequest(u16 scid, u16 MTU, u16 FlushTimeOut) { _dbg_assert_(WII_IPC_WIIMOTE, DoesChannelExist(scid)); SChannel& rChannel = m_Channel[scid]; u8 Buffer[1024]; int Offset = 0; l2cap_cfg_req_cp* cr = (l2cap_cfg_req_cp*)&Buffer[Offset]; cr->dcid = rChannel.DCID; cr->flags = 0; Offset += sizeof(l2cap_cfg_req_cp); DEBUG_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendConfigurationRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Dcid: 0x%04x", cr->dcid); DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", cr->flags); l2cap_cfg_opt_t* pOptions; // (shuffle2) currently we end up not appending options. this is because we don't // negotiate after trying to set MTU = 0 fails (stack will respond with // "configuration failed" msg...). This is still fine, we'll just use whatever the // Bluetooth stack defaults to. if (MTU || rChannel.MTU) { if (MTU == 0) MTU = rChannel.MTU; pOptions = (l2cap_cfg_opt_t*)&Buffer[Offset]; Offset += sizeof(l2cap_cfg_opt_t); pOptions->type = L2CAP_OPT_MTU; pOptions->length = L2CAP_OPT_MTU_SIZE; *(u16*)&Buffer[Offset] = MTU; Offset += L2CAP_OPT_MTU_SIZE; DEBUG_LOG(WII_IPC_WIIMOTE, " MTU: 0x%04x", MTU); } if (FlushTimeOut || rChannel.FlushTimeOut) { if (FlushTimeOut == 0) FlushTimeOut = rChannel.FlushTimeOut; pOptions = (l2cap_cfg_opt_t*)&Buffer[Offset]; Offset += sizeof(l2cap_cfg_opt_t); pOptions->type = L2CAP_OPT_FLUSH_TIMO; pOptions->length = L2CAP_OPT_FLUSH_TIMO_SIZE; *(u16*)&Buffer[Offset] = FlushTimeOut; Offset += L2CAP_OPT_FLUSH_TIMO_SIZE; DEBUG_LOG(WII_IPC_WIIMOTE, " FlushTimeOut: 0x%04x", FlushTimeOut); } SendCommandToACL(L2CAP_CONFIG_REQ, L2CAP_CONFIG_REQ, Offset, Buffer); }
// We don't initially disconnect Wiimote though ... void CWII_IPC_HLE_WiiMote::SendDisconnectRequest(u16 scid) { // create the channel SChannel& rChannel = m_Channel[scid]; l2cap_discon_req_cp cr; cr.dcid = rChannel.DCID; cr.scid = rChannel.SCID; INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendDisconnectionRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Dcid: 0x%04x", cr.dcid); DEBUG_LOG(WII_IPC_WIIMOTE, " Scid: 0x%04x", cr.scid); SendCommandToACL(L2CAP_DISCONNECT_REQ, L2CAP_DISCONNECT_REQ, sizeof(l2cap_discon_req_cp), (u8*)&cr); }
// We assume WiiMote is always connected void CWII_IPC_HLE_WiiMote::SendConnectionRequest(u16 scid, u16 psm) { // create the channel SChannel& rChannel = m_Channel[scid]; rChannel.PSM = psm; rChannel.SCID = scid; l2cap_con_req_cp cr; cr.psm = psm; cr.scid = scid; INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendConnectionRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Psm: 0x%04x", cr.psm); DEBUG_LOG(WII_IPC_WIIMOTE, " Scid: 0x%04x", cr.scid); SendCommandToACL(L2CAP_CONNECT_REQ, L2CAP_CONNECT_REQ, sizeof(l2cap_con_req_cp), (u8*)&cr); }
void CWII_IPC_HLE_WiiMote::ReceiveDisconnectionReq(u8 _Ident, u8* _pData, u32 _Size) { l2cap_discon_req_cp* pCommandDisconnectionReq = (l2cap_discon_req_cp*)_pData; INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] ReceiveDisconnectionReq"); DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident); DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", pCommandDisconnectionReq->dcid); DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", pCommandDisconnectionReq->scid); // response l2cap_discon_req_cp Rsp; Rsp.dcid = pCommandDisconnectionReq->dcid; Rsp.scid = pCommandDisconnectionReq->scid; INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendDisconnectionResponse"); SendCommandToACL(_Ident, L2CAP_DISCONNECT_RSP, sizeof(l2cap_discon_req_cp), (u8*)&Rsp); }
void CWII_IPC_HLE_WiiMote::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _Size) { u32 Offset = 0; l2cap_cfg_req_cp* pCommandConfigReq = (l2cap_cfg_req_cp*)_pData; _dbg_assert_(WII_IPC_WIIMOTE, pCommandConfigReq->flags == 0x00); // 1 means that the options are send in multi-packets _dbg_assert_(WII_IPC_WIIMOTE, DoesChannelExist(pCommandConfigReq->dcid)); SChannel& rChannel = m_Channel[pCommandConfigReq->dcid]; INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] ReceiveConfigurationRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident); DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", pCommandConfigReq->dcid); DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", pCommandConfigReq->flags); Offset += sizeof(l2cap_cfg_req_cp); u8 TempBuffer[1024]; u32 RespLen = 0; l2cap_cfg_rsp_cp* Rsp = (l2cap_cfg_rsp_cp*)TempBuffer; Rsp->scid = rChannel.DCID; Rsp->flags = 0x00; Rsp->result = L2CAP_SUCCESS; RespLen += sizeof(l2cap_cfg_rsp_cp); // read configuration options while (Offset < _Size) { l2cap_cfg_opt_t* pOptions = (l2cap_cfg_opt_t*)&_pData[Offset]; Offset += sizeof(l2cap_cfg_opt_t); switch (pOptions->type) { case L2CAP_OPT_MTU: { _dbg_assert_(WII_IPC_WIIMOTE, pOptions->length == L2CAP_OPT_MTU_SIZE); l2cap_cfg_opt_val_t* pMTU = (l2cap_cfg_opt_val_t*)&_pData[Offset]; rChannel.MTU = pMTU->mtu; DEBUG_LOG(WII_IPC_WIIMOTE, " MTU: 0x%04x", pMTU->mtu); } break; case L2CAP_OPT_FLUSH_TIMO: { _dbg_assert_(WII_IPC_WIIMOTE, pOptions->length == L2CAP_OPT_FLUSH_TIMO_SIZE); l2cap_cfg_opt_val_t* pFlushTimeOut = (l2cap_cfg_opt_val_t*)&_pData[Offset]; rChannel.FlushTimeOut = pFlushTimeOut->flush_timo; DEBUG_LOG(WII_IPC_WIIMOTE, " FlushTimeOut: 0x%04x", pFlushTimeOut->flush_timo); } break; default: _dbg_assert_msg_(WII_IPC_WIIMOTE, 0, "Unknown Option: 0x%02x", pOptions->type); break; } Offset += pOptions->length; u32 OptionSize = sizeof(l2cap_cfg_opt_t) + pOptions->length; memcpy(&TempBuffer[RespLen], pOptions, OptionSize); RespLen += OptionSize; } INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendConfigurationResponse"); SendCommandToACL(_Ident, L2CAP_CONFIG_RSP, RespLen, TempBuffer); // update state machine if (rChannel.PSM == L2CAP_PSM_HID_CNTL) m_HIDControlChannel_Connected = true; else if (rChannel.PSM == L2CAP_PSM_HID_INTR) m_HIDInterruptChannel_Connected = true; }