libnx  v4.8.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  */
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 /**
233  * @brief SetWowlDelayedWakeTime
234  * @note Only available with ::NifmServiceType_System or ::NifmServiceType_Admin.
235  * @note Only available on [9.0.0+].
236  * @param[in] val Input value.
237  */
239 
240 ///@name IRequest
241 ///@{
242 
243 /**
244  * @brief Close a \ref NifmRequest.
245  * @param r \ref NifmRequest
246  */
248 
249 /**
250  * @brief GetRequestState
251  * @param r \ref NifmRequest
252  * @param[out] out \ref NifmRequestState
253  */
255 
256 /**
257  * @brief GetResult
258  * @param r \ref NifmRequest
259  */
261 
262 /**
263  * @brief Cancel
264  * @param r \ref NifmRequest
265  */
267 
268 /**
269  * @brief Submit
270  * @param r \ref NifmRequest
271  */
273 
274 /**
275  * @brief SubmitAndWait
276  * @param r \ref NifmRequest
277  */
279 
280 /**
281  * @brief GetAppletInfo
282  * @note This is used by \ref nifmLaHandleNetworkRequestResult.
283  * @param r \ref NifmRequest
284  * @param[in] theme_color ThemeColor
285  * @param[out] buffer Output buffer for storage data.
286  * @param[in] size Output buffer size.
287  * @param[out] applet_id \ref AppletId
288  * @param[out] mode \ref LibAppletMode
289  * @param[out] out_size Total data size written to the output buffer.
290  */
291 Result nifmRequestGetAppletInfo(NifmRequest* r, u32 theme_color, void* buffer, size_t size, u32 *applet_id, u32 *mode, u32 *out_size);
292 
293 /**
294  * @brief SetKeptInSleep
295  * @note Only available on [3.0.0+].
296  * @note ::NifmRequestState must be ::NifmRequestState_Unknown1.
297  * @param r \ref NifmRequest
298  * @param[in] flag Flag
299  */
301 
302 /**
303  * @brief RegisterSocketDescriptor. Only 1 socket can be registered at a time with a NifmRequest. Do not use directly, use \ref socketNifmRequestRegisterSocketDescriptor instead.
304  * @note Only available on [3.0.0+].
305  * @note ::NifmRequestState must be ::NifmRequestState_Available.
306  * @param r \ref NifmRequest
307  * @param[in] sockfd Socket fd
308  */
310 
311 /**
312  * @brief UnregisterSocketDescriptor. Do not use directly, use \ref socketNifmRequestUnregisterSocketDescriptor instead.
313  * @note Only available on [3.0.0+].
314  * @note ::NifmRequestState must be ::NifmRequestState_Available.
315  * @param r \ref NifmRequest
316  * @param[in] sockfd Socket fd, must match the fd previously registered with \ref nifmRequestRegisterSocketDescriptor.
317  */
319 
320 ///@}
321 
Result nifmRequestCancel(NifmRequest *r)
Cancel.
Result nifmRequestUnregisterSocketDescriptor(NifmRequest *r, int sockfd)
UnregisterSocketDescriptor.
Result nifmGetCurrentIpConfigInfo(u32 *current_addr, u32 *subnet_mask, u32 *gateway, u32 *primary_dns_server, u32 *secondary_dns_server)
GetCurrentIpConfigInfo.
Result nifmRequestSetKeptInSleep(NifmRequest *r, bool flag)
SetKeptInSleep.
Result nifmGetResult(NifmRequest *r)
GetResult.
Result nifmRequestGetAppletInfo(NifmRequest *r, u32 theme_color, void *buffer, size_t size, u32 *applet_id, u32 *mode, u32 *out_size)
GetAppletInfo.
Result nifmSetWowlDelayedWakeTime(s32 val)
SetWowlDelayedWakeTime.
Service * nifmGetServiceSession_GeneralService(void)
Gets the Service object for IGeneralService.
Result nifmGetCurrentNetworkProfile(NifmNetworkProfileData *profile)
GetCurrentNetworkProfile.
Result nifmRequestSubmitAndWait(NifmRequest *r)
SubmitAndWait.
Result nifmSetWirelessCommunicationEnabled(bool enable)
Result nifmInitialize(NifmServiceType service_type)
Initialize nifm. This is used automatically by gethostid().
Result nifmRequestSubmit(NifmRequest *r)
Submit.
Result nifmGetNetworkProfile(Uuid uuid, NifmNetworkProfileData *profile)
GetNetworkProfile.
NifmServiceType
Definition: nifm.h:13
@ NifmServiceType_Admin
Initializes nifm:a.
Definition: nifm.h:16
@ NifmServiceType_System
Initializes nifm:s.
Definition: nifm.h:15
@ NifmServiceType_User
Initializes nifm:u.
Definition: nifm.h:14
NifmInternetConnectionType
Definition: nifm.h:19
@ NifmInternetConnectionType_Ethernet
Ethernet connection is used.
Definition: nifm.h:21
@ NifmInternetConnectionType_WiFi
Wi-Fi connection is used.
Definition: nifm.h:20
Result nifmSetNetworkProfile(const NifmNetworkProfileData *profile, Uuid *uuid)
SetNetworkProfile.
NifmClientId nifmGetClientId(void)
GetClientId.
Result nifmGetRequestState(NifmRequest *r, NifmRequestState *out)
GetRequestState.
NifmInternetConnectionStatus
Definition: nifm.h:24
@ NifmInternetConnectionStatus_Connected
Internet is connected.
Definition: nifm.h:29
@ NifmInternetConnectionStatus_ConnectingUnknown2
Unknown internet connection status 2.
Definition: nifm.h:26
@ NifmInternetConnectionStatus_ConnectingUnknown3
Unknown internet connection status 3 (conntest?).
Definition: nifm.h:27
@ NifmInternetConnectionStatus_ConnectingUnknown1
Unknown internet connection status 1.
Definition: nifm.h:25
@ NifmInternetConnectionStatus_ConnectingUnknown4
Unknown internet connection status 4.
Definition: nifm.h:28
void nifmRequestClose(NifmRequest *r)
Close a NifmRequest.
Result nifmGetInternetConnectionStatus(NifmInternetConnectionType *connectionType, u32 *wifiStrength, NifmInternetConnectionStatus *connectionStatus)
NifmRequestState
Definition: nifm.h:32
@ NifmRequestState_Unknown5
Unknown.
Definition: nifm.h:38
@ NifmRequestState_OnHold
OnHold.
Definition: nifm.h:35
@ NifmRequestState_Unknown1
Not yet submitted or error.
Definition: nifm.h:34
@ NifmRequestState_Available
Available.
Definition: nifm.h:36
@ NifmRequestState_Unknown4
Unknown.
Definition: nifm.h:37
@ NifmRequestState_Invalid
Error.
Definition: nifm.h:33
Result nifmRequestRegisterSocketDescriptor(NifmRequest *r, int sockfd)
RegisterSocketDescriptor.
bool nifmIsAnyInternetRequestAccepted(NifmClientId id)
IsAnyInternetRequestAccepted.
void nifmExit(void)
Exit nifm. This is used automatically by gethostid().
Service * nifmGetServiceSession_StaticService(void)
Gets the Service object for the actual nifm:* service session.
Result nifmGetCurrentIpAddress(u32 *out)
GetCurrentIpAddress.
Result nifmCreateRequest(NifmRequest *r, bool autoclear)
CreateRequest.
Kernel-mode event structure.
Definition: event.h:13
ClientId.
Definition: nifm.h:52
u32 id
ClientId.
Definition: nifm.h:53
DnsSetting.
Definition: nifm.h:71
NifmIpV4Address secondary_dns_server
Secondary DNS server.
Definition: nifm.h:75
u8 is_automatic
Whether this setting is automatic. Ignored by nifmGetCurrentIpConfigInfo.
Definition: nifm.h:72
NifmIpV4Address primary_dns_server
Primary DNS server.
Definition: nifm.h:74
IpAddressSetting.
Definition: nifm.h:62
NifmIpV4Address gateway
Gateway.
Definition: nifm.h:67
NifmIpV4Address current_addr
Current address.
Definition: nifm.h:65
NifmIpV4Address subnet_mask
Subnet Mask.
Definition: nifm.h:66
u8 is_automatic
Whether this setting is automatic. Ignored by nifmGetCurrentIpConfigInfo.
Definition: nifm.h:63
IpSettingData.
Definition: nifm.h:91
NifmIpAddressSetting ip_address_setting
NifmIpAddressSetting
Definition: nifm.h:92
NifmProxySetting proxy_setting
NifmProxySetting
Definition: nifm.h:94
NifmDnsSetting dns_setting
NifmDnsSetting
Definition: nifm.h:93
u16 mtu
MTU.
Definition: nifm.h:95
IpV4Address.
Definition: nifm.h:57
NetworkProfileData. Converted from/to NifmSfNetworkProfileData.
Definition: nifm.h:134
Uuid uuid
NifmSfNetworkProfileData::uuid.
Definition: nifm.h:135
NifmIpSettingData ip_setting_data
NifmIpSettingData
Definition: nifm.h:143
u8 unk_x59
NifmSfNetworkProfileData::unk_x115.
Definition: nifm.h:140
u32 unk_x54
NifmSfNetworkProfileData::unk_x113.
Definition: nifm.h:138
u8 unk_x58
NifmSfNetworkProfileData::unk_x114.
Definition: nifm.h:139
u32 unk_x50
NifmSfNetworkProfileData::unk_x112.
Definition: nifm.h:137
NifmWirelessSettingData wireless_setting_data
NifmWirelessSettingData
Definition: nifm.h:142
ProxySetting.
Definition: nifm.h:79
u8 pad2
Padding.
Definition: nifm.h:87
u16 port
Port.
Definition: nifm.h:82
u8 auto_auth_enabled
Enables auto-authentication when set, which uses the following two strings.
Definition: nifm.h:84
u8 pad
Padding.
Definition: nifm.h:81
u8 enabled
Enables using the proxy when set.
Definition: nifm.h:80
Request.
Definition: nifm.h:42
NifmRequestState request_state
NifmRequestState from the GetRequestState cmd.
Definition: nifm.h:47
Result res
Result from the GetResult cmd.
Definition: nifm.h:48
Service s
IRequest.
Definition: nifm.h:43
Event event1
Second Event from cmd GetSystemEventReadableHandles.
Definition: nifm.h:45
Event event_request_state
First Event from cmd GetSystemEventReadableHandles, autoclear=true. Signaled when the RequestState ch...
Definition: nifm.h:44
SfNetworkProfileData. Converted to/from NifmNetworkProfileData.
Definition: nifm.h:121
NifmIpSettingData ip_setting_data
NifmIpSettingData
Definition: nifm.h:122
u8 unk_x115
Unknown.
Definition: nifm.h:128
Uuid uuid
Uuid.
Definition: nifm.h:123
u8 unk_x114
Unknown.
Definition: nifm.h:127
u8 unk_x113
Unknown.
Definition: nifm.h:126
u8 unk_x112
Unknown.
Definition: nifm.h:125
NifmSfWirelessSettingData wireless_setting_data
NifmSfWirelessSettingData
Definition: nifm.h:129
u8 pad
Padding.
Definition: nifm.h:130
SfWirelessSettingData.
Definition: nifm.h:111
u8 unk_x21
Unknown.
Definition: nifm.h:114
u8 unk_x22
Unknown.
Definition: nifm.h:115
u8 ssid_len
SSID length.
Definition: nifm.h:112
u8 unk_x23
Unknown.
Definition: nifm.h:116
WirelessSettingData.
Definition: nifm.h:99
u32 unk_x28
NifmSfWirelessSettingData::unk_x23.
Definition: nifm.h:105
u8 ssid_len
NifmSfWirelessSettingData::ssid_len.
Definition: nifm.h:100
u32 unk_x24
NifmSfWirelessSettingData::unk_x22.
Definition: nifm.h:104
u8 pad
Padding.
Definition: nifm.h:103
u8 unk_x22
NifmSfWirelessSettingData::unk_x21.
Definition: nifm.h:102
Service object structure.
Definition: service.h:14
Definition: types.h:48
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
u32 Result
Function error code result type.
Definition: types.h:44
int32_t s32
32-bit signed integer.
Definition: types.h:27
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21