Implemented UDS data_channel handling. Added the data_channel param to udsBind(), udsConnectNetwork(), and udsCreateNetwork(). Removed UDS_SEND_NETFLAGS_DEFAULT. The output bind context for network creation/connecting is now optional.

This commit is contained in:
yellows8 2016-04-08 19:09:15 -04:00
parent 353f7af759
commit b6e0555b1a
2 changed files with 21 additions and 21 deletions

View File

@ -13,9 +13,6 @@
/// NetworkNodeID for the host(the first node). /// NetworkNodeID for the host(the first node).
#define UDS_HOST_NETWORKNODEID 0x1 #define UDS_HOST_NETWORKNODEID 0x1
/// Default value that can be used for udsSendTo() netflags.
#define UDS_SEND_NETFLAGS_DEFAULT 0xF3
/// Node info struct. /// Node info struct.
typedef struct { typedef struct {
u64 uds_friendcodeseed;//UDS version of the FriendCodeSeed. 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 bindcontext The output bind context.
* @param NetworkNodeID This is the NetworkNodeID which this bind can receive data from. * @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 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. * @brief Remove a bind.
@ -258,12 +256,12 @@ Result udsPullPacket(const udsBindContext *bindcontext, void *buf, size_t size,
/** /**
* @brief Sends data over the network. * @brief Sends data over the network.
* @param dst_NetworkNodeID Destination NetworkNodeID. * @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 flags Send flags, see the UDS_SENDFLAG enum values.
* @param buf Input send buffer. * @param buf Input send buffer.
* @param size Size of the 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. * @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 network The NetworkStruct, you can use udsGenerateDefaultNetworkStruct() for generating this.
* @param passphrase Raw input passphrase buffer. * @param passphrase Raw input passphrase buffer.
* @param passphrase_size Size of the 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. * @brief Connect to a network.
* @param network The NetworkStruct, you can use udsScanBeacons() for this. * @param network The NetworkStruct, you can use udsScanBeacons() for this.
* @param passphrase Raw input passphrase buffer. * @param passphrase Raw input passphrase buffer.
* @param passphrase_size Size of the 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 recv_NetworkNodeID This is the NetworkNodeID passed to udsBind() internally.
* @param connection_type Type of connection, see the udsConnectionType enum values. * @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. * @brief Stop hosting the network.

View File

@ -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_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_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_Unbind(udsBindContext *bindcontext);
static Result udsipc_DecryptBeaconData(udsNetworkStruct *network, u8 *tag0, u8 *tag1, udsNodeInfo *out); 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; 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; Result ret=0;
@ -253,14 +253,14 @@ Result udsCreateNetwork(const udsNetworkStruct *network, const void *passphrase,
ret = udsipc_BeginHostingNetwork(network, passphrase, passphrase_size); ret = udsipc_BeginHostingNetwork(network, passphrase, passphrase_size);
if(R_FAILED(ret))return ret; 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(); if(R_FAILED(ret))udsDestroyNetwork();
return ret; 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; Result ret=0;
bool spectator=false; bool spectator=false;
@ -271,7 +271,7 @@ Result udsConnectNetwork(const udsNetworkStruct *network, const void *passphrase
ret = udsipc_ConnectToNetwork(network, passphrase, passphrase_size, connection_type); ret = udsipc_ConnectToNetwork(network, passphrase, passphrase_size, connection_type);
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
//printf("bind...\n"); //printf("bind...\n");
ret = udsBind(context, recv_NetworkNodeID, spectator); if(context)ret = udsBind(context, recv_NetworkNodeID, spectator, data_channel);
if(R_FAILED(ret))udsDisconnectNetwork(); if(R_FAILED(ret))udsDisconnectNetwork();
@ -532,7 +532,7 @@ Result udsScanBeacons(void *buf, size_t maxsize, udsNetworkScanInfo **networks,
return ret; return ret;
} }
Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID, bool spectator) Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID, bool spectator, u8 data_channel)
{ {
u32 pos; u32 pos;
@ -559,7 +559,7 @@ Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID, bool spectator)
bindcontext->spectator = spectator; bindcontext->spectator = spectator;
return udsipc_Bind(bindcontext, 0x2e30, 0xf3, NetworkNodeID); return udsipc_Bind(bindcontext, 0x2e30, data_channel, NetworkNodeID);
} }
Result udsUnbind(udsBindContext *bindcontext) Result udsUnbind(udsBindContext *bindcontext)
@ -790,14 +790,14 @@ Result udsGetNetworkStructApplicationData(const udsNetworkStruct *network, void
return 0; 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(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=IPC_MakeHeader(0x12,4,0); // 0x120100 cmdbuf[0]=IPC_MakeHeader(0x12,4,0); // 0x120100
cmdbuf[1]=bindcontext->BindNodeID; cmdbuf[1]=bindcontext->BindNodeID;
cmdbuf[2]=input0; cmdbuf[2]=input0;
cmdbuf[3]=input1; cmdbuf[3]=data_channel;
cmdbuf[4]=NetworkNodeID; cmdbuf[4]=NetworkNodeID;
Result ret=0; Result ret=0;
@ -863,7 +863,7 @@ Result udsPullPacket(const udsBindContext *bindcontext, void *buf, size_t size,
return ret; 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(); 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[0]=IPC_MakeHeader(0x17,6,2); // 0x170182
cmdbuf[1]=0x1;//Unused cmdbuf[1]=0x1;//Unused
cmdbuf[2]=dst_NetworkNodeID; cmdbuf[2]=dst_NetworkNodeID;
cmdbuf[3]=netflags; cmdbuf[3]=data_channel;
cmdbuf[4]=aligned_size>>2; cmdbuf[4]=aligned_size>>2;
cmdbuf[5]=size; cmdbuf[5]=size;
cmdbuf[6]=flags; cmdbuf[6]=flags;