]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetworkConnection.h
configd-963.200.27.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCNetworkConnection.h
1 /*
2 * Copyright (c) 2003-2006, 2008-2010, 2015, 2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _SCNETWORKCONNECTION_H
25 #define _SCNETWORKCONNECTION_H
26
27 #include <os/availability.h>
28 #include <TargetConditionals.h>
29 #include <sys/cdefs.h>
30 #include <dispatch/dispatch.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <CoreFoundation/CoreFoundation.h>
34 #include <SystemConfiguration/SystemConfiguration.h>
35
36 CF_IMPLICIT_BRIDGING_ENABLED
37 CF_ASSUME_NONNULL_BEGIN
38
39 /*!
40 @header SCNetworkConnection
41 @discussion The SCNetworkConnection API contains functions that allow
42 an application to control connection-oriented services defined
43 in the system and get connection-status information.
44
45 The functions in the SCNetworkConnection API allow you to
46 control and get information about existing services only.
47 If you need to create, change, or remove services, you
48 should use the SCNetworkConfiguration API instead.
49
50 Note: Currently, only PPP services can be controlled.
51 */
52
53
54 /*!
55 @typedef SCNetworkConnectionRef
56 @discussion This is the handle to manage a connection-oriented service.
57 */
58 typedef const struct CF_BRIDGED_TYPE(id) __SCNetworkConnection * SCNetworkConnectionRef;
59
60
61 /*!
62 @typedef SCNetworkConnectionContext
63 @discussion Structure containing user-specified data and callbacks
64 for a SCNetworkConnection.
65 @field version The version number of the structure type being passed
66 in as a parameter to the SCNetworkConnectionCreateWithServiceID
67 function. This structure is version 0.
68 @field info A C pointer to a user-specified block of data.
69 @field retain The callback used to add a retain for the info field.
70 If this parameter is not a pointer to a function of the correct
71 prototype, the behavior is undefined. The value may be NULL.
72 @field release The calllback used to remove a retain previously added
73 for the info field. If this parameter is not a pointer to a
74 function of the correct prototype, the behavior is undefined.
75 The value may be NULL.
76 @field copyDescription The callback used to provide a description of
77 the info field.
78 */
79 typedef struct {
80 CFIndex version;
81 void * __nullable info;
82 const void * __nonnull (* __nullable retain)(const void *info);
83 void (* __nullable release)(const void *info);
84 CFStringRef __nonnull (* __nullable copyDescription)(const void *info);
85 } SCNetworkConnectionContext;
86
87
88
89 /*!
90 @enum SCNetworkConnectionStatus
91 @discussion Status of the network connection.
92 This status is intended to be generic and high level.
93 An extended status, specific to the type of network
94 connection is also available for applications that
95 need additonal information.
96 @constant kSCNetworkConnectionInvalid
97 The network connection refers to an invalid service.
98 @constant kSCNetworkConnectionDisconnected
99 The network connection is disconnected.
100 @constant kSCNetworkConnectionConnecting
101 The network connection is connecting.
102 @constant kSCNetworkConnectionConnected
103 The network connection is connected.
104 @constant kSCNetworkConnectionDisconnecting
105 The network connection is disconnecting.
106 */
107 typedef CF_ENUM(int32_t, SCNetworkConnectionStatus) {
108 kSCNetworkConnectionInvalid = -1,
109 kSCNetworkConnectionDisconnected = 0,
110 kSCNetworkConnectionConnecting = 1,
111 kSCNetworkConnectionConnected = 2,
112 kSCNetworkConnectionDisconnecting = 3
113 };
114
115
116 /*!
117 @enum SCNetworkConnectionPPPStatus
118 @discussion PPP-specific status of the network connection.
119 This status is returned as part of the extended information
120 for a PPP service.
121 Note: additional status might be returned in the future.
122 Your application should be prepared to receive an unknown value.
123 @constant kSCNetworkConnectionPPPDisconnected
124 PPP is disconnected.
125 @constant kSCNetworkConnectionPPPInitializing
126 PPP is initializing.
127 @constant kSCNetworkConnectionPPPConnectingLink
128 PPP is connecting the lower connection layer (for example,
129 the modem is dialing out).
130 @constant kSCNetworkConnectionPPPDialOnTraffic
131 PPP is waiting for networking traffic to automatically
132 establish the connection.
133 @constant kSCNetworkConnectionPPPNegotiatingLink
134 The PPP lower layer is connected and PPP is negotiating the
135 link layer (LCP protocol).
136 @constant kSCNetworkConnectionPPPAuthenticating
137 PPP is authenticating to the server (PAP, CHAP, MS-CHAP or
138 EAP protocols).
139 @constant kSCNetworkConnectionPPPWaitingForCallBack
140 PPP is waiting for the server to call back.
141 @constant kSCNetworkConnectionPPPNegotiatingNetwork
142 PPP is now authenticated and negotiating the networking
143 layer (IPCP or IPv6CP protocols)
144 @constant kSCNetworkConnectionPPPConnected
145 PPP is now fully connected for at least one networking layer.
146 Additional networking protocol might still be negotiating.
147 @constant kSCNetworkConnectionPPPTerminating
148 PPP networking and link protocols are terminating.
149 @constant kSCNetworkConnectionPPPDisconnectingLink
150 PPP is disconnecting the lower level (for example, the modem
151 is hanging up).
152 @constant kSCNetworkConnectionPPPHoldingLinkOff
153 PPP is disconnected and maintaining the link temporarily off.
154 @constant kSCNetworkConnectionPPPSuspended
155 PPP is suspended as a result of the suspend command (for
156 example, when a V.92 Modem is On Hold).
157 @constant kSCNetworkConnectionPPPWaitingForRedial
158 PPP has found a busy server and is waiting for redial.
159 */
160 typedef CF_ENUM(int32_t, SCNetworkConnectionPPPStatus) {
161 kSCNetworkConnectionPPPDisconnected = 0,
162 kSCNetworkConnectionPPPInitializing = 1,
163 kSCNetworkConnectionPPPConnectingLink = 2,
164 kSCNetworkConnectionPPPDialOnTraffic = 3,
165 kSCNetworkConnectionPPPNegotiatingLink = 4,
166 kSCNetworkConnectionPPPAuthenticating = 5,
167 kSCNetworkConnectionPPPWaitingForCallBack = 6,
168 kSCNetworkConnectionPPPNegotiatingNetwork = 7,
169 kSCNetworkConnectionPPPConnected = 8,
170 kSCNetworkConnectionPPPTerminating = 9,
171 kSCNetworkConnectionPPPDisconnectingLink = 10,
172 kSCNetworkConnectionPPPHoldingLinkOff = 11,
173 kSCNetworkConnectionPPPSuspended = 12,
174 kSCNetworkConnectionPPPWaitingForRedial = 13
175 };
176
177 /*!
178 @typedef SCNetworkConnectionCallBack
179 @discussion Type of the callback function used when a
180 status event is delivered.
181 @param status The connection status.
182 @param connection The connection reference.
183 @param info Application-specific information.
184 */
185 typedef void (*SCNetworkConnectionCallBack) (
186 SCNetworkConnectionRef connection,
187 SCNetworkConnectionStatus status,
188 void * __nullable info
189 );
190
191
192
193 /*
194 Keys for the statistics dictionary
195 */
196
197 #define kSCNetworkConnectionBytesIn CFSTR("BytesIn") /* CFNumber */
198 #define kSCNetworkConnectionBytesOut CFSTR("BytesOut") /* CFNumber */
199 #define kSCNetworkConnectionPacketsIn CFSTR("PacketsIn") /* CFNumber */
200 #define kSCNetworkConnectionPacketsOut CFSTR("PacketsOut") /* CFNumber */
201 #define kSCNetworkConnectionErrorsIn CFSTR("ErrorsIn") /* CFNumber */
202 #define kSCNetworkConnectionErrorsOut CFSTR("ErrorsOut") /* CFNumber */
203
204
205 /*
206 Keys for the SCNetworkConnectionCopyUserPreferences() "selectionOptions"
207 dictionary
208 */
209
210 /*!
211 @define kSCNetworkConnectionSelectionOptionOnDemandHostName
212 @discussion A host name that will be used to select the
213 "best" SCNetworkConnection.
214 */
215 #define kSCNetworkConnectionSelectionOptionOnDemandHostName CFSTR("OnDemandHostName") // CFString
216 // API_AVAILABLE(macos(4.0))
217 // SPI_AVAILABLE(ios(3.0), tvos(9.0), watchos(1.0), bridgeos(1.0))
218
219 /*!
220 @define kSCNetworkConnectionSelectionOptionOnDemandRetry
221 @discussion A boolean value used to indicate whether a DNS query has
222 already been issued for the specified OnDemand host name.
223 */
224 #define kSCNetworkConnectionSelectionOptionOnDemandRetry CFSTR("OnDemandRetry") // CFBoolean
225 // API_AVAILABLE(macos(4.0))
226 // SPI_AVAILABLE(ios(3.0), tvos(9.0), watchos(1.0), bridgeos(1.0))
227
228 __BEGIN_DECLS
229
230 /*!
231 @function SCNetworkConnectionGetTypeID
232 @discussion Returns the type identifier of all SCNetworkConnection
233 instances.
234 */
235 CFTypeID
236 SCNetworkConnectionGetTypeID (void) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
237
238
239 /*!
240 @function SCNetworkConnectionCopyUserPreferences
241 @discussion Provides the default service ID and a dictionary of user
242 options for the connection. Applications can use the
243 returned serviceID and userOptions values to open a
244 connection on the fly.
245 @param selectionOptions Currently unimplemented. Pass NULL for this
246 version.
247 @param serviceID Reference to the default serviceID for starting
248 connections, this value will be returned by the function.
249 @param userOptions Reference to default userOptions for starting
250 connections, this will be returned by the function.
251 @result Returns TRUE if there is a valid service to dial;
252 FALSE if the function was unable to retrieve a service to dial.
253 */
254 Boolean
255 SCNetworkConnectionCopyUserPreferences (
256 CFDictionaryRef __nullable selectionOptions,
257 CFStringRef __nonnull * __nullable serviceID,
258 CFDictionaryRef __nonnull * __nullable userOptions
259 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
260
261
262 /*!
263 @function SCNetworkConnectionCreateWithServiceID
264 @discussion Creates a new connection reference to use for getting
265 the status or for connecting or disconnecting the associated
266 service.
267 @param allocator The CFAllocator that should be used to allocate
268 memory for the connection structure. This parameter may be
269 NULL in which case the current default CFAllocator is used.
270 If this reference is not a valid CFAllocator, the behavior
271 is undefined.
272 @param serviceID A string that defines the service identifier
273 of the connection. Service identifiers uniquely identify
274 services in the system configuration database.
275 @param callout The function to be called when the status
276 of the connection changes. If this parameter is NULL, the
277 application will not receive notifications of status change
278 and will need to poll for updates.
279 @param context The SCNetworkConnectionContext associated with the
280 callout.
281 @result Returns a reference to the new SCNetworkConnection.
282 */
283 SCNetworkConnectionRef __nullable
284 SCNetworkConnectionCreateWithServiceID (
285 CFAllocatorRef __nullable allocator,
286 CFStringRef serviceID,
287 SCNetworkConnectionCallBack __nullable callout,
288 SCNetworkConnectionContext * __nullable context
289 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
290
291
292 /*!
293 @function SCNetworkConnectionCopyServiceID
294 @discussion Returns the service ID associated with the SCNetworkConnection.
295 @param connection The SCNetworkConnection to obtain status from.
296 @result Returns the service ID associated with the SCNetworkConnection.
297 */
298 CFStringRef __nullable
299 SCNetworkConnectionCopyServiceID (
300 SCNetworkConnectionRef connection
301 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
302
303
304 /*!
305 @function SCNetworkConnectionGetStatus
306 @discussion Returns the status of the SCNetworkConnection.
307 A status is one of the following values:
308 <pre>
309 @textblock
310 &#32
311 kSCNetworkConnectionInvalid
312 kSCNetworkConnectionDisconnected
313 kSCNetworkConnectionConnecting
314 kSCNetworkConnectionDisconnecting
315 kSCNetworkConnectionConnected
316 @/textblock
317 </pre>
318 @param connection The SCNetworkConnection to obtain status from.
319 @result Returns the status value.
320 */
321 SCNetworkConnectionStatus
322 SCNetworkConnectionGetStatus (
323 SCNetworkConnectionRef connection
324 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
325
326
327 /*!
328 @function SCNetworkConnectionCopyExtendedStatus
329 @discussion Returns the extended status of the connection.
330 An extended status dictionary contains specific dictionaries
331 describing the status for each subcomponent of the service.
332
333 For example, a status dictionary will contain the following
334 sub-dictionaries, keys, and values:
335 <pre>
336 @textblock
337 &#32
338 IPv4 : Addresses : the assigned IP address.
339 &#32
340 PPP : Status : the PPP-specific status of type
341 SCNetworkConnectionPPPStatus.
342 &#32
343 LastCause : Available when the status is "Disconnected"
344 and contains the last error associated with
345 connecting or disconnecting.
346 &#32
347 ConnectTime : the time when the connection was
348 established.
349 &#32
350 Modem : ConnectSpeed : the speed of the modem connection
351 in bits/second.
352 &#32
353 IPSec : Status : the IPSec-specific status of type
354 SCNetworkConnectionIPSecStatus
355 &#32
356 ConnectTime : the time when the connection was
357 established.
358
359 @/textblock
360 </pre>
361 Other dictionaries could be present for PPPoE, PPTP, and L2TP.
362
363 The status dictionary may be extended in the future to contain
364 additional information.
365 @param connection The SCNetworkConnection to obtain status from.
366 @result Returns the status dictionary.
367 If NULL is returned, the error can be retrieved using the SCError function.
368 */
369 CFDictionaryRef __nullable
370 SCNetworkConnectionCopyExtendedStatus (
371 SCNetworkConnectionRef connection
372 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
373
374
375 /*!
376 @function SCNetworkConnectionCopyStatistics
377 @discussion Returns the statistics of the SCNetworkConnection.
378 A statistic dictionary contains specific dictionaries
379 with statistics for each subcomponent of the service.
380
381 For example, a statistics dictionary will contain the following
382 sub-dictionaries, keys, and values:
383 <pre>
384 @textblock
385 &#32
386 PPP : BytesIn :
387 PPP : BytesOut : Contains the number of bytes going up into
388 (or coming out of) the network stack for
389 any networking protocol without the PPP
390 headers and trailers.
391 &#32
392 PPP : PacketsIn :
393 PPP : PacketsOut : Contains the number of packets going up into
394 (or coming out of) the network stack for
395 any networking protocol without the PPP
396 headers and trailers.
397 &#32
398 PPP : ErrorsIn :
399 PPP : ErrorsOut : Contains the number of errors going up into
400 (or coming out of) the network stack for
401 any networking protocol without the PPP
402 headers and trailers.
403 @/textblock
404 </pre>
405 The statistics dictionary may be extended in the future to
406 contain additional information.
407 @param connection The SCNetworkConnection to obtained statistics from.
408 @result Returns the statistics dictionary.
409 If NULL is returned, the error can be retrieved using the SCError function.
410 */
411 CFDictionaryRef __nullable
412 SCNetworkConnectionCopyStatistics (
413 SCNetworkConnectionRef connection
414 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
415
416
417 /*!
418 @function SCNetworkConnectionStart
419 @discussion Starts the connection for the SCNetworkConnection.
420 The connection process is asynchronous and the function will
421 return immediately. The connection status can be obtained
422 by polling or by callback. The connection is made with the
423 default settings from the administrator. Some of the settings
424 can be overridden for the duration of the connection. These
425 are specified in an options dictionary. The options dictionary
426 uses the same format as a network service defined in the system
427 configuration preferences schema.
428
429 Note: Starting and stopping of connections is implicitly
430 arbitrated. Calling SCNetworkConnectionStart on a connection
431 already started will indicate that the application has
432 interest in the connection and it shouldn't be stopped by
433 anyone else.
434 @param connection The SCNetworkConnection to start.
435 @param userOptions The options dictionary to start the connection with.
436 If userOptions is NULL, the default settings will be used.
437 If userOptions are specified, they must be in the same format
438 as network services stored in the system configuration
439 preferences schema. The options will override the default
440 settings defined for the service.
441
442 For security reasons, not all options can be overridden; the
443 appropriate merging of all settings will be done before the
444 connection is established, and inappropriate options will be
445 ignored.
446 @param linger This parameter indicates whether or not the connection
447 can stay around when the application no longer has interest
448 in it. A typical application should pass FALSE, and the
449 connection will be automatically stopped when the reference
450 is released or if the application quits. If the application
451 passes TRUE, the application can release the reference or
452 exit and the connection will be maintained until a timeout
453 event, until a specific stop request occurs, or until an
454 error is encountered.
455 @result Returns TRUE if the connection was correctly started (the
456 actual connection is not established yet, and the connection
457 status needs to be periodically checked); FALSE if the
458 connection request was not started. The error must be
459 retrieved from the SCError function.
460 */
461 Boolean
462 SCNetworkConnectionStart (
463 SCNetworkConnectionRef connection,
464 CFDictionaryRef __nullable userOptions,
465 Boolean linger
466 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
467
468
469 /*!
470 @function SCNetworkConnectionStop
471 @discussion Stops the connection for the SCNetworkConnection.
472 The disconnection process is asynchronous and the function
473 will return immediately. The connection status can be
474 obtained by polling or by callback. This function performs
475 an arbitrated stop of the connection. If several applications
476 have marked their interest in the connection, by calling
477 SCNetworkConnectionStart, the call will succeed but the
478 actual connection will be maintained until the last interested
479 application calls SCNetworkConnectionStop.
480
481 In certain cases, you might want to stop the connection anyway.
482 In these cases, you set the forceDisconnect argument to TRUE.
483 @param connection The SCNetworkConnection to stop.
484 @result Returns TRUE if the disconnection request succeeded;
485 FALSE if the disconnection request failed.
486 The error must be retrieved from the SCError function.
487 */
488 Boolean
489 SCNetworkConnectionStop (
490 SCNetworkConnectionRef connection,
491 Boolean forceDisconnect
492 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
493
494
495 /*!
496 @function SCNetworkConnectionCopyUserOptions
497 @discussion Copies the user options used to start the connection.
498 This is a mechanism a client can use to retrieve the user options
499 previously passed to the SCNetworkConnectionStart function.
500 @param connection The SCNetworkConnection to obtain options from.
501 @result Returns the service dictionary containing the connection options.
502 The dictionary can be empty if no user options were used.
503 If NULL is returned, the error can be retrieved using the SCError function.
504 */
505 CFDictionaryRef __nullable
506 SCNetworkConnectionCopyUserOptions (
507 SCNetworkConnectionRef connection
508 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
509
510
511 /*!
512 @function SCNetworkConnectionScheduleWithRunLoop
513 @discussion Schedules a connection with the run loop.
514 @param connection The SCNetworkConnection to schedule.
515 @param runLoop The run loop to schedule with.
516 @param runLoopMode The run loop mode.
517 @result Returns TRUE if the connection is scheduled successfully;
518 FALSE if the scheduling failed.
519 The error can be retrieved using the SCError function.
520 */
521 Boolean
522 SCNetworkConnectionScheduleWithRunLoop (
523 SCNetworkConnectionRef connection,
524 CFRunLoopRef runLoop,
525 CFStringRef runLoopMode
526 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
527
528
529 /*!
530 @function SCNetworkConnectionUnscheduleFromRunLoop
531 @discussion Unschedules a connection from the run loop.
532 @param connection The SCNetworkConnection to unschedule.
533 @param runLoop The run loop to unschedule from.
534 @param runLoopMode The run loop mode.
535 @result Returns TRUE if the connection is unscheduled successfully;
536 FALSE if the unscheduling failed.
537 The error can be retrieved using the SCError function.
538 */
539 Boolean
540 SCNetworkConnectionUnscheduleFromRunLoop (
541 SCNetworkConnectionRef connection,
542 CFRunLoopRef runLoop,
543 CFStringRef runLoopMode
544 ) API_AVAILABLE(macos(10.3)) SPI_AVAILABLE(ios(2.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
545
546
547 /*!
548 @function SCNetworkConnectionSetDispatchQueue
549 @discussion Caller provides a dispatch queue on which the callback contained in connection will run.
550 @param connection The SCNetworkConnection to notify.
551 @param queue The libdispatch queue to run the callback on.
552 Pass NULL to disable notifications, and release queue.
553 @result Returns TRUE if the notifications have been enabled/disabled as desired;
554 FALSE if not.
555 The error can be retrieved using the SCError function.
556 */
557 Boolean
558 SCNetworkConnectionSetDispatchQueue (
559 SCNetworkConnectionRef connection,
560 dispatch_queue_t __nullable queue
561 ) API_AVAILABLE(macos(10.6)) SPI_AVAILABLE(ios(4.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
562
563 __END_DECLS
564
565 CF_ASSUME_NONNULL_END
566 CF_IMPLICIT_BRIDGING_DISABLED
567
568 #endif /* _SCNETWORKCONNECTION_H */