diff --git a/libctru/include/3ds/services/uds.h b/libctru/include/3ds/services/uds.h index 9c519f9..e44517f 100644 --- a/libctru/include/3ds/services/uds.h +++ b/libctru/include/3ds/services/uds.h @@ -13,9 +13,6 @@ /// NetworkNodeID for the host(the first node). #define UDS_HOST_NETWORKNODEID 0x1 -/// Default value that can be used for udsSendTo() netflags. -#define UDS_SEND_NETFLAGS_DEFAULT 0xF3 - /// Node info struct. typedef struct { u64 uds_friendcodeseed;//UDS version of the FriendCodeSeed. @@ -227,8 +224,9 @@ Result udsGetNetworkStructApplicationData(const udsNetworkStruct *network, void * @param bindcontext The output bind context. * @param NetworkNodeID This is the NetworkNodeID which this bind can receive data from. * @param spectator False for a regular bind, true for a spectator. + * @param data_channel This is an arbitrary value to use for data-frame filtering. This bind will only receive data frames which contain a matching data_channel value, which was specified by udsSendTo(). The data_channel must be non-zero. */ -Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID, bool spectator); +Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID, bool spectator, u8 data_channel); /** * @brief Remove a bind. @@ -258,12 +256,12 @@ Result udsPullPacket(const udsBindContext *bindcontext, void *buf, size_t size, /** * @brief Sends data over the network. * @param dst_NetworkNodeID Destination NetworkNodeID. - * @param netflags UDS_SEND_NETFLAGS_DEFAULT can be used for this. This field is sent in the data frame NWM-module header. + * @param data_channel See udsBind(). * @param flags Send flags, see the UDS_SENDFLAG enum values. * @param buf Input send buffer. * @param size Size of the buffer. */ -Result udsSendTo(u16 dst_NetworkNodeID, u8 netflags, u8 flags, const void *buf, size_t size); +Result udsSendTo(u16 dst_NetworkNodeID, u8 data_channel, u8 flags, const void *buf, size_t size); /** * @brief Gets the wifi channel currently being used. @@ -276,20 +274,22 @@ Result udsGetChannel(u8 *channel); * @param network The NetworkStruct, you can use udsGenerateDefaultNetworkStruct() for generating this. * @param passphrase Raw input passphrase buffer. * @param passphrase_size Size of the passphrase buffer. - * @param bindcontext Output bind context which will be created for this host, with NetworkNodeID=UDS_BROADCAST_NETWORKNODEID. + * @param bindcontext Optional output bind context which will be created for this host, with NetworkNodeID=UDS_BROADCAST_NETWORKNODEID. + * @param data_channel This is the data_channel value which will be passed to udsBind(). */ -Result udsCreateNetwork(const udsNetworkStruct *network, const void *passphrase, size_t passphrase_size, udsBindContext *bindcontext); +Result udsCreateNetwork(const udsNetworkStruct *network, const void *passphrase, size_t passphrase_size, udsBindContext *bindcontext, u8 data_channel); /** * @brief Connect to a network. * @param network The NetworkStruct, you can use udsScanBeacons() for this. * @param passphrase Raw input passphrase buffer. * @param passphrase_size Size of the passphrase buffer. - * @param bindcontext Output bind context which will be created for this host. + * @param bindcontext Optional output bind context which will be created for this host. * @param recv_NetworkNodeID This is the NetworkNodeID passed to udsBind() internally. * @param connection_type Type of connection, see the udsConnectionType enum values. + * @param data_channel This is the data_channel value which will be passed to udsBind() internally. */ -Result udsConnectNetwork(const udsNetworkStruct *network, const void *passphrase, size_t passphrase_size, udsBindContext *context, u16 recv_NetworkNodeID, udsConnectionType connection_type); +Result udsConnectNetwork(const udsNetworkStruct *network, const void *passphrase, size_t passphrase_size, udsBindContext *context, u16 recv_NetworkNodeID, udsConnectionType connection_type, u8 data_channel); /** * @brief Stop hosting the network. diff --git a/libctru/source/services/uds.c b/libctru/source/services/uds.c index 6278905..c57e152 100644 --- a/libctru/source/services/uds.c +++ b/libctru/source/services/uds.c @@ -37,7 +37,7 @@ static Result udsipc_SetProbeResponseParam(u32 oui, s8 data); static Result udsipc_RecvBeaconBroadcastData(u8 *outbuf, u32 maxsize, nwmScanInputStruct *scaninput, u32 wlancommID, u8 id8, Handle event); static Result udsipc_ScanOnConnection(u8 *outbuf, u32 maxsize, nwmScanInputStruct *scaninput, u32 wlancommID, u8 id8); -static Result udsipc_Bind(udsBindContext *bindcontext, u32 input0, u8 input1, u16 NetworkNodeID); +static Result udsipc_Bind(udsBindContext *bindcontext, u32 input0, u8 data_channel, u16 NetworkNodeID); static Result udsipc_Unbind(udsBindContext *bindcontext); static Result udsipc_DecryptBeaconData(udsNetworkStruct *network, u8 *tag0, u8 *tag1, udsNodeInfo *out); @@ -243,7 +243,7 @@ static Result uds_Initialize(u32 sharedmem_size, const char *username) return ret; } -Result udsCreateNetwork(const udsNetworkStruct *network, const void *passphrase, size_t passphrase_size, udsBindContext *context) +Result udsCreateNetwork(const udsNetworkStruct *network, const void *passphrase, size_t passphrase_size, udsBindContext *context, u8 data_channel) { Result ret=0; @@ -253,14 +253,14 @@ Result udsCreateNetwork(const udsNetworkStruct *network, const void *passphrase, ret = udsipc_BeginHostingNetwork(network, passphrase, passphrase_size); if(R_FAILED(ret))return ret; - ret = udsBind(context, UDS_BROADCAST_NETWORKNODEID, false); + if(context)ret = udsBind(context, UDS_BROADCAST_NETWORKNODEID, false, data_channel); if(R_FAILED(ret))udsDestroyNetwork(); return ret; } -Result udsConnectNetwork(const udsNetworkStruct *network, const void *passphrase, size_t passphrase_size, udsBindContext *context, u16 recv_NetworkNodeID, udsConnectionType connection_type) +Result udsConnectNetwork(const udsNetworkStruct *network, const void *passphrase, size_t passphrase_size, udsBindContext *context, u16 recv_NetworkNodeID, udsConnectionType connection_type, u8 data_channel) { Result ret=0; bool spectator=false; @@ -271,7 +271,7 @@ Result udsConnectNetwork(const udsNetworkStruct *network, const void *passphrase ret = udsipc_ConnectToNetwork(network, passphrase, passphrase_size, connection_type); if(R_FAILED(ret))return ret; //printf("bind...\n"); - ret = udsBind(context, recv_NetworkNodeID, spectator); + if(context)ret = udsBind(context, recv_NetworkNodeID, spectator, data_channel); if(R_FAILED(ret))udsDisconnectNetwork(); @@ -532,7 +532,7 @@ Result udsScanBeacons(void *buf, size_t maxsize, udsNetworkScanInfo **networks, return ret; } -Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID, bool spectator) +Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID, bool spectator, u8 data_channel) { u32 pos; @@ -559,7 +559,7 @@ Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID, bool spectator) bindcontext->spectator = spectator; - return udsipc_Bind(bindcontext, 0x2e30, 0xf3, NetworkNodeID); + return udsipc_Bind(bindcontext, 0x2e30, data_channel, NetworkNodeID); } Result udsUnbind(udsBindContext *bindcontext) @@ -790,14 +790,14 @@ Result udsGetNetworkStructApplicationData(const udsNetworkStruct *network, void return 0; } -static Result udsipc_Bind(udsBindContext *bindcontext, u32 input0, u8 input1, u16 NetworkNodeID)//input0 and input1 are unknown. +static Result udsipc_Bind(udsBindContext *bindcontext, u32 input0, u8 data_channel, u16 NetworkNodeID) { u32* cmdbuf=getThreadCommandBuffer(); cmdbuf[0]=IPC_MakeHeader(0x12,4,0); // 0x120100 cmdbuf[1]=bindcontext->BindNodeID; cmdbuf[2]=input0; - cmdbuf[3]=input1; + cmdbuf[3]=data_channel; cmdbuf[4]=NetworkNodeID; Result ret=0; @@ -863,7 +863,7 @@ Result udsPullPacket(const udsBindContext *bindcontext, void *buf, size_t size, return ret; } -Result udsSendTo(u16 dst_NetworkNodeID, u8 netflags, u8 flags, const void *buf, size_t size) +Result udsSendTo(u16 dst_NetworkNodeID, u8 data_channel, u8 flags, const void *buf, size_t size) { u32* cmdbuf=getThreadCommandBuffer(); @@ -872,7 +872,7 @@ Result udsSendTo(u16 dst_NetworkNodeID, u8 netflags, u8 flags, const void *buf, cmdbuf[0]=IPC_MakeHeader(0x17,6,2); // 0x170182 cmdbuf[1]=0x1;//Unused cmdbuf[2]=dst_NetworkNodeID; - cmdbuf[3]=netflags; + cmdbuf[3]=data_channel; cmdbuf[4]=aligned_size>>2; cmdbuf[5]=size; cmdbuf[6]=flags;