/*---------------------------------------------------------------------------* Project: Horizon File: uds_Api.h Copyright (C) 2009-2011 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 54504 $ *---------------------------------------------------------------------------*/ #ifndef INCLUDE_NN_UDS_CAFE_UDS_API_H_ #define INCLUDE_NN_UDS_CAFE_UDS_API_H_ /*! @file @brief These are members of the UDS Library. */ #include #include #ifdef NN_UDS_SUPPORT_CLIENT #include #endif #include namespace nn { namespace uds { namespace Cafe { /*! @ingroup nn_uds @defgroup nn_uds_api Local Communication (UDS) API @brief This file lists Local Communication (UDS) library API members. (Includes only C++ API members.) @{ */ /*! @name Initialization and Shutdown @{ */ /*! @brief Initializes the UDS library. Initialization fails if any other communication features are already in use. Background communications are terminated and execution is blocked for 120 to 150 msec so the UDS library can take ownership of the communication device until @ref Finalize executes. Always call the @ref Finalize function to release the communication device after you are finished using the UDS library.
This function is thread-unsafe. @param[in] receiveBuffer Pointer to the start of the receive buffer used by the UDS library. Specify a buffer aligned to 64 bytes. Access to the memory region specified by the buffer is prohibited until the @ref Finalize function completes. @param[in] bufferSize The size of the receive buffer. Specify a value greater than ATTACH_BUFFER_SIZE_MIN that is a multiple of 64. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that initialization succeeded. @retval ResultAlreadyOccupiedWirelessDevice Indicates that communication is already taking place. New UDS communication cannot begin. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. */ nn::Result Initialize( void* receiveBuffer, const size_t bufferSize); /*! @brief Initializes the UDS library. Initialization fails if any other communication features are already in use. Background communications are terminated and execution is blocked for 120 to 150 msec so the UDS library can take ownership of the communication device until @ref Finalize executes. Always call the @ref Finalize function to release the communication device after you are finished using the UDS library.
Handle the user name specified by pUserName according to UGC guidelines.
This function is thread-unsafe. @param[in] receiveBuffer Pointer to the start of the receive buffer used by the UDS library. Specify a buffer aligned to 64 bytes. Access to the memory region specified by the buffer is prohibited until the @ref Finalize function completes. @param[in] bufferSize The size of the receive buffer. Specify a value that is a multiple of 64. @param[in] pUserName The user name. Handle user names according to UGC guidelines. If you specify NULL, the function uses the Mii character name of the account that is logged in. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that initialization succeeded. @retval ResultAlreadyOccupiedWirelessDevice Indicates that communication is already taking place. New UDS communication cannot begin. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. */ nn::Result Initialize( void* receiveBuffer, const size_t bufferSize, nn::cfg::CTR::UserName* pUserName); /*! @brief Finalizes the UDS library. After executing, other communication features become usable. Blocks for 50 to 60 milliseconds. Releases the communication device held by the @ref Initialize function. The receive buffer specified by the @ref Initialize function can be accessed from the application after this function's execution completes.
Finalizes the event received by the @ref Initialize function, which is used to send notifications of connection status updates. Destroys an endpoint that has not been destroyed.
The buffer allocated by the @ref Attach function is released.
This function is thread-unsafe. @return None. */ void Finalize (); /*! @} */ /*! @name Networks (Creating, Destroying, Connecting, and Disconnecting) @{ */ /*! @brief Creates a local communication ID from a unique ID. This uses a 20-bit unique ID assigned by Nintendo to generate a 32-bit value (a local communication ID) to use for UDS communication.
If Nintendo has not assigned a unique ID to you, use one of the unique IDs for game prototypes (in the range from 0xFF000 through 0xFF3FF).
However, you must get a unique ID from Nintendo for your retail product.
This function is thread-safe. @param[in] uniqueId The unique ID. To communicate between multiple titles, specify either of their unique IDs. @param[in] isDemo This flag is used when the same unique ID is used for both the retail and demo versions. Specify true for the demo if you do not want communication between the retail product and downloadable demo versions. Note: Always set this flag to false in retail builds. @return Returns the local communication ID. */ bit32 CreateLocalCommunicationId( bit32 uniqueId, bool isDemo = false); /*! @brief Creates a new network. This function blocks for a period of 100 to 120 milliseconds until automatic channel selection is complete.
This function is thread-safe. @param[in] subId Specifies the ID for identifying the communication mode. Set this parameter to a value between 0x00 and 0xFE. @param[in] maxEntry Specifies the maximum number of nodes that can connect to the network. This value can be up to @ref NODE_MAX, including the local device. @param[in] localId Specifies the local communication ID. Specify the value generated by @ref CreateLocalCommunicationId. @param[in] passphrase Specifies the string holding the seed of the passphrase to use for wireless layer encryption. With UDS, communication can only be established if uniqueId and passphrase match. @param[in] passphraseLength Specifies the passphrase length. Specify a value that is at least IR_PASSPHRASE_LENGTH_MIN, but no larger than IR_PASSPHRASE_LENGTH_MAX. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates the node successfully established local communication and began operating as a host. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state other than @ref STATE_DISCONNECTED. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultNotAuthorized Indicates an invalid value for localId. Specify the value generated by @ref CreateLocalCommunicationId. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. */ nn::Result CreateNetwork( u8 subId, u8 maxEntry, bit32 localId, const char passphrase[], size_t passphraseLength ); /*! @brief Sets application data in the beacon and builds a new network. This function blocks for a period of 100 to 120 milliseconds until automatic channel selection is complete.
This API function allows you to set application data in the beacon when building the network. To update the beacon's application data after the network has been built, use the @ref SetApplicationDataToBeacon function. The maximum size of this application data is @ref NET_DESC_APPDATA_SIZE_MAX bytes. The data is not encrypted. It can be collected by any general-purpose computing device, such as a desktop computer. Other devices can get this data by calling Scan while they are connected as a Client or Spectator.
This function is thread-safe. @param[in] subId Specifies the ID for identifying the communication mode. Set this parameter to a value between 0x00 and 0xFE. @param[in] maxEntry Specifies the maximum number of nodes that can connect to the network. This value can be up to @ref NODE_MAX, including the local device. @param[in] localId Specifies the local communication ID. Specify the value generated by @ref CreateLocalCommunicationId. @param[in] passphrase Specifies the string holding the seed of the passphrase to use for wireless layer encryption. With UDS, communication can only be established if uniqueId and passphrase match. @param[in] passphraseLength Specifies the passphrase length. Specify a value that is at least IR_PASSPHRASE_LENGTH_MIN, but no larger than IR_PASSPHRASE_LENGTH_MAX. @param[in] pData Specifies a pointer to the application data to set in the beacon. @param[in] dataSize Specifies the size of the application data to set in the beacon. Specify a value no greater than @ref NET_DESC_APPDATA_SIZE_MAX. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the node successfully established local communication and began operating as a host. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state other than @ref STATE_DISCONNECTED. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultNotAuthorized Indicates an invalid value for localId. Specify the value generated by @ref CreateLocalCommunicationId. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. @retval ResultTooLarge Indicates that dataSize is greater than @ref NET_DESC_APPDATA_SIZE_MAX. @retval ResultInvalidPointer Indicates that pData is NULL. NULL is allowed when dataSize is 0. */ nn::Result CreateNetwork( u8 subId, u8 maxEntry, bit32 localId, const char passphrase[], size_t passphraseLength, const void* pData, size_t dataSize ); /*! @brief Creates a new network. This function is provided for debugging purposes, and can be used to specify the channel to use for wireless communication during development. The channel argument is ignored in production mode. This function blocks for a period of 100 to 120 milliseconds until automatic channel selection is complete.
This function is thread-safe. @param[in] subId Specifies the ID for identifying the communication mode. Set this parameter to a value between 0x00 and 0xFE. @param[in] maxEntry Specifies the maximum number of nodes that can connect to the network. This value can be up to @ref NODE_MAX, including the local device. @param[in] localId Specifies the local communication ID. Specify the value generated by @ref CreateLocalCommunicationId. @param[in] passphrase Specifies the string holding the seed of the passphrase to use for wireless layer encryption. With UDS, communication can only be established if uniqueId and passphrase match. @param[in] passphraseLength Specifies the passphrase length. Specify a value that is at least IR_PASSPHRASE_LENGTH_MIN, but no larger than IR_PASSPHRASE_LENGTH_MAX. @param[in] channel Specifies the channel to use for communication. Specify channel 0 (automatic), 1, 6, or 11. When this function runs in production mode, the channel is always selected automatically. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the node successfully established local communication and began operating as a host. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state other than @ref STATE_DISCONNECTED. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultNotAuthorized Indicates an invalid value for localId. Specify the value generated by @ref CreateLocalCommunicationId. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultInvalidPointer Indicates that pData is NULL. NULL is allowed when dataSize is 0. */ nn::Result CreateNetwork( u8 subId, u8 maxEntry, bit32 localId, const char passphrase[], size_t passphraseLength, u8 channel ); /*! @brief Sets application data in the beacon and builds a new network. This function is provided for debugging purposes, and can be used to specify the channel to use for wireless communication during development. The channel argument is ignored in production mode. This function blocks for a period of 100 to 120 milliseconds until automatic channel selection is complete.
This API function allows you to set application data in the beacon when building the network. To update the beacon's application data after the network has been built, use the @ref SetApplicationDataToBeacon function. The maximum size of this application data is @ref NET_DESC_APPDATA_SIZE_MAX bytes. The data is not encrypted. It can be collected by any general-purpose computing device, such as a desktop computer. Other devices can get this data by calling Scan while they are connected as a Client or Spectator.
This function is thread-safe. @param[in] subId Specifies the ID for identifying the communication mode. Set this parameter to a value between 0x00 and 0xFE. @param[in] maxEntry Specifies the maximum number of nodes that can connect to the network. This value can be up to @ref NODE_MAX, including the local device. @param[in] localId Specifies the local communication ID. Specify the value generated by @ref CreateLocalCommunicationId. @param[in] passphrase Specifies the string holding the seed of the passphrase to use for wireless layer encryption. With UDS, communication can only be established if uniqueId and passphrase match. @param[in] passphraseLength Specifies the passphrase length. Specify a value that is at least IR_PASSPHRASE_LENGTH_MIN, but no larger than IR_PASSPHRASE_LENGTH_MAX. @param[in] channel Specifies the channel to use for communication. Specify channel 0 (automatic), 1, 6, or 11. In production mode, the channel is always selected automatically. @param[in] pData Specifies a pointer to the application data to set in the beacon. @param[in] dataSize Specifies the size of the application data to set in the beacon. Specify a value no greater than @ref NET_DESC_APPDATA_SIZE_MAX. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the node successfully established local communication and began operating as a host. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state other than @ref STATE_DISCONNECTED. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultNotAuthorized Indicates an invalid value for localId. Specify the value generated by @ref CreateLocalCommunicationId. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. @retval ResultTooLarge Indicates that dataSize is greater than @ref NET_DESC_APPDATA_SIZE_MAX. @retval ResultInvalidPointer Indicates that pData is NULL. NULL is allowed when dataSize is 0. */ nn::Result CreateNetwork( u8 subId, u8 maxEntry, bit32 localId, const char passphrase[], size_t passphraseLength, u8 channel, const void* pData, size_t dataSize ); #ifdef NN_UDS_SUPPORT_CLIENT /*! @brief Scans for nearby networks. By default, this feature requires 330 ms to complete. This function is thread-safe. @param[out] pBuffer Specifies the buffer for storing information about discovered networks. @param[in] bufferSize Specifies the size of the buffer. Estimate roughly 1 KB per network. @param[in] subId Specifies the ID used to identify the arbitrary communication mode set by the application. Specify 0xff to search all SubIDs. @param[in] localId Specifies the local communication ID. Specify the value generated by @ref CreateLocalCommunicationId. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that local communication was successfully established and the located network information was stored in the buffer. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state other than STATE_DISCONNECTED. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultWirelessOff Indicates that the device entered wireless off mode. Reinitialization is required. @retval Other Indicates failure for other reasons. */ nn::Result Scan( void* pBuffer, size_t bufferSize, u8 subId, bit32 localId ); /*! :private @brief Scans for nearby networks. This feature is only used in special circumstances such as when a scan channel must be specified. By default, this feature requires 330 ms to complete. This function is thread-safe. @param[out] pBuffer Specifies the buffer for storing information about discovered networks. @param[in] bufferSize Specifies the size of the buffer. Estimate roughly 1 KB per network. @param[in] subId Specifies the ID used to identify the arbitrary communication mode set by the application. Specify 0xff to search all SubIDs. @param[in] localId Specifies the local communication ID. Specify the value generated by @ref CreateLocalCommunicationId. @param[in] channel By default, the function scans all channels used by UDS. Only set this value when you want to scan a specific channel. (0: Scans all channels used by UDS: 1, 6, and 11.) @param[in] scanTime Specifies the scan time per channel. There is normally no need to specify this. (0: 110 milliseconds) @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that local communication was successfully established and the located network information was stored in the buffer. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state other than STATE_DISCONNECTED. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultWirelessOff Indicates that the device entered wireless off mode. Reinitialization is required. @retval Other Indicates failure for other reasons. */ nn::Result Scan( void* pBuffer, size_t bufferSize, u8 subId, bit32 localId, u8 channel, u16 scanTime = 0 ); /*! @brief Connects to an existing network. Connection takes longer when the signal strength is poor. Up to approximately 800 ms is required until completion. This function is thread-safe. @param[in] networkDescription Specifies network information. This is obtained from the scanning results. @param[in] type Specifies the network type. @param[in] passphrase Specifies the passphrase to use for wireless layer encryption. With UDS, communication can only be established if uniqueId and passphrase match. @param[in] passphraseLength Specifies the passphrase length. Specify a value that is at least IR_PASSPHRASE_LENGTH_MIN, but no larger than IR_PASSPHRASE_LENGTH_MAX. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the connection succeeded and operations began for the specified connection type. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultNotFoundNetwork Indicates that the connection target network was not found. Returned when the network has already been destroyed or when it is outside the range of communications. @retval ResultAlreadyNetworkIsFull Indicates the number of network nodes has already reached the maximum number of connections. You cannot connect unless you reduce the number of nodes. @retval ResultDeniedFromMaster Indicates that the host denied the connection. Returned when the host has denied a connection to the network. Also returned when the passphrase is in error. @retval ResultConnectionTimeout Indicates that the connection was not established in time. Returned when the signal strength is bad or when there is excessive load on the host. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state other than STATE_DISCONNECTED. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultWirelessOff Indicates that the device entered wireless off mode. Reinitialization is required. @retval Other Indicates failure for other reasons. */ nn::Result ConnectNetwork( const NetworkDescription& networkDescription, ConnectType type, const char passphrase[], size_t passphraseLength ); #endif /*! @brief Kicks the specified node off the network. Only the host can call this function. This function is thread-safe. @param[in] nodeId The ID of the node being added. If @ref BROADCAST_NODE_ID is specified, all connected nodes are disconnected. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates the specified node was removed from the network. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when executed in a state other than host. @retval ResultNotAuthorized Indicates the node ID of the host was specified. */ nn::Result EjectClient ( u16 nodeId ); /*! @brief Prevents client nodes from connecting to the network. Does not affect clients that are currently connected. The intended use of this feature is to deny connections by new clients after an online game has started. When you want to allow connections again, call the @ref AllowToConnect function. Only the host can call this function.
This function is thread-safe. @param[in] isDisallowToReconnect If set to false, only the clients that were disconnected after calling this function can reconnect. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. */ nn::Result DisallowToConnect(bool isDisallowToReconnect = false); /*! @brief Allows the client to connect to the network. This function is used to connects a client denied connection by the @ref DisallowToConnect function. This function does not clear the spectator's denied connection state resulting from the @ref EjectSpectator function. Only the host can call this function.
This function is thread-safe. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. */ nn::Result AllowToConnect(); /*! @brief Kicks all connected spectators off the network. New spectators cannot connect after you execute this function. To allow Spectator nodes to connect again, call the @ref AllowToSpectate function. Only the host can call this function.
This function is thread-safe. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when executed in a state other than host. */ nn::Result EjectSpectator( void ); /*! @brief Allows the spectator to connect to the network. Use this function when you want to reconnect a Spectator to the network after executing the @ref EjectSpectator function.
This function is thread-safe. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. */ nn::Result AllowToSpectate(); /*! @brief Destroys the network. All connected clients and spectators are released and the network is destroyed. Only the host can call this function. When you call this function, a disconnect request packet is sent to clients and spectators and they immediately disconnect from the network. At this time, the @ref GetConnectionStatus function returns DISCARDED_FROM_NETWORK as the reason for disconnection (DisconnectReason). However, depending on the communications environment, there may be times when the disconnect request packet does not reach clients and spectators. In this case, they are disconnected roughly one second after this function is called. In this case, the reason for disconnection is CONNECTION_LOST.
This function is thread-safe. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the network was destroyed and the node transitioned to the STATE_DISCONNECTED state. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when executed in a state other than host. */ nn::Result DestroyNetwork ( void ); #ifdef NN_UDS_SUPPORT_CLIENT /*! @brief Disconnects the local node from the network. Only clients and spectators can call this function. This function also succeeds when the node is not connected to the network, because the node may have already been disconnected (because of external factors, for example). This function is thread-safe. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the network was destroyed and the node transitioned to the STATE_DISCONNECTED state. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when executed in a state other than host. @retval ResultWirelessOff Indicates that the device entered wireless off mode. Reinitialization is required. @retval Other Indicates failure for other reasons. */ nn::Result DisconnectNetwork ( void ); #endif /*! @} */ /*! @name Functions for Sending and Receiving Data @{ */ /*! @brief Creates a network endpoint and returns the corresponding descriptor. [Provisional spec] Currently, up to 16 endpoints can be created.
This function is thread-safe. @param[out] pEndpointDesc Descriptor indicating the endpoint to create. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultOutOfResource More than the stipulated number of endpoints were already generated. Destroy an existing endpoint. */ nn::Result CreateEndpoint( EndpointDescriptor* pEndpointDesc ); /*! @brief Specifies the maximum send delay time. For the system to improve the efficiency of its physical layer, smaller packets are sent bundled together. As a result, when the maximum amount of data is sent by the @ref SendTo function, it may wait up to the amount of time set by this function. When minimizing latency is more important than communication efficiency, you can specify @ref NO_WAIT to the @ref SendTo function to avoid this delay in sending data. This can be executed only when not connected to the network.
This function is thread-safe. @param[in] maxDelay Specifies the maximum latency. Specify a value in the range from 5 to 100 milliseconds. The default is 10 milliseconds. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when executed while communicating. */ nn::Result SetMaxSendDelay ( nn::fnd::TimeSpan maxDelay ); /*! @brief Sends data to the specified port on the specified partner's system. This function blocks until it has finished sending data. The send method can be specified by setting option to @ref NO_WAIT or @ref FORCE_DIRECT_BC. To specify multiple options, you can OR multiple values.
This function is thread-safe. @param[in] endpointDesc Specifies a descriptor indicating the endpoint to use. @param[in] data Specifies a pointer to the data to send. Processing efficiency is better if the buffer is on a 64-byte address boundary, and its size is a multiple of 64 bytes. @param[in] dataSize Specifies the size of the data to send (in bytes). The maximum size of the data to send is @ref UDS_PACKET_PAYLOAD_MAX_SIZE bytes. @param[in] destNodeId Specifies the recipient. Specify @ref BROADCAST_NODE_ID to broadcast the data. @param[in] port Specifies the port to assign. Port 0x00 is reserved by the system and cannot be used. @param[in] option Specifies the send options. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when this function is executed by a local device acting as other than a host or client. @retval ResultTooLarge Indicates that dataSize is greater than @ref UDS_PACKET_PAYLOAD_MAX_SIZE. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultBufferIsFull Indicates that packets exceeding the transmission capacity of the wireless device were sent when the NO_WAIT option was specified. This result can occur more frequently when the signal strength is bad. @retval ResultMisalignedAddress Indicates that the value of data is invalid. The function may succeed if you execute it again with a suitable value for the argument. You might succeed by retrying, but if this errors occurs frequently, try specifying a larger buffer size with the @ref Initialize function. */ nn::Result SendTo ( const EndpointDescriptor& endpointDesc, const void* data, size_t dataSize, u16 destNodeId, u8 port, bit8 option = 0x00 ); /*! @brief Enables the local device to receive packets from the endpoint. Assigns the specified port and node ID to the endpoint. The system creates a receive buffer and prepares to receive packets at the port specified below.
This function is thread-safe. @param[in] pEndpointDesc Specifies a descriptor indicating the endpoint to use. @param[in] srcNodeId Specifies the node ID being assigned. Specify @ref BROADCAST_NODE_ID to attach all nodes. @param[in] port Specifies the port being assigned. Port 0x00 is reserved by the system and cannot be used. @param[in] receiveBufferSize Specifies the size of the receive buffer being allocated. Memory is allocated from the memory block retrieved by the @ref Initialize function. Do not try to allocate a receive buffer larger than that total. You must specify at least @ref ATTACH_BUFFER_SIZE_MIN bytes. The default value is @ref ATTACH_BUFFER_SIZE_DEFAULT bytes. Communication is most efficient when the specified data size is a multiple of 64. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultOutOfResource The buffer specified with the @ref Initialize function was insufficient. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. */ nn::Result Attach ( EndpointDescriptor* pEndpointDesc, u16 srcNodeId, u8 port, size_t receiveBufferSize = ATTACH_BUFFER_SIZE_DEFAULT ); /*! @brief Receives data. (No functionality is provided for getting the address of the sender.) Other than the parameters, this function is the same as @ref ReceiveFrom. For more information, see the @ref ReceiveFrom function reference.
This function is thread-safe. @param[in] endpointDesc Specifies a descriptor indicating the endpoint to use. The port and sender must be attached in advance using the @ref Attach function. @param[out] pBuffer Specifies the location to store received data. It is efficient to specify a buffer that is 64-byte aligned. @param[out] pReceivedSize Specifies the size of the received data. The UDS maximum received data size is @ref UDS_PACKET_PAYLOAD_MAX_SIZE bytes. @param[in] bufferSize Specifies the size (in bytes) of the receive buffer (pBuffer). It is efficient to specify a multiple of 64. @param[in] option Specifies the receive options. Specifying @ref NO_WAIT causes the function to return immediately, even if no data has been received. If not specified, the function does not return until either it receives data or an error occurs. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the specified endpoint did not exist when the library was not initialized. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returns that it was executed in a state where it was not connected to the network. @retval ResultNotAuthorized Indicates that an endpoint that was not attached was specified. @retval ResultTooLarge Indicates that the bufferSize was smaller than the received data. The best size is @ref UDS_PACKET_PAYLOAD_MAX_SIZE. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultMisalignedSize Invalid bufferSize. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultMisalignedAddress The value of pBuffer is invalid. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultBusy Packet reception with the specified endpoint is in progress. Call after the previous reception process finishes. You might succeed by retrying, but if this errors occurs frequently, try specifying a larger buffer size with the @ref Initialize function. */ nn::Result Receive ( const EndpointDescriptor& endpointDesc, void* pBuffer, size_t* pReceivedSize, size_t bufferSize, bit8 option = 0x00 ); /*! @brief Receives data. Receives packets sent to an endpoint for which the @ref Attach function was executed. This function blocks when there are no packets to receive. (Unless an error occurs.) The function exits even if it does not receive packets if @ref NO_WAIT is specified in option.
This function is thread-safe. @param[in] endpointDesc Specifies a descriptor indicating the endpoint to use. The port and sender must be attached in advance using the @ref Attach function. @param[out] pBuffer Specifies the location to store received data. It is efficient to specify a buffer that is 64-byte aligned. @param[out] pReceivedSize Specifies the size of the received data. The UDS maximum received data size is @ref UDS_PACKET_PAYLOAD_MAX_SIZE bytes. @param[out] pSrcNodeId The ID of the sending node. @param[in] bufferSize Specifies the size (in bytes) of the receive buffer (pBuffer). It is efficient to specify a multiple of 64. @param[in] option Specifies the receive options. Specifying @ref NO_WAIT causes the function to return immediately, even if no data has been received. If not specified, the function does not return until either it receives data or an error occurs. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the specified endpoint did not exist when the library was not initialized. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state where it was not connected to the network. @retval ResultNotAuthorized Indicates that an endpoint that was not attached was specified. @retval ResultTooLarge Indicates that the bufferSize was smaller than the received data. The best size is @ref UDS_PACKET_PAYLOAD_MAX_SIZE. @retval ResultOutOfRange Indicates that an argument was outside of the allowed range. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultMisalignedSize Invalid bufferSize. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultMisalignedAddress The value of pBuffer is invalid. The function may succeed if you execute it again with a suitable value for the argument. @retval ResultBusy Packet reception with the specified endpoint is in progress. Call after the previous reception process finishes. You might succeed by retrying, but if this errors occurs frequently, try specifying a larger buffer size with the @ref Initialize function. */ nn::Result ReceiveFrom ( const EndpointDescriptor& endpointDesc, void* pBuffer, size_t* pReceivedSize, u16* pSrcNodeId, size_t bufferSize, bit8 option = 0x00 ); /*! @brief Destroys an endpoint. Frees the receive buffer if the @ref Attach function has been called with the specified endpoint. The freed receive buffer can be reused with the @ref Attach function, but note that the application can only access it after the @ref Finalize function is executed.
This function is thread-safe. @param[in] pEndpointDesc Descriptor indicating the endpoint. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultNotAuthorized Indicates that an invalid endpoint descriptor was specified. */ nn::Result DestroyEndpoint( EndpointDescriptor* pEndpointDesc ); /*! @} */ /*! @name Functions for detecting state changes and getting information @{ */ /*! @brief Gets the current connection status. Calling this function is sufficient only when the @ref PollStateChange function succeeds (that is, when there is a change in the state).

This function is thread-safe. @param[out] pStatus The current connection status. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. */ nn::Result GetConnectionStatus( ConnectionStatus* pStatus ); /*! @brief Gets the current channel. This function is thread-safe. @param[out] pChannel Returns the channel. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Execute the nn::uds::Initialize function. */ nn::Result GetChannel(u8* pChannel); /*! @brief Gets information about the specified node. This function is thread-safe. @param[out] pNodeInfo Information about the node. @param[in] nodeId The ID of the target node. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidNode The target node does not exist on the network. You might be disconnected. */ nn::Result GetNodeInformation ( NodeInformation* pNodeInfo, u16 nodeId ); /*! @brief Queries whether a host has changed status or a client has connected or disconnected. Excluding the case when NO_WAIT is specified in the option parameter, this API does not return until there is a change in the state.
This function is thread-safe. When NO_WAIT is specified, returns the result without blocking. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess The state has changed. For more information about the state, see the @ref GetConnectionStatus function. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultNotFound The state has not changed. Returned only when NO_WAIT is specified in the option parameter. @retval ResultBusy Called by another thread. Call after the previous call completes. */ nn::Result PollStateChange(u8 option); /*! @} */ /*! @name Accessors for Beacon Application Data @{ */ /*! @brief Sets application data in the beacon. Specifies up to @ref NET_DESC_APPDATA_SIZE_MAX bytes of application data. The data is not encrypted. It can be collected by any general-purpose computing device, such as a desktop computer. Other devices can get this data by calling Scan while they are connected as a Client or Spectator. Only the host can run this function.
This function is thread-safe. @param[in] pData Pointer to data being set. @param[in] dataSize Size of the data to set. Specify a value no greater than @ref NET_DESC_APPDATA_SIZE_MAX. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state other than host. @retval ResultTooLarge Indicates that dataSize is greater than @ref NET_DESC_APPDATA_SIZE_MAX. @retval ResultOutOfResource Indicates that the system is out of resources. Try again. @retval ResultBusy Indicates that the system is busy. Try again. */ nn::Result SetApplicationDataToBeacon ( const void* pData, size_t dataSize ); /*! @brief Gets the data set in the beacon. The host gets the data set using the @ref SetApplicationDataToBeacon function. This function can only be run when connected to the network. There is no notification if the data is updated.
This function is thread-safe. @param[out] pBuffer Specifies the location storing the data. @param[out] pDataSize Specifies the size of the data. Returns 0 when the bufferSize was smaller than the received data. @param[in] bufferSize Specifies the size of the buffer. The sender can freely change the size of the data. In general, specify @ref NET_DESC_APPDATA_SIZE_MAX bytes. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultInvalidState Indicates that the function cannot be executed in this state. Returned when the function is executed in a state where it was not connected to the network. */ nn::Result GetApplicationDataFromBeacon ( void* pBuffer, size_t* pDataSize, size_t bufferSize ); /*! @} */ /*! @} */ #ifdef NN_UDS_SUPPORT_POWER_SAVE /*! :private @brief Changes the power-saving mode. (This has not yet been implemented.) This setting can only be changed for a host. Clients and spectators follow the host's settings. This function is not yet implemented. It always fails if run. After the feature is implemented, you can dynamically change to a power-save mode during communications. Do not change the mode very frequently (more frequently than once every few seconds).

This function is thread-safe. @param[in] mode The power-saving mode. Enabling a power-saving mode may cause a slight decline in connectivity. @return Returns the result of the function. Returns one of the following Result values. @retval ResultNotImplemented Not yet implemented. */ nn::Result SetPowerSaveMode(PowerSaveMode mode); #endif namespace detail{ #if 0 /*! :private @brief Gets the detailed signal intensity. Do not use this function on retail consoles as it is only provided for use on development hardware to aid development. Communication is negatively affected if this function is called too frequently. Execute it about once per second. This function is thread-safe. @param[out] info The signal intensity. Stores data if the function succeeds. @return Returns the result of the function. If execution succeeds, the function stores data in info and returns a value for which @ref nn::Result::IsSuccess returns true. */ nn::Result GetRadioStrengthInfo(RadioStrengthInfo* info); #endif /*! :private @brief Destroys an endpoint. The receive buffer created when Attach was called is freed at this time. This function is used for debugging purposes. It allows you to get information about packets lost because of UDS receive buffer overflow, even when wireless transfer has succeeded.
This function is thread-safe. @param[in] pEndpoint Descriptor indicating the endpoint. @param[out] pReport Information about packets that arrived at the destroyed endpoint. @return Returns the result of the function. Returns one of the following Result values. @retval Result::IsSuccess Indicates that the operation succeeded. @retval ResultNotInitialized Indicates that the library is not initialized. Call the @ref Initialize function. @retval ResultNotAuthorized Indicates that an invalid endpoint descriptor was specified. */ nn::Result DestroyEndpoint( EndpointDescriptor* pEndpointDesc, ReceiveReport* pReport ); } // end of namespace detail } // end of namespace Cafe } // end of namespace uds } // end of namespace nn #endif // ifndef INCLUDE_NN_UDS_CAFE_UDS_API_H_