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