From c9a8672987a1f4335885816f0637bbc77f4d9cf5 Mon Sep 17 00:00:00 2001 From: "fires.gc" Date: Sun, 26 Oct 2008 14:16:51 +0000 Subject: [PATCH] some more wpad work... git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@973 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Core.vcproj | 4 - .../Core/Src/Debugger/Debugger_SymbolMap.cpp | 20 ++ .../Core/Src/Debugger/Debugger_SymbolMap.h | 1 + .../Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp | 212 +++++++++++++----- .../Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h | 5 +- .../Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp | 74 ++++-- .../Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h | 14 ++ Source/Core/Core/Src/IPC_HLE/hci.h | 6 + Source/Core/Core/Src/IPC_HLE/l2cap.h | 63 ++++++ .../Plugin_Wiimote_Test/Src/Wiimote.cpp | 93 +++++--- .../Plugin_Wiimote_Test/Src/wiimote_hid.h | 9 + 11 files changed, 399 insertions(+), 102 deletions(-) diff --git a/Source/Core/Core/Core.vcproj b/Source/Core/Core/Core.vcproj index bd2ab5fb2d..8fc8bda590 100644 --- a/Source/Core/Core/Core.vcproj +++ b/Source/Core/Core/Core.vcproj @@ -1143,10 +1143,6 @@ RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_WiiMote.h" > - - = _Size) + break; + } + + __Log(_Log, " Data: %s", Temp.c_str()); + } +} + } // end of namespace Debugger diff --git a/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.h b/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.h index 7a8366531a..bbd29b7733 100644 --- a/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.h +++ b/Source/Core/Core/Src/Debugger/Debugger_SymbolMap.h @@ -35,6 +35,7 @@ struct CallstackEntry bool GetCallstack(std::vector &output); void PrintCallstack(); void PrintCallstack(LogTypes::LOG_TYPE _Log); +void PrintDataBuffer(LogTypes::LOG_TYPE _Log, u8* _pData, size_t _Size, const char* _title); } // end of namespace Debugger diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp index 3d090a6905..8cfcf2113d 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp @@ -18,6 +18,8 @@ #include "WII_IPC_HLE_Device_usb.h" #include "../Plugins/Plugin_Wiimote.h" +#include "../Debugger/Debugger_SymbolMap.h" + // ugly hacks for "SendEventNumberOfCompletedPackets" int g_HCICount = 0; int g_GlobalHandle = 0; @@ -67,9 +69,17 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::IOCtl(u32 _CommandAddress) bool CWII_IPC_HLE_Device_usb_oh1_57e_305::IOCtlV(u32 _CommandAddress) { - // wpadsampled.elf - patch so the USB_LOG will print somehting + + Memory::Write_U8(255, 0x80149950); // BTM LOG + // 3 logs L2Cap + // 4 logs l2_csm$ + + Memory::Write_U8(255, 0x80149949); // HID + + Memory::Write_U8(255, 0x80152058); // low ?? + // even it it wasn't very useful yet... - Memory::Write_U8(1, 0x80151488); // DebugLog + // Memory::Write_U8(1, 0x80151488); // WPAD_LOG // Memory::Write_U8(1, 0x801514A8); // USB_LOG // Memory::Write_U8(1, 0x801514D8); // WUD_DEBUGPrint // Memory::Write_U8(1, 0x80148E09); // HID LOG @@ -210,7 +220,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::SendToDevice(u16 _ConnectionHandle, u8 CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_ConnectionHandle); if (pWiiMote == NULL) { - PanicAlert("Cant find WiiMote by connection handle: %02x", _ConnectionHandle); + PanicAlert("SendToDevice: Cant find WiiMote by connection handle: %02x", _ConnectionHandle); return; } @@ -293,7 +303,31 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() g_HCICount = 0; } - PluginWiimote::Wiimote_Update(); + if (m_AclFrameQue.empty()) + { + PluginWiimote::Wiimote_Update(); + } + + + static bool test = true; + if (GetAsyncKeyState(VK_LBUTTON) && GetAsyncKeyState(VK_RBUTTON)) + { + if (test) + { + for (size_t i=0; iEventType = 0x04; pEventRequestConnection->PayloadLength = sizeof(SHCIEventRequestConnection) - 2; - pEventRequestConnection->bdaddr = rWiiMote.GetBD(); // BD_ADDR of the device that requests the connection - pEventRequestConnection->uclass[0] = rWiiMote.GetClass()[0]; - pEventRequestConnection->uclass[1] = rWiiMote.GetClass()[1]; - pEventRequestConnection->uclass[2] = rWiiMote.GetClass()[2]; + pEventRequestConnection->bdaddr = pWiiMote->GetBD(); // BD_ADDR of the device that requests the connection + pEventRequestConnection->uclass[0] = pWiiMote->GetClass()[0]; + pEventRequestConnection->uclass[1] = pWiiMote->GetClass()[1]; + pEventRequestConnection->uclass[2] = pWiiMote->GetClass()[2]; pEventRequestConnection->LinkType = 0x01; AddEventToQueue(Event); @@ -480,12 +517,36 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRequestConnection() return true; }; +bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRequestLinkKey(bdaddr_t _bd) +{ + const CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_bd); + + SQueuedEvent Event(sizeof(SHCIEventRequestLinkKey), 0); + + SHCIEventRequestLinkKey* pEventRequestLinkKey = (SHCIEventRequestLinkKey*)Event.m_buffer; + + pEventRequestLinkKey->EventType = 0x17; + pEventRequestLinkKey->PayloadLength = sizeof(SHCIEventRequestLinkKey) - 2; + pEventRequestLinkKey->bdaddr = _bd; + + AddEventToQueue(Event); + + + LOG(WIIMOTE, "Event: SendEventRequestLinkKey"); + LOG(WIIMOTE, " bd: %02x:%02x:%02x:%02x:%02x:%02x", + pEventRequestLinkKey->bdaddr.b[0], pEventRequestLinkKey->bdaddr.b[1], pEventRequestLinkKey->bdaddr.b[2], + pEventRequestLinkKey->bdaddr.b[3], pEventRequestLinkKey->bdaddr.b[4], pEventRequestLinkKey->bdaddr.b[5]); + + return true; +}; + + bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventConnectionComplete(bdaddr_t _bd) { CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_bd); if (pWiiMote == NULL) { - PanicAlert("Cant find WiiMote by bd: %02x:%02x:%02x:%02x:%02x:%02x", + PanicAlert("SendEventConnectionComplete: Cant find WiiMote by bd: %02x:%02x:%02x:%02x:%02x:%02x", _bd.b[0], _bd.b[1], _bd.b[2], _bd.b[3], _bd.b[4], _bd.b[5]); return false; @@ -532,7 +593,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRoleChange(bdaddr_t _bd) CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_bd); if (pWiiMote == NULL) { - PanicAlert("Cant find WiiMote by bd: %02x:%02x:%02x:%02x:%02x:%02x", + PanicAlert("SendEventRoleChange: Cant find WiiMote by bd: %02x:%02x:%02x:%02x:%02x:%02x", _bd.b[0], _bd.b[1], _bd.b[2], _bd.b[3], _bd.b[4], _bd.b[5]); return false; @@ -542,7 +603,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRoleChange(bdaddr_t _bd) SHCIEventRoleChange* pRoleChange = (SHCIEventRoleChange*)Event.m_buffer; - pRoleChange->EventType = 0x03; + pRoleChange->EventType = 0x12; pRoleChange->PayloadLength = sizeof(SHCIEventRoleChange) - 2; pRoleChange->Status = 0x00; pRoleChange->bdaddr = pWiiMote->GetBD(); @@ -566,7 +627,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventReadClockOffsetComplete(u16 _ CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_connectionHandle); if (pWiiMote == NULL) { - PanicAlert("Cant find WiiMote by connection handle: %02x", _connectionHandle); + PanicAlert("SendEventReadClockOffsetComplete: Cant find WiiMote by connection handle: %02x", _connectionHandle); return false; } @@ -594,7 +655,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventReadRemoteVerInfo(u16 _connec CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_connectionHandle); if (pWiiMote == NULL) { - PanicAlert("Cant find WiiMote by connection handle: %02x", _connectionHandle); + PanicAlert("SendEventReadRemoteVerInfo: Cant find WiiMote by connection handle: %02x", _connectionHandle); return false; } @@ -626,7 +687,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventReadRemoteFeatures(u16 _conne CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_connectionHandle); if (pWiiMote == NULL) { - PanicAlert("Cant find WiiMote by connection handle: %02x", _connectionHandle); + PanicAlert("SendEventReadRemoteFeatures: Cant find WiiMote by connection handle: %02x", _connectionHandle); return false; } @@ -771,9 +832,6 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventDisconnect(u16 _connectionHan } - - - //////////////////////////////////////////////////////////////////////////////////////////////////// // // @@ -787,7 +845,10 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::ExecuteHCICommandMessage(const SHCICom u8* pInput = Memory::GetPointer(_rHCICommandMessage.m_PayLoadAddr + 3); SCommandMessage* pMsg = (SCommandMessage*)Memory::GetPointer(_rHCICommandMessage.m_PayLoadAddr); - LOG(WIIMOTE, "****************************** ExecuteHCICommandMessage(0x%04x)", pMsg->Opcode); + u16 ocf = HCI_OCF(pMsg->Opcode); + u16 ogf = HCI_OGF(pMsg->Opcode); + LOG(WIIMOTE, "****************************** ExecuteHCICommandMessage(0x%04x)" + "(ocf: 0x%02x, ogf: 0x%02x)", pMsg->Opcode, ocf, ogf); switch(pMsg->Opcode) { @@ -914,6 +975,15 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::ExecuteHCICommandMessage(const SHCICom case HCI_CMD_DISCONNECT: CommandDisconnect(pInput); break; + + case HCI_CMD_WRITE_LINK_SUPERVISION_TIMEOUT: + CommandWriteLinkSupervisionTimeout(pInput); + break; + + case HCI_CMD_LINK_KEY_NEG_REP: + CommandLinkKeyNegRep(pInput); + break; + // // --- default --- // @@ -1191,15 +1261,15 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteScanEnable(u8* _Input) SendEventCommandComplete(HCI_CMD_WRITE_SCAN_ENABLE, &Reply, sizeof(hci_write_scan_enable_rp)); + return; + // TODO: fix this ugly request connection hack :) //for homebrew works this - if (pWriteScanEnable->scan_enable & 2) // check if page scan is enable + for (size_t i=0; iscan_enable)) { - first = false; - // SendEventRequestConnection(); + SendEventRequestConnection(m_WiiMotes[i].GetBD()); } } } @@ -1292,13 +1362,8 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandInquiry(u8* _Input) LOG(WIIMOTE, " num_responses: %i (N x 1.28) sec", pInquiry->num_responses); SendEventCommandStatus(HCI_CMD_INQUIRY); - - if (g_GlobalHandle == 0) - { - SendEventInquiryResponse(); - } -/* - SendEventInquiryComplete(); */ + SendEventInquiryResponse(); + SendEventInquiryComplete(); } void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteInquiryScanType(u8* _Input) @@ -1331,12 +1396,10 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandVendorSpecific_FC4F(u8* _Input, hci_status_rp Reply; Reply.status = 0x00; - LOG(WIIMOTE, "Command: CommandVendorSpecific_FC4F:"); + LOG(WIIMOTE, "Command: CommandVendorSpecific_FC4F: (callstack WUDiRemovePatch)"); LOG(WIIMOTE, "input (size 0x%x):", _Size); - for (u32 i=0; i<_Size; i++) - LOG(WIIMOTE, " Data: 0x%02x", _Input[i]); - LOG(WIIMOTE, "write:"); - LOG(WIIMOTE, " callstack WUDiRemovePatch"); + + Debugger::PrintDataBuffer(LogTypes::WIIMOTE, _Input, _Size, "Data: "); SendEventCommandComplete(0xFC4F, &Reply, sizeof(hci_status_rp)); } @@ -1349,10 +1412,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandVendorSpecific_FC4C(u8* _Input, LOG(WIIMOTE, "Command: CommandVendorSpecific_FC4C:"); LOG(WIIMOTE, "input (size 0x%x):", _Size); - for (u32 i=0; i<_Size; i++) - LOG(WIIMOTE, " Data: 0x%02x", _Input[i]); - LOG(WIIMOTE, "write:"); - LOG(WIIMOTE, " perhaps append patch?"); + Debugger::PrintDataBuffer(LogTypes::WIIMOTE, _Input, _Size, "Data: "); SendEventCommandComplete(0xFC4C, &Reply, sizeof(hci_status_rp)); } @@ -1428,6 +1488,13 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandAcceptCon(u8* _Input) LOG(WIIMOTE, " role: %s", s_szRole[pAcceptCon->role]); SendEventCommandStatus(HCI_CMD_ACCEPT_CON); + + CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pAcceptCon->bdaddr); + if (pWiimote) + { + pWiimote->EventConnectionAccepted(); + } + SendEventConnectionComplete(pAcceptCon->bdaddr); } @@ -1442,6 +1509,9 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReadClockOffset(u8* _Input) SendEventCommandStatus(HCI_CMD_READ_CLOCK_OFFSET); SendEventReadClockOffsetComplete(pReadClockOffset->con_handle); + + //CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(pReadClockOffset->con_handle); +// pWiiMote->Connect(); } void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReadRemoteVerInfo(u8* _Input) @@ -1455,10 +1525,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReadRemoteVerInfo(u8* _Input) SendEventCommandStatus(HCI_CMD_READ_REMOTE_VER_INFO); SendEventReadRemoteVerInfo(pReadRemoteVerInfo->con_handle); - - // connect - // CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pReadRemoteVerInfo->con_handle); - // pWiimote->Connect(); } void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReadRemoteFeatures(u8* _Input) @@ -1472,6 +1538,10 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReadRemoteFeatures(u8* _Input) SendEventCommandStatus(HCI_CMD_READ_REMOTE_FEATURES); SendEventReadRemoteFeatures(pReadRemoteFeatures->con_handle); + + // connect + // CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pReadRemoteFeatures->con_handle); + // pWiimote->Connect(); } void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteLinkPolicy(u8* _Input) @@ -1485,12 +1555,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteLinkPolicy(u8* _Input) LOG(WIIMOTE, " Policy: 0x%04x", pLinkPolicy->settings); SendEventCommandStatus(HCI_CMD_WRITE_LINK_POLICY_SETTINGS); - - PanicAlert("The connect should be send after the command status... check it"); - - // for homebrew works this - // CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pLinkPolicy->con_handle); - // pWiimote->Connect(); } void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandAuthenticationRequested(u8* _Input) @@ -1535,8 +1599,52 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandDisconnect(u8* _Input) SendEventCommandStatus(HCI_CMD_DISCONNECT); SendEventDisconnect(pDiscon->con_handle, pDiscon->reason); + + CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pDiscon->con_handle); + if (pWiimote) + { + pWiimote->EventDisconnect(); + } + } +void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteLinkSupervisionTimeout(u8* _Input) +{ + // command parameters + hci_write_link_supervision_timeout_cp* pSuperVision = (hci_write_link_supervision_timeout_cp*)_Input; + + LOG(WIIMOTE, "Command: HCI_OCF_WRITE_LINK_SUPERVISION_TIMEOUT"); + LOG(WIIMOTE, "Input:"); + LOG(WIIMOTE, " con_handle: 0x%04x", pSuperVision->con_handle); + LOG(WIIMOTE, " timeout: 0x%02x", pSuperVision->timeout); + + hci_write_link_supervision_timeout_rp Reply; + Reply.status = 0x00; + Reply.con_handle = pSuperVision->con_handle; + + SendEventCommandComplete(HCI_OCF_WRITE_LINK_SUPERVISION_TIMEOUT, &Reply, sizeof(hci_write_link_supervision_timeout_rp)); +} + +void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandLinkKeyNegRep(u8* _Input) +{ + // command parameters + hci_link_key_neg_rep_cp* pKeyNeg = (hci_link_key_neg_rep_cp*)_Input; + + LOG(WIIMOTE, "Command: HCI_CMD_LINK_KEY_NEG_REP"); + LOG(WIIMOTE, "Input:"); + LOG(WIIMOTE, " bd: %02x:%02x:%02x:%02x:%02x:%02x", + pKeyNeg->bdaddr.b[0], pKeyNeg->bdaddr.b[1], pKeyNeg->bdaddr.b[2], + pKeyNeg->bdaddr.b[3], pKeyNeg->bdaddr.b[4], pKeyNeg->bdaddr.b[5]); + + hci_link_key_neg_rep_rp Reply; + Reply.status = 0x00; + Reply.bdaddr = pKeyNeg->bdaddr; + + SendEventCommandComplete(HCI_OCF_WRITE_LINK_SUPERVISION_TIMEOUT, &Reply, sizeof(hci_link_key_neg_rep_rp)); + +// CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(pKeyNeg->bdaddr); +// pWiiMote->Connect(); +} diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h index 5a3772de42..2cbf3a4adf 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h @@ -152,7 +152,7 @@ private: bool SendEventInquiryResponse(); bool SendEventInquiryComplete(); bool SendEventRemoteNameReq(bdaddr_t _bd); - bool SendEventRequestConnection(); + bool SendEventRequestConnection(bdaddr_t _bd); bool SendEventConnectionComplete(bdaddr_t _bd); bool SendEventReadClockOffsetComplete(u16 _connectionHandle); bool SendEventReadRemoteVerInfo(u16 _connectionHandle); @@ -162,6 +162,7 @@ private: bool SendEventAuthenticationCompleted(u16 _connectionHandle); bool SendEventModeChange(u16 _connectionHandle, u8 _mode, u16 _value); bool SendEventDisconnect(u16 _connectionHandle, u8 _Reason); + bool SendEventRequestLinkKey(bdaddr_t _bd); // Execute HCI Message void ExecuteHCICommandMessage(const SHCICommandMessage& _rCtrlMessage); @@ -180,6 +181,7 @@ private: void CommandAuthenticationRequested(u8* _Input); void CommandInquiry(u8* _Input); void CommandDisconnect(u8* _Input); + void CommandLinkKeyNegRep(u8* _Input); // OGF 0x02 Link policy commands and return parameters void CommandWriteLinkPolicy(u8* _Input); @@ -195,6 +197,7 @@ private: void CommandWritePinType(u8* _Input); void CommandSetEventFilter(u8* _Input); void CommandWriteInquiryScanType(u8* _Input); + void CommandWriteLinkSupervisionTimeout(u8* _Input); // OGF 0x04 Informational commands and return parameters void CommandReadBufferSize(u8* _Input); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp index 3349adf6c2..16d5b1b558 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp @@ -135,13 +135,27 @@ static CWII_IPC_HLE_Device_usb_oh1_57e_305* s_Usb; namespace Core { void Callback_WiimoteInput(u16 _channelID, const void* _pData, u32 _Size) { + const u8* pData = (const u8*)_pData; + LOG(WIIMOTE, "Callback_WiimoteInput: 0x%x", _channelID); + std::string Temp; + for (u32 j=0; j<_Size; j++) + { + char Buffer[128]; + sprintf(Buffer, "%02x ", pData[j]); + Temp.append(Buffer); + } + LOG(WIIMOTE, " Data: %s", Temp.c_str()); + s_Usb->m_WiiMotes[0].SendL2capData(_channelID, _pData, _Size); + + // CCPU::Break(); } } CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number) : m_Name("Nintendo RVL-CNT-01") , m_pHost(_pHost) + , m_Connected(false) { s_Usb = _pHost; LOG(WIIMOTE, "Wiimote %i constructed", _Number); @@ -172,21 +186,33 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* lmp_subversion = 0x229; } +void CWII_IPC_HLE_WiiMote::EventConnectionAccepted() +{ + m_Connected = true; +} + +void CWII_IPC_HLE_WiiMote::EventDisconnect() +{ + m_Connected = false; +} + +bool CWII_IPC_HLE_WiiMote::EventPagingChanged(u8 _pageMode) +{ + if (m_Connected) + return false; + + if ((_pageMode & 2) == 0) + return false; + + return true; +} + + + void CWII_IPC_HLE_WiiMote::SendACLFrame(u8* _pData, u32 _Size) { -/* // dump raw data - { - LOG(WIIMOTE, "SendToDevice: 0x%x", GetConnectionHandle()); - std::string Temp; - for (u32 j=0; j<_Size; j++) - { - char Buffer[128]; - sprintf(Buffer, "%02x ", _pData[j]); - Temp.append(Buffer); - } - LOG(WIIMOTE, " Data: %s", Temp.c_str()); - } -*/ + // Debugger::PrintDataBuffer(LogTypes::WIIMOTE, _pData, _Size, "SendACLFrame: "); + // parse the command SL2CAP_Header* pHeader = (SL2CAP_Header*)_pData; u8* pData = _pData + sizeof(SL2CAP_Header); @@ -296,8 +322,10 @@ void CWII_IPC_HLE_WiiMote::SendCommandToACL(u8 _Ident, u8 _Code, u8 _CommandLeng void CWII_IPC_HLE_WiiMote::Connect() { - SendConnectionRequest(0x0040, HIDP_OUTPUT_CHANNEL); - SendConnectionRequest(0x0041, HIDP_INPUT_CHANNEL); + SendConnectionRequest(0x0040, 1); + +// SendConnectionRequest(0x0041, HIDP_OUTPUT_CHANNEL); +// SendConnectionRequest(0x0042, HIDP_INPUT_CHANNEL); } void CWII_IPC_HLE_WiiMote::SendConnectionRequest(u16 scid, u16 psm) @@ -318,6 +346,22 @@ void CWII_IPC_HLE_WiiMote::SendConnectionRequest(u16 scid, u16 psm) SendCommandToACL(L2CAP_CONN_REQ, L2CAP_CONN_REQ, sizeof(l2cap_conn_req), (u8*)&cr); } +void CWII_IPC_HLE_WiiMote::SendDisconnectRequest(u16 scid) +{ + // create the channel + SChannel& rChannel = m_Channel[scid]; + + l2cap_disconn_req cr; + cr.dcid = rChannel.DCID; + cr.scid = rChannel.SCID; + + LOG(WIIMOTE, " SendDisconnectionRequest()"); + LOG(WIIMOTE, " Dcid: 0x%04x", cr.dcid); + LOG(WIIMOTE, " Scid: 0x%04x", cr.scid); + + SendCommandToACL(L2CAP_DISCONN_REQ, L2CAP_DISCONN_REQ, sizeof(l2cap_disconn_req), (u8*)&cr); +} + void CWII_IPC_HLE_WiiMote::SendConfigurationRequest(u16 scid, u16* MTU, u16* FlushTimeOut) { _dbg_assert_(WIIMOTE, DoesChannelExist(scid)); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h index c79bc04025..2e8a71cbb8 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h @@ -80,6 +80,17 @@ public: virtual ~CWII_IPC_HLE_WiiMote() {} + ////////////////////////////////////////////////////////////// + // ugly Host handling.... + // we really have to clean all this code + + bool IsConnected() const { return m_Connected; } + + + void EventConnectionAccepted(); + void EventDisconnect(); + bool EventPagingChanged(u8 _pageMode); + const bdaddr_t& GetBD() const { return m_BD; } const uint8_t* GetClass() const { return uclass; } @@ -104,6 +115,8 @@ public: private: + bool m_Connected; + // STATE_TO_SAVE bdaddr_t m_BD; @@ -146,6 +159,7 @@ private: void SendConnectionRequest(u16 scid, u16 psm); void SendConfigurationRequest(u16 scid, u16* MTU, u16* FlushTimeOut); + void SendDisconnectRequest(u16 scid); void CommandConnectionReq(u8 _Ident, u8* _pData, u32 _Size); void CommandCofigurationReq(u8 _Ident, u8* _pData, u32 _Size); diff --git a/Source/Core/Core/Src/IPC_HLE/hci.h b/Source/Core/Core/Src/IPC_HLE/hci.h index 1e3fb6d247..e218c1c266 100644 --- a/Source/Core/Core/Src/IPC_HLE/hci.h +++ b/Source/Core/Core/Src/IPC_HLE/hci.h @@ -2534,6 +2534,12 @@ struct SHCIEventDisconnectCompleted u8 Reason; }; +struct SHCIEventRequestLinkKey +{ + u8 EventType; + u8 PayloadLength; + bdaddr_t bdaddr; +}; #ifdef __cplusplus } diff --git a/Source/Core/Core/Src/IPC_HLE/l2cap.h b/Source/Core/Core/Src/IPC_HLE/l2cap.h index e04ddfe229..7f46e278fc 100644 --- a/Source/Core/Core/Src/IPC_HLE/l2cap.h +++ b/Source/Core/Core/Src/IPC_HLE/l2cap.h @@ -212,6 +212,69 @@ struct l2cap_info_rsp { #pragma pack(pop) #endif +struct value_string +{ + u32 value; + char* string; +}; + +static const value_string command_code_vals[] = { + { 0x01, "Command Reject" }, + { 0x02, "Connection Request" }, + { 0x03, "Connection Response" }, + { 0x04, "Configure Request" }, + { 0x05, "Configure Response" }, + { 0x06, "Disconnect Request" }, + { 0x07, "Disconnect Response" }, + { 0x08, "Echo Request" }, + { 0x09, "Echo Response" }, + { 0x0A, "Information Request" }, + { 0x0B, "Information Response" }, + { 0, NULL } +}; + + + +static const value_string psm_vals[] = { + { 0x0001, "SDP" }, + { 0x0003, "RFCOMM" }, + { 0x0005, "TCS-BIN" }, + { 0x0007, "TCS-BIN-CORDLESS" }, + { 0x000F, "BNEP" }, + { 0x0011, "HID_CONTROL" }, + { 0x0013, "HID_INTERRUPT" }, + { 0x0015, "UPnP" }, + { 0x0017, "AVCTP" }, + { 0x0019, "AVDTP" }, + { 0x001D, "UDI_C-Plane" }, + { 0, NULL } +}; + + +static const value_string result_vals[] = { + { 0x0000, "Connection successful" }, + { 0x0001, "Connection pending" }, + { 0x0002, "Connection Refused - PSM not supported" }, + { 0x0003, "Connection refused - security block" }, + { 0x0004, "Connection refused - no resources available" }, + { 0, NULL } +}; + + +static const value_string status_vals[] = { + { 0x0000, "No further information available" }, + { 0x0001, "Authentication panding" }, + { 0x0002, "Authorization pending" }, + { 0, NULL } +}; + + + + + + + + #ifdef NOT_DOLPHIN /* ----- L2CAP connections ----- */ diff --git a/Source/Plugins/Plugin_Wiimote_Test/Src/Wiimote.cpp b/Source/Plugins/Plugin_Wiimote_Test/Src/Wiimote.cpp index 4af42cb6a4..01c4a252e4 100644 --- a/Source/Plugins/Plugin_Wiimote_Test/Src/Wiimote.cpp +++ b/Source/Plugins/Plugin_Wiimote_Test/Src/Wiimote.cpp @@ -67,12 +67,12 @@ void WmRequestStatus(u16 _channelID, wm_request_status* rs); void WmDataReporting(u16 _channelID, wm_data_reporting* dr); void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size); -void SendWriteDataReply(u16 _channelID); void SendReportCoreAccel(u16 _channelID); void SendReportCoreAccelIr12(u16 _channelID); void SendReportCore(u16 _channelID); -int WriteWmReport(u16 _channelID, u8* dst, u8 channel); +int WriteWmReport(u8* dst, u8 channel); +void WmSendAck(u16 _channelID, u8 _reportID); static u32 convert24bit(const u8* src) { return (src[0] << 16) | (src[1] << 8) | src[2]; @@ -202,7 +202,11 @@ extern "C" void Wiimote_Input(u16 _channelID, const void* _pData, u32 _Size) switch(hidp->param) { case HID_PARAM_OUTPUT: - HidOutputReport(_channelID, (wm_report*)hidp->data); + { + wm_report* sr = (wm_report*)hidp->data; + WmSendAck(_channelID, sr->channel); + HidOutputReport(_channelID, sr); + } break; default: @@ -278,7 +282,7 @@ extern "C" void Wiimote_Update() { switch(g_ReportingMode) { case 0: break; - case WM_REPORT_CORE: SendReportCoreAccel(g_ReportingChannel); break; + case WM_REPORT_CORE: SendReportCore(g_ReportingChannel); break; case WM_REPORT_CORE_ACCEL: SendReportCoreAccel(g_ReportingChannel); break; case WM_REPORT_CORE_ACCEL_IR12: SendReportCoreAccelIr12(g_ReportingChannel);break; } @@ -299,6 +303,7 @@ void HidOutputReport(u16 _channelID, wm_report* sr) { { case WM_LEDS: WmLeds(_channelID, (wm_leds*)sr->data); + // WmSendAck(_channelID, WM_LEDS); break; case WM_READ_DATA: WmReadData(_channelID, (wm_read_data*)sr->data); @@ -309,6 +314,7 @@ void HidOutputReport(u16 _channelID, wm_report* sr) { case WM_IR_PIXEL_CLOCK: case WM_IR_LOGIC: LOG(WIIMOTE, " IR Enable 0x%02x 0x%02x", sr->channel, sr->data[0]); + // WmSendAck(_channelID, WM_IR_LOGIC); break; case WM_WRITE_DATA: WmWriteData(_channelID, (wm_write_data*)sr->data); @@ -330,8 +336,36 @@ void WmLeds(u16 _channelID, wm_leds* leds) { g_Leds = leds->leds; } +void WmSendAck(u16 _channelID, u8 _reportID) +{ -void WmDataReporting(u16 _channelID, wm_data_reporting* dr) { + u8 DataFrame[1024]; + + u32 Offset = 0; + + // header + hid_packet* pHidHeader = (hid_packet*)(DataFrame + Offset); + pHidHeader->type = HID_TYPE_DATA; + pHidHeader->param = HID_PARAM_INPUT; + Offset += sizeof(hid_packet); + + wm_acknowledge* pData = (wm_acknowledge*)(DataFrame + Offset); + pData->Channel = WM_WRITE_DATA_REPLY; + pData->unk0 = 0; + pData->unk1 = 0; + pData->reportID = _reportID; + pData->errorID = 0; + Offset += sizeof(wm_acknowledge); + + + LOG(WIIMOTE, " WMSendAck()"); + + g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); +} + + +void WmDataReporting(u16 _channelID, wm_data_reporting* dr) +{ LOG(WIIMOTE, " Set Data reporting mode"); LOG(WIIMOTE, " Rumble: %x", dr->rumble); LOG(WIIMOTE, " Continuous: %x", dr->continuous); @@ -341,7 +375,7 @@ void WmDataReporting(u16 _channelID, wm_data_reporting* dr) { g_ReportingMode = dr->mode; g_ReportingChannel = _channelID; - switch(g_ReportingMode) { //see Wiimote_Update() + switch(dr->mode) { //see Wiimote_Update() case 0x30: case 0x31: case 0x33: @@ -349,26 +383,30 @@ void WmDataReporting(u16 _channelID, wm_data_reporting* dr) { default: PanicAlert("Wiimote: Unknown reporting mode 0x%x", dr->mode); } + + // WmSendAck(_channelID, WM_DATA_REPORTING); } -void FillReportInfo(wm_report_core& _reportCore) +void FillReportInfo(wm_core& _core) { static bool bb = true; bb = !bb; - _reportCore.c.a = bb ? 1 : 0; + _core.a = GetAsyncKeyState(VK_LBUTTON) ? 1 : 0; + _core.b = GetAsyncKeyState(VK_RBUTTON) ? 1 : 0; } -void SendReportCore(u16 _channelID) { +void SendReportCore(u16 _channelID) +{ u8 DataFrame[1024]; - u32 Offset = WriteWmReport(_channelID, DataFrame, WM_REPORT_CORE); + u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE); wm_report_core* pReport = (wm_report_core*)(DataFrame + Offset); Offset += sizeof(wm_report_core); memset(pReport, 0, sizeof(wm_report_core)); - FillReportInfo(*pReport); + FillReportInfo(pReport->c); LOG(WIIMOTE, " SendReportCore()"); @@ -378,7 +416,7 @@ void SendReportCore(u16 _channelID) { void SendReportCoreAccelIr12(u16 _channelID) { u8 DataFrame[1024]; - u32 Offset = WriteWmReport(_channelID, DataFrame, WM_REPORT_CORE_ACCEL_IR12); + u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL_IR12); wm_report_core_accel_ir12* pReport = (wm_report_core_accel_ir12*)(DataFrame + Offset); Offset += sizeof(wm_report_core_accel_ir12); @@ -437,7 +475,7 @@ void SendReportCoreAccelIr12(u16 _channelID) { void SendReportCoreAccel(u16 _channelID) { u8 DataFrame[1024]; - u32 Offset = WriteWmReport(_channelID, DataFrame, WM_REPORT_CORE_ACCEL); + u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL); wm_report_core_accel* pReport = (wm_report_core_accel*)(DataFrame + Offset); Offset += sizeof(wm_report_core_accel); @@ -462,10 +500,12 @@ void WmReadData(u16 _channelID, wm_read_data* rd) { LOG(WIIMOTE, " Size: 0x%04x", size); LOG(WIIMOTE, " Rumble: %x", rd->rumble); - if(size <= 16 && rd->space == 0) { + if(size <= 100 && rd->space == 0) { SendReadDataReply(_channelID, g_Eeprom, address, (u8)size); - } else { - PanicAlert("WmReadData: unimplemented parameters!"); + } + else + { + PanicAlert("WmReadData: unimplemented parameters (size: %i, addr: 0x%x!", size, rd->space); } } @@ -484,7 +524,8 @@ void WmWriteData(u16 _channelID, wm_write_data* wd) { return; } memcpy(g_Eeprom + address, wd->data, wd->size); - SendWriteDataReply(_channelID); + + // WmSendAck(_channelID, WM_WRITE_DATA); } else if(wd->size <= 16 && (wd->space == WM_SPACE_REGS1 || wd->space == WM_SPACE_REGS2)) { @@ -513,22 +554,14 @@ void WmWriteData(u16 _channelID, wm_write_data* wd) { return; } memcpy(block + address, wd->data, wd->size); - SendWriteDataReply(_channelID); + + // WmSendAck(_channelID, WM_WRITE_DATA); } else { PanicAlert("WmWriteData: unimplemented parameters!"); } } -void SendWriteDataReply(u16 _channelID) { - u8 DataFrame[1024]; - u32 Offset = WriteWmReport(_channelID, DataFrame, WM_WRITE_DATA_REPLY); - - LOG(WIIMOTE, " SendWriteDataReply()"); - - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); -} - -int WriteWmReport(u16 _channelID, u8* dst, u8 channel) { +int WriteWmReport(u8* dst, u8 channel) { u32 Offset = 0; hid_packet* pHidHeader = (hid_packet*)(dst + Offset); Offset += sizeof(hid_packet); @@ -547,7 +580,7 @@ void WmRequestStatus(u16 _channelID, wm_request_status* rs) { //SendStatusReport(); u8 DataFrame[1024]; - u32 Offset = WriteWmReport(_channelID, DataFrame, WM_STATUS_REPORT); + u32 Offset = WriteWmReport(DataFrame, WM_STATUS_REPORT); wm_status_report* pStatus = (wm_status_report*)(DataFrame + Offset); Offset += sizeof(wm_status_report); @@ -566,7 +599,7 @@ void WmRequestStatus(u16 _channelID, wm_request_status* rs) { void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size) { u8 DataFrame[1024]; - u32 Offset = WriteWmReport(_channelID, DataFrame, WM_READ_DATA_REPLY); + u32 Offset = WriteWmReport(DataFrame, WM_READ_DATA_REPLY); _dbg_assert_(WIIMOTE, _Size <= 16); diff --git a/Source/Plugins/Plugin_Wiimote_Test/Src/wiimote_hid.h b/Source/Plugins/Plugin_Wiimote_Test/Src/wiimote_hid.h index bf9fdd0837..79e83789a6 100644 --- a/Source/Plugins/Plugin_Wiimote_Test/Src/wiimote_hid.h +++ b/Source/Plugins/Plugin_Wiimote_Test/Src/wiimote_hid.h @@ -80,6 +80,15 @@ struct wm_write_data { }; #define WM_WRITE_DATA_REPLY 0x22 //empty, afaik +struct wm_acknowledge +{ + u8 Channel; + u8 unk0; + u8 unk1; + u8 reportID; + u8 errorID; +}; + #define WM_READ_DATA 0x17 struct wm_read_data {