libnx  v4.2.0
nifm.h
Go to the documentation of this file.
1 /**
2  * @file nifm.h
3  * @brief Network interface service IPC wrapper.
4  * @author shadowninja108, shibboleet, exelix, yellows8
5  * @copyright libnx Authors
6  */
7 
8 #pragma once
9 #include "../types.h"
10 #include "../sf/service.h"
11 #include "../kernel/event.h"
12 
13 typedef enum {
14  NifmServiceType_User = 0, ///< Initializes nifm:u.
15  NifmServiceType_System = 1, ///< Initializes nifm:s.
16  NifmServiceType_Admin = 2, ///< Initializes nifm:a.
18 
19 typedef enum {
20  NifmInternetConnectionType_WiFi = 1, ///< Wi-Fi connection is used.
21  NifmInternetConnectionType_Ethernet = 2, ///< Ethernet connection is used.
23 
24 typedef enum {
25  NifmInternetConnectionStatus_ConnectingUnknown1 = 0, ///< Unknown internet connection status 1.
26  NifmInternetConnectionStatus_ConnectingUnknown2 = 1, ///< Unknown internet connection status 2.
27  NifmInternetConnectionStatus_ConnectingUnknown3 = 2, ///< Unknown internet connection status 3 (conntest?).
28  NifmInternetConnectionStatus_ConnectingUnknown4 = 3, ///< Unknown internet connection status 4.
29  NifmInternetConnectionStatus_Connected = 4, ///< Internet is connected.
31 
32 typedef enum {
33  NifmRequestState_Invalid = 0, ///< Error.
34  NifmRequestState_Unknown1 = 1, ///< Not yet submitted or error.
35  NifmRequestState_OnHold = 2, ///< OnHold
36  NifmRequestState_Available = 3, ///< Available
37  NifmRequestState_Unknown4 = 4, ///< Unknown
38  NifmRequestState_Unknown5 = 5, ///< Unknown
40 
41 /// Request
42 typedef struct {
43  Service s; ///< IRequest
44  Event event_request_state; ///< First Event from cmd GetSystemEventReadableHandles, autoclear=true. Signaled when the RequestState changes.
45  Event event1; ///< Second Event from cmd GetSystemEventReadableHandles.
46 
47  NifmRequestState request_state; ///< \ref NifmRequestState from the GetRequestState cmd.
48  Result res; ///< Result from the GetResult cmd.
49 } NifmRequest;
50 
51 /// ClientId
52 typedef struct {
53  u32 id; ///< ClientId
54 } NifmClientId;
55 
56 /// IpV4Address
57 typedef struct {
58  u8 addr[4]; ///< IPv4 address, aka struct in_addr.
60 
61 /// IpAddressSetting
62 typedef struct {
63  u8 is_automatic; ///< Whether this setting is automatic. Ignored by \ref nifmGetCurrentIpConfigInfo.
64 
65  NifmIpV4Address current_addr; ///< Current address.
66  NifmIpV4Address subnet_mask; ///< Subnet Mask.
67  NifmIpV4Address gateway; ///< Gateway.
69 
70 /// DnsSetting
71 typedef struct {
72  u8 is_automatic; ///< Whether this setting is automatic. Ignored by \ref nifmGetCurrentIpConfigInfo.
73 
74  NifmIpV4Address primary_dns_server; ///< Primary DNS server.
75  NifmIpV4Address secondary_dns_server; ///< Secondary DNS server.
77 
78 /// ProxySetting
79 typedef struct {
80  u8 enabled; ///< Enables using the proxy when set.
81  u8 pad; ///< Padding
82  u16 port; ///< Port
83  char server[0x64]; ///< Server string, NUL-terminated.
84  u8 auto_auth_enabled; ///< Enables auto-authentication when set, which uses the following two strings.
85  char user[0x20]; ///< User string, NUL-terminated.
86  char password[0x20]; ///< Password string, NUL-terminated.
87  u8 pad2; ///< Padding
89 
90 /// IpSettingData
91 typedef struct {
92  NifmIpAddressSetting ip_address_setting; ///< \ref NifmIpAddressSetting
93  NifmDnsSetting dns_setting; ///< \ref NifmDnsSetting
94  NifmProxySetting proxy_setting; ///< \ref NifmProxySetting
95  u16 mtu; ///< MTU
97 
98 /// WirelessSettingData
99 typedef struct {
100  u8 ssid_len; ///< NifmSfWirelessSettingData::ssid_len
101  char ssid[0x21]; ///< NifmSfWirelessSettingData::ssid
102  u8 unk_x22; ///< NifmSfWirelessSettingData::unk_x21
103  u8 pad; ///< Padding
104  u32 unk_x24; ///< NifmSfWirelessSettingData::unk_x22
105  u32 unk_x28; ///< NifmSfWirelessSettingData::unk_x23
106  u8 passphrase[0x41]; ///< NifmSfWirelessSettingData::passphrase
107  u8 pad2[0x3]; ///< Padding
109 
110 /// SfWirelessSettingData
111 typedef struct {
112  u8 ssid_len; ///< SSID length.
113  char ssid[0x20]; ///< SSID string.
114  u8 unk_x21; ///< Unknown
115  u8 unk_x22; ///< Unknown
116  u8 unk_x23; ///< Unknown
117  u8 passphrase[0x41]; ///< Passphrase
119 
120 /// SfNetworkProfileData. Converted to/from \ref NifmNetworkProfileData.
121 typedef struct {
122  NifmIpSettingData ip_setting_data; ///< \ref NifmIpSettingData
123  Uuid uuid; ///< Uuid
124  char network_name[0x40]; ///< NUL-terminated Network Name string.
125  u8 unk_x112; ///< Unknown
126  u8 unk_x113; ///< Unknown
127  u8 unk_x114; ///< Unknown
128  u8 unk_x115; ///< Unknown
129  NifmSfWirelessSettingData wireless_setting_data; ///< \ref NifmSfWirelessSettingData
130  u8 pad; ///< Padding
132 
133 /// NetworkProfileData. Converted from/to \ref NifmSfNetworkProfileData.
134 typedef struct {
135  Uuid uuid; ///< NifmSfNetworkProfileData::uuid
136  char network_name[0x40]; ///< NifmSfNetworkProfileData::network_name
137  u32 unk_x50; ///< NifmSfNetworkProfileData::unk_x112
138  u32 unk_x54; ///< NifmSfNetworkProfileData::unk_x113
139  u8 unk_x58; ///< NifmSfNetworkProfileData::unk_x114
140  u8 unk_x59; ///< NifmSfNetworkProfileData::unk_x115
141  u8 pad[2]; ///< Padding
142  NifmWirelessSettingData wireless_setting_data; ///< \ref NifmWirelessSettingData
143  NifmIpSettingData ip_setting_data; ///< \ref NifmIpSettingData
145 
146 /// Initialize nifm. This is used automatically by gethostid().
148 
149 /// Exit nifm. This is used automatically by gethostid().
150 void nifmExit(void);
151 
152 /// Gets the Service object for the actual nifm:* service session.
154 
155 /// Gets the Service object for IGeneralService.
157 
158 /**
159  * @brief GetClientId
160  */
162 
163 /**
164  * @brief CreateRequest
165  * @param[out] r \ref NifmRequest
166  * @param[in] autoclear Event autoclear to use for NifmRequest::event1, a default of true can be used for this.
167  */
168 Result nifmCreateRequest(NifmRequest* r, bool autoclear);
169 
170 /**
171  * @brief GetCurrentNetworkProfile
172  * @param[out] profile \ref NifmNetworkProfileData
173  */
175 
176 /**
177  * @brief GetNetworkProfile
178  * @param[in] uuid Uuid
179  * @param[out] profile \ref NifmNetworkProfileData
180  */
182 
183 /**
184  * @brief SetNetworkProfile
185  * @note Only available with ::NifmServiceType_Admin.
186  * @param[in] profile \ref NifmNetworkProfileData
187  * @param[out] uuid Uuid
188  */
190 
191 /**
192  * @brief GetCurrentIpAddress
193  * @param[out] out IPv4 address (struct in_addr).
194  */
196 
197 /**
198  * @brief GetCurrentIpConfigInfo
199  * @param[out] current_addr Same as \ref nifmGetCurrentIpAddress output.
200  * @param[out] subnet_mask Subnet Mask (struct in_addr).
201  * @param[out] gateway Gateway (struct in_addr).
202  * @param[out] primary_dns_server Primary DNS server IPv4 address (struct in_addr).
203  * @param[out] secondary_dns_server Secondary DNS server IPv4 address (struct in_addr).
204  */
205 Result nifmGetCurrentIpConfigInfo(u32 *current_addr, u32 *subnet_mask, u32 *gateway, u32 *primary_dns_server, u32 *secondary_dns_server);
206 
207 /**
208  * @note Works only if called from nifm:a or nifm:s.
209  */
211 
212 Result nifmIsWirelessCommunicationEnabled(bool* out);
213 
214 /**
215  * @note Will fail with 0xd46ed if Internet is neither connecting or connected (airplane mode or no known network in reach).
216  * @param wifiStrength Strength of the Wi-Fi signal in number of bars from 0 to 3.
217  */
219 
220 Result nifmIsEthernetCommunicationEnabled(bool* out);
221 
222 /**
223  * @brief IsAnyInternetRequestAccepted
224  * @param[in] id \ref NifmClientId
225  */
227 
228 Result nifmIsAnyForegroundRequestAccepted(bool* out);
229 Result nifmPutToSleep(void);
230 Result nifmWakeUp(void);
231 
232 ///@name IRequest
233 ///@{
234 
235 /**
236  * @brief Close a \ref NifmRequest.
237  * @param r \ref NifmRequest
238  */
240 
241 /**
242  * @brief GetRequestState
243  * @param r \ref NifmRequest
244  * @param[out] out \ref NifmRequestState
245  */
247 
248 /**
249  * @brief GetResult
250  * @param r \ref NifmRequest
251  */
253 
254 /**
255  * @brief Cancel
256  * @param r \ref NifmRequest
257  */
259 
260 /**
261  * @brief Submit
262  * @param r \ref NifmRequest
263  */
265 
266 /**
267  * @brief SubmitAndWait
268  * @param r \ref NifmRequest
269  */
271 
272 /**
273  * @brief GetAppletInfo
274  * @note This is used by \ref nifmLaHandleNetworkRequestResult.
275  * @param r \ref NifmRequest
276  * @param[in] theme_color ThemeColor
277  * @param[out] buffer Output buffer for storage data.
278  * @param[in] size Output buffer size.
279  * @param[out] applet_id \ref AppletId
280  * @param[out] mode \ref LibAppletMode
281  * @param[out] out_size Total data size written to the output buffer.
282  */
283 Result nifmRequestGetAppletInfo(NifmRequest* r, u32 theme_color, void* buffer, size_t size, u32 *applet_id, u32 *mode, u32 *out_size);
284 
285 ///@}
286 
NifmInternetConnectionStatus_Connected
@ NifmInternetConnectionStatus_Connected
Internet is connected.
Definition: nifm.h:29
NifmIpSettingData::dns_setting
NifmDnsSetting dns_setting
NifmDnsSetting
Definition: nifm.h:93
NifmInternetConnectionStatus
NifmInternetConnectionStatus
Definition: nifm.h:24
NifmIpSettingData::ip_address_setting
NifmIpAddressSetting ip_address_setting
NifmIpAddressSetting
Definition: nifm.h:92
NifmWirelessSettingData::unk_x22
u8 unk_x22
NifmSfWirelessSettingData::unk_x21.
Definition: nifm.h:102
NifmRequestState_Unknown4
@ NifmRequestState_Unknown4
Unknown.
Definition: nifm.h:37
NifmServiceType_Admin
@ NifmServiceType_Admin
Initializes nifm:a.
Definition: nifm.h:16
nifmGetResult
Result nifmGetResult(NifmRequest *r)
GetResult.
NifmSfNetworkProfileData::unk_x115
u8 unk_x115
Unknown.
Definition: nifm.h:128
NifmClientId::id
u32 id
ClientId.
Definition: nifm.h:53
NifmRequest::s
Service s
IRequest.
Definition: nifm.h:43
NifmInternetConnectionStatus_ConnectingUnknown3
@ NifmInternetConnectionStatus_ConnectingUnknown3
Unknown internet connection status 3 (conntest?).
Definition: nifm.h:27
NifmNetworkProfileData::wireless_setting_data
NifmWirelessSettingData wireless_setting_data
NifmWirelessSettingData
Definition: nifm.h:142
u8
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
NifmRequestState
NifmRequestState
Definition: nifm.h:32
Event
Kernel-mode event structure.
Definition: event.h:13
nifmSetNetworkProfile
Result nifmSetNetworkProfile(const NifmNetworkProfileData *profile, Uuid *uuid)
SetNetworkProfile.
nifmGetRequestState
Result nifmGetRequestState(NifmRequest *r, NifmRequestState *out)
GetRequestState.
nifmGetCurrentNetworkProfile
Result nifmGetCurrentNetworkProfile(NifmNetworkProfileData *profile)
GetCurrentNetworkProfile.
NifmProxySetting::pad
u8 pad
Padding.
Definition: nifm.h:81
NifmRequest::request_state
NifmRequestState request_state
NifmRequestState from the GetRequestState cmd.
Definition: nifm.h:47
NifmSfWirelessSettingData::ssid_len
u8 ssid_len
SSID length.
Definition: nifm.h:112
NifmNetworkProfileData::unk_x54
u32 unk_x54
NifmSfNetworkProfileData::unk_x113.
Definition: nifm.h:138
NifmIpAddressSetting
IpAddressSetting.
Definition: nifm.h:62
nifmIsAnyInternetRequestAccepted
bool nifmIsAnyInternetRequestAccepted(NifmClientId id)
IsAnyInternetRequestAccepted.
nifmGetServiceSession_StaticService
Service * nifmGetServiceSession_StaticService(void)
Gets the Service object for the actual nifm:* service session.
NifmSfWirelessSettingData::unk_x23
u8 unk_x23
Unknown.
Definition: nifm.h:116
NifmInternetConnectionStatus_ConnectingUnknown2
@ NifmInternetConnectionStatus_ConnectingUnknown2
Unknown internet connection status 2.
Definition: nifm.h:26
nifmGetCurrentIpConfigInfo
Result nifmGetCurrentIpConfigInfo(u32 *current_addr, u32 *subnet_mask, u32 *gateway, u32 *primary_dns_server, u32 *secondary_dns_server)
GetCurrentIpConfigInfo.
NifmWirelessSettingData
WirelessSettingData.
Definition: nifm.h:99
nifmSetWirelessCommunicationEnabled
Result nifmSetWirelessCommunicationEnabled(bool enable)
NifmDnsSetting::secondary_dns_server
NifmIpV4Address secondary_dns_server
Secondary DNS server.
Definition: nifm.h:75
NifmNetworkProfileData::unk_x59
u8 unk_x59
NifmSfNetworkProfileData::unk_x115.
Definition: nifm.h:140
NifmIpSettingData::proxy_setting
NifmProxySetting proxy_setting
NifmProxySetting
Definition: nifm.h:94
nifmGetInternetConnectionStatus
Result nifmGetInternetConnectionStatus(NifmInternetConnectionType *connectionType, u32 *wifiStrength, NifmInternetConnectionStatus *connectionStatus)
NifmInternetConnectionType_Ethernet
@ NifmInternetConnectionType_Ethernet
Ethernet connection is used.
Definition: nifm.h:21
nifmRequestGetAppletInfo
Result nifmRequestGetAppletInfo(NifmRequest *r, u32 theme_color, void *buffer, size_t size, u32 *applet_id, u32 *mode, u32 *out_size)
GetAppletInfo.
NifmRequest::event1
Event event1
Second Event from cmd GetSystemEventReadableHandles.
Definition: nifm.h:45
nifmRequestCancel
Result nifmRequestCancel(NifmRequest *r)
Cancel.
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
NifmNetworkProfileData
NetworkProfileData. Converted from/to NifmSfNetworkProfileData.
Definition: nifm.h:134
NifmDnsSetting::primary_dns_server
NifmIpV4Address primary_dns_server
Primary DNS server.
Definition: nifm.h:74
NifmIpSettingData::mtu
u16 mtu
MTU.
Definition: nifm.h:95
NifmServiceType_System
@ NifmServiceType_System
Initializes nifm:s.
Definition: nifm.h:15
NifmInternetConnectionStatus_ConnectingUnknown4
@ NifmInternetConnectionStatus_ConnectingUnknown4
Unknown internet connection status 4.
Definition: nifm.h:28
nifmRequestSubmit
Result nifmRequestSubmit(NifmRequest *r)
Submit.
NifmSfNetworkProfileData::pad
u8 pad
Padding.
Definition: nifm.h:130
NifmSfNetworkProfileData::wireless_setting_data
NifmSfWirelessSettingData wireless_setting_data
NifmSfWirelessSettingData
Definition: nifm.h:129
NifmNetworkProfileData::unk_x58
u8 unk_x58
NifmSfNetworkProfileData::unk_x114.
Definition: nifm.h:139
NifmInternetConnectionStatus_ConnectingUnknown1
@ NifmInternetConnectionStatus_ConnectingUnknown1
Unknown internet connection status 1.
Definition: nifm.h:25
Result
u32 Result
Function error code result type.
Definition: types.h:44
NifmIpAddressSetting::gateway
NifmIpV4Address gateway
Gateway.
Definition: nifm.h:67
NifmIpSettingData
IpSettingData.
Definition: nifm.h:91
NifmIpAddressSetting::current_addr
NifmIpV4Address current_addr
Current address.
Definition: nifm.h:65
NifmWirelessSettingData::unk_x24
u32 unk_x24
NifmSfWirelessSettingData::unk_x22.
Definition: nifm.h:104
NifmProxySetting::enabled
u8 enabled
Enables using the proxy when set.
Definition: nifm.h:80
NifmRequest::res
Result res
Result from the GetResult cmd.
Definition: nifm.h:48
Uuid
Definition: types.h:48
NifmRequestState_Available
@ NifmRequestState_Available
Available.
Definition: nifm.h:36
nifmGetServiceSession_GeneralService
Service * nifmGetServiceSession_GeneralService(void)
Gets the Service object for IGeneralService.
nifmRequestClose
void nifmRequestClose(NifmRequest *r)
Close a NifmRequest.
NifmRequestState_Unknown1
@ NifmRequestState_Unknown1
Not yet submitted or error.
Definition: nifm.h:34
NifmRequestState_OnHold
@ NifmRequestState_OnHold
OnHold.
Definition: nifm.h:35
NifmProxySetting::auto_auth_enabled
u8 auto_auth_enabled
Enables auto-authentication when set, which uses the following two strings.
Definition: nifm.h:84
NifmSfNetworkProfileData
SfNetworkProfileData. Converted to/from NifmNetworkProfileData.
Definition: nifm.h:121
NifmNetworkProfileData::ip_setting_data
NifmIpSettingData ip_setting_data
NifmIpSettingData
Definition: nifm.h:143
NifmSfWirelessSettingData::unk_x22
u8 unk_x22
Unknown.
Definition: nifm.h:115
NifmWirelessSettingData::unk_x28
u32 unk_x28
NifmSfWirelessSettingData::unk_x23.
Definition: nifm.h:105
NifmProxySetting::port
u16 port
Port.
Definition: nifm.h:82
NifmInternetConnectionType_WiFi
@ NifmInternetConnectionType_WiFi
Wi-Fi connection is used.
Definition: nifm.h:20
NifmServiceType
NifmServiceType
Definition: nifm.h:13
NifmSfNetworkProfileData::ip_setting_data
NifmIpSettingData ip_setting_data
NifmIpSettingData
Definition: nifm.h:122
NifmRequest::event_request_state
Event event_request_state
First Event from cmd GetSystemEventReadableHandles, autoclear=true. Signaled when the RequestState ch...
Definition: nifm.h:44
NifmIpV4Address
IpV4Address.
Definition: nifm.h:57
NifmClientId
ClientId.
Definition: nifm.h:52
NifmSfNetworkProfileData::uuid
Uuid uuid
Uuid.
Definition: nifm.h:123
nifmRequestSubmitAndWait
Result nifmRequestSubmitAndWait(NifmRequest *r)
SubmitAndWait.
NifmRequestState_Invalid
@ NifmRequestState_Invalid
Error.
Definition: nifm.h:33
NifmSfNetworkProfileData::unk_x113
u8 unk_x113
Unknown.
Definition: nifm.h:126
Service
Service object structure.
Definition: service.h:13
NifmDnsSetting::is_automatic
u8 is_automatic
Whether this setting is automatic. Ignored by nifmGetCurrentIpConfigInfo.
Definition: nifm.h:72
nifmGetClientId
NifmClientId nifmGetClientId(void)
GetClientId.
NifmProxySetting::pad2
u8 pad2
Padding.
Definition: nifm.h:87
NifmInternetConnectionType
NifmInternetConnectionType
Definition: nifm.h:19
NifmProxySetting
ProxySetting.
Definition: nifm.h:79
NifmWirelessSettingData::pad
u8 pad
Padding.
Definition: nifm.h:103
NifmDnsSetting
DnsSetting.
Definition: nifm.h:71
NifmRequest
Request.
Definition: nifm.h:42
nifmGetNetworkProfile
Result nifmGetNetworkProfile(Uuid uuid, NifmNetworkProfileData *profile)
GetNetworkProfile.
NifmNetworkProfileData::uuid
Uuid uuid
NifmSfNetworkProfileData::uuid.
Definition: nifm.h:135
NifmServiceType_User
@ NifmServiceType_User
Initializes nifm:u.
Definition: nifm.h:14
NifmSfNetworkProfileData::unk_x112
u8 unk_x112
Unknown.
Definition: nifm.h:125
nifmCreateRequest
Result nifmCreateRequest(NifmRequest *r, bool autoclear)
CreateRequest.
NifmRequestState_Unknown5
@ NifmRequestState_Unknown5
Unknown.
Definition: nifm.h:38
NifmWirelessSettingData::ssid_len
u8 ssid_len
NifmSfWirelessSettingData::ssid_len.
Definition: nifm.h:100
NifmNetworkProfileData::unk_x50
u32 unk_x50
NifmSfNetworkProfileData::unk_x112.
Definition: nifm.h:137
nifmGetCurrentIpAddress
Result nifmGetCurrentIpAddress(u32 *out)
GetCurrentIpAddress.
NifmSfWirelessSettingData::unk_x21
u8 unk_x21
Unknown.
Definition: nifm.h:114
u16
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
nifmExit
void nifmExit(void)
Exit nifm. This is used automatically by gethostid().
NifmIpAddressSetting::subnet_mask
NifmIpV4Address subnet_mask
Subnet Mask.
Definition: nifm.h:66
NifmSfNetworkProfileData::unk_x114
u8 unk_x114
Unknown.
Definition: nifm.h:127
nifmInitialize
Result nifmInitialize(NifmServiceType service_type)
Initialize nifm. This is used automatically by gethostid().
NifmSfWirelessSettingData
SfWirelessSettingData.
Definition: nifm.h:111
NifmIpAddressSetting::is_automatic
u8 is_automatic
Whether this setting is automatic. Ignored by nifmGetCurrentIpConfigInfo.
Definition: nifm.h:63