NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
WUDInternal.h
1#ifndef RVL_SDK_WUD_INTERNAL_H
2#define RVL_SDK_WUD_INTERNAL_H
3#include <types.h>
4
5// Public API
6#include <revolution/WUD/WUD.h>
7
8#include <revolution/BTE.h>
9#include <revolution/OS.h>
10#include <revolution/SC.h>
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#define WUD_BDCMP(LHS, RHS) memcmp(LHS, RHS, BD_ADDR_LEN)
16#define WUD_BDCPY(DST, SRC) memcpy(DST, SRC, BD_ADDR_LEN)
17
18// clang-format off
19#define WUD_DEV_NAME_IS(NAME, VALUE) \
20 (memcmp(NAME, VALUE, sizeof(VALUE) - 1) == 0)
21
22#define WUD_DEV_NAME_IS_CNT(NAME) \
23 WUD_DEV_NAME_IS(NAME, "Nintendo RVL-CNT")
24
25#define WUD_DEV_NAME_IS_CNT_01(NAME) \
26 WUD_DEV_NAME_IS(NAME, "Nintendo RVL-CNT-01")
27// clang-format on
28
29typedef enum { WUD_STATE_START = 0, WUD_STATE_ERROR = 255 } WUDState;
30
31typedef enum {
32 WUD_STATE_SYNC_PREPARE_SEARCH = 1,
33 WUD_STATE_SYNC_START_SEARCH = 2,
34 WUD_STATE_SYNC_WAIT_FOR_SEARCH_RESULT = 3,
35 WUD_STATE_SYNC_CHECK_SEARCH_RESULT = 4,
36 WUD_STATE_SYNC_IS_EXISTED_DEVICE = 5,
37 WUD_STATE_SYNC_6 = 6,
38 WUD_STATE_SYNC_STORED_LINK_KEY_TO_EEPROM = 7,
39 WUD_STATE_SYNC_WAIT_FOR_STORING = 8,
40 WUD_STATE_SYNC_WAIT_FOR_READING = 10,
41 WUD_STATE_SYNC_11 = 11,
42 WUD_STATE_SYNC_12 = 12,
43 WUD_STATE_SYNC_13 = 13,
44 WUD_STATE_SYNC_DONE = 14,
45 WUD_STATE_SYNC_TRY_CONNECT = 15,
46 WUD_STATE_SYNC_PREPARE_FOR_EXISTED_DEVICE = 16,
47 WUD_STATE_SYNC_PREPARE_FOR_UNKNOWN_DEVICE = 17,
48 WUD_STATE_SYNC_REGISTER_DEVICE = 18,
49 WUD_STATE_SYNC_VIRGIN_SIMPLE = 19,
50 WUD_STATE_SYNC_VIRGIN_STANDARD = 20,
51 WUD_STATE_SYNC_CHANGE_SIMPLE_TO_STANDARD = 21,
52 WUD_STATE_SYNC_STORED_DEV_INFO_TO_NAND = 22,
53 WUD_STATE_SYNC_COMPLETE = 23,
54 WUD_STATE_SYNC_WAIT_FOR_INCOMING = 24,
55 WUD_STATE_SYNC_SC_FLUSH = 25,
56 WUD_STATE_SYNC_CANCEL_SEARCH = 26,
57 WUD_STATE_SYNC_WAIT_FOR_START_SEARCH = 29,
58} WUDSyncState;
59
60typedef enum {
61 WUD_RESULT_SYNC_BUSY = -1,
62 WUD_RESULT_SYNC_WAITING,
63 WUD_RESULT_SYNC_DONE,
64} WUDSyncResult;
65
66typedef enum {
67 WUD_STATE_DELETE_DISALLOW_INCOMING = 1,
68 WUD_STATE_DELETE_DISCONNECT_ALL = 2,
69 WUD_STATE_DELETE_CLEANUP_DATABASE = 3,
70 WUD_STATE_DELETE_CLEANUP_SETTING = 5,
71 WUD_STATE_DELETE_6 = 6,
72 WUD_STATE_DELETE_7 = 7,
73 WUD_STATE_DELETE_DONE = 8
74} WUDDeleteState;
75
76typedef enum {
77 WUD_RESULT_DELETE_BUSY = -1,
78 WUD_RESULT_DELETE_WAITING,
79 WUD_RESULT_DELETE_COMPLETE,
80} WUDDeleteResult;
81
82typedef enum {
83 WUD_STATE_LINK_KEY_READING = 1,
84 WUD_STATE_LINK_KEY_WRITING = 2,
85 WUD_STATE_LINK_KEY_DELETING = 3,
86} WUDLinkKeyState;
87
88typedef enum {
89 WUD_STATE_STACK_GET_STORED_LINK_KEY = 1,
90 WUD_STATE_STACK_CHECK_DEVICE_INFO = 2,
91 WUD_STATE_STACK_DONE = 3,
92 WUD_STATE_STACK_INITIALIZED = 4
93} WUDStackState;
94
95typedef enum {
96 WUD_STATE_INIT_WAIT_FOR_INITIALIZATION = 1,
97 WUD_STATE_INIT_GET_DEV_INFO = 2,
98 WUD_STATE_INIT_DONE = 3,
99 WUD_STATE_INIT_INITIALIZED = 4
100} WUDInitState;
101
102typedef enum {
103 WUD_STATE_SHUTDOWN_STORE_SETTINGS = 1,
104 WUD_STATE_SHUTDOWN_FLUSH_SETTINGS = 2,
105 WUD_STATE_SHUTDOWN_DONE = 3
106} WUDShutdownState;
107
108typedef enum {
109 WUD_VSE_INITIATE_PAIRING = 8,
110 WUD_VSE_DELETE_ALL_KEYS,
111 WUD_VSE_SI_PORT_STATUS,
112 WUD_VSE_WATCH_DOG_RESET_HW = 16,
113} WUDVendorSpecificEvent;
114
115typedef struct WUDDevInfoList {
116 WUDDevInfo* devInfo; // at 0x0
117 struct WUDDevInfoList* prev; // at 0x4
118 struct WUDDevInfoList* next; // at 0x8
120
121typedef struct WUDDiscResp {
122 BD_ADDR devAddr; // at 0x0
123 char devName[64]; // at 0x6
124 u8 UNK_0x46[0xBA];
125 tBTA_SERVICE_MASK services; // at 0x100
126 u8 UNK_0x104[0x4];
128
129typedef struct WUDPatchCmd {
130 u8 data[13]; // at 0x0
132typedef struct WUDPatchList {
133 u8 num; // at 0x0
134 WUDPatchCmd cmds[]; // at 0x1
136#define WUD_PATCH_BUFFER_SIZE 0xFF
137#define WUD_MAX_PATCHES (WUD_PATCH_BUFFER_SIZE / (s32)sizeof(WUDPatchCmd))
138
139typedef struct WUDCB {
140 WUDSyncDeviceCallback syncStdCB; // at 0x0
141 WUDSyncDeviceCallback syncSmpCB; // at 0x4
142 WUDClearDeviceCallback clearDevCB; // at 0x8
143
144 u8 syncState; // at 0xC
145 u8 deleteState; // at 0xD
146 u8 linkKeyState; // at 0xE
147 u8 stackState; // at 0xF
148 u8 initState; // at 0x10
149 u8 shutdownState; // at 0x11
150
151 u8 devNums; // at 0x12
152 u8 devSmpNums; // at 0x13
153
154 WUDDevInfoList* smpListHead; // at 0x14
155 WUDDevInfoList* smpListTail; // at 0x18
156 WUDDevInfoList smpList[WUD_MAX_DEV_ENTRY_FOR_SMP]; // at 0x1C
157
158 WUDDevInfoList* stdListHead; // at 0x64
159 WUDDevInfoList* stdListTail; // at 0x68
160 WUDDevInfoList stdList[WUD_MAX_DEV_ENTRY_FOR_STD]; // at 0x6C
161
162 WUDDevInfo stdDevs[WUD_MAX_DEV_ENTRY_FOR_STD]; // at 0xE4
163 WUDDevInfo smpDevs[WUD_MAX_DEV_ENTRY_FOR_SMP]; // at 0x4A4
164
165 u8 connectedNum; // at 0x6E4
166 u8 linkedNum; // at 0x6E5
167 u8 syncedNum; // at 0x6E6
168
169 u8 syncSkipChecks; // at 0x6E7
170 s8 syncLoopNum; // at 0x6E8
171 u8 syncType; // at 0x6E9
172
173 u8 connectable; // at 0x6EA
174 u8 discoverable; // at 0x6EB
175
176 WUDHidRecvCallback hidRecvCB; // at 0x6EC
177 WUDHidConnCallback hidConnCB; // at 0x6F0
178
179 WUDAllocFunc allocFunc; // at 0x6F4
180 WUDFreeFunc freeFunc; // at 0x6F8
181
182 BD_ADDR pairAddr; // at 0x6FC
183 BD_ADDR hostAddr; // at 0x702
184
185 s8 libStatus; // at 0x708
186
187 u8 serialPortStatus; // at 0x709
188 UINT8 pmID; // at 0x70A
189 s8 syncRssi; // at 0x70B
190 OSAlarm alarm; // at 0x710
191 u32 hhFlags; // at 0x740
192
193 u16 bufferStatus0; // at 0x744
194 u16 bufferStatus1; // at 0x746
195} WUDCB;
196
197extern WUDCB _wcb;
198extern WUDDevInfo _work;
199
200extern SCBtDeviceInfoArray _scArray;
201
202extern BD_ADDR_PTR _dev_handle_to_bda[WUD_MAX_DEV_ENTRY];
203extern u16 _dev_handle_queue_size[WUD_MAX_DEV_ENTRY];
204extern u16 _dev_handle_notack_num[WUD_MAX_DEV_ENTRY];
205
206#ifdef __cplusplus
207}
208#endif
209#endif