2 * Copyright (c) 2004-2012 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * May 13, 2004 Allan Nathanson <ajn@apple.com>
29 * which includes code originally authored by
30 * Robert Ulrich <rulrich@apple.com>
31 * Elizabeth Douglas <elizabeth@apple.com>
32 * Quinn <eskimo1@apple.com>
36 #include <Availability.h>
37 #include <TargetConditionals.h>
38 #include <CoreFoundation/CoreFoundation.h>
39 #include <CoreFoundation/CFRuntime.h>
40 #include <SystemConfiguration/SystemConfiguration.h>
41 #include "SCNetworkConfigurationInternal.h"
42 #include <SystemConfiguration/SCValidation.h>
43 #include <SystemConfiguration/SCPrivate.h>
44 #include "SCPreferencesInternal.h"
45 #include "SCHelper_client.h"
48 #include <EAP8021X/EAPClientProperties.h>
49 #else // !TARGET_OS_IPHONE
50 #ifndef kEAPClientPropUserName
51 #define kEAPClientPropUserName CFSTR("UserName")
53 #ifndef kEAPClientPropUserPasswordKeychainItemID
54 #define kEAPClientPropUserPasswordKeychainItemID CFSTR("UserPasswordKeychainItemID")
56 #endif // !TARGET_OS_IPHONE
58 #include <IOKit/IOKitLib.h>
59 #include <IOKit/IOCFBundle.h>
60 #include <IOKit/IOBSD.h>
61 #include <IOKit/network/IONetworkController.h>
62 #include <IOKit/network/IONetworkInterface.h>
63 #include <IOKit/network/IOEthernetInterface.h> // for kIOEthernetInterfaceClass
64 #include <IOKit/serial/IOSerialKeys.h>
65 #include <IOKit/storage/IOStorageDeviceCharacteristics.h>
66 #include <IOKit/usb/USB.h>
68 #include "dy_framework.h"
70 #ifndef kIODeviceSupportsHoldKey
71 #define kIODeviceSupportsHoldKey "V92Modem"
74 #ifndef kPCIThunderboltString
75 #define kPCIThunderboltString "PCI-Thunderbolt"
78 #ifndef kUSBProductString
79 #define kUSBProductString "USB Product Name"
82 #ifndef kIOUserEthernetInterfaceRoleKey
83 #define kIOUserEthernetInterfaceRoleKey "InterfaceRole"
87 #include <mach/mach.h>
89 #include <net/if_types.h>
90 #include <net/route.h>
91 #include <sys/param.h>
92 #include <sys/types.h>
93 #include <sys/socket.h>
95 #include <sys/sysctl.h>
97 #include <NSSystemDirectories.h>
100 static CFStringRef
copy_interface_string (CFBundleRef bundle
, CFStringRef key
, Boolean localized
);
101 static CFStringRef
__SCNetworkInterfaceCopyDescription (CFTypeRef cf
);
102 static void __SCNetworkInterfaceDeallocate (CFTypeRef cf
);
103 static Boolean
__SCNetworkInterfaceEqual (CFTypeRef cf1
, CFTypeRef cf2
);
104 static CFHashCode
__SCNetworkInterfaceHash (CFTypeRef cf
);
123 kSortBluetoothPAN_GN
,
124 kSortBluetoothPAN_NAP
,
133 const CFStringRef kSCNetworkInterfaceType6to4
= CFSTR("6to4");
134 const CFStringRef kSCNetworkInterfaceTypeBluetooth
= CFSTR("Bluetooth");
135 const CFStringRef kSCNetworkInterfaceTypeBond
= CFSTR("Bond");
136 const CFStringRef kSCNetworkInterfaceTypeBridge
= CFSTR("Bridge");
137 const CFStringRef kSCNetworkInterfaceTypeEthernet
= CFSTR("Ethernet");
138 const CFStringRef kSCNetworkInterfaceTypeFireWire
= CFSTR("FireWire");
139 const CFStringRef kSCNetworkInterfaceTypeIEEE80211
= CFSTR("IEEE80211"); // IEEE 802.11, AirPort
140 const CFStringRef kSCNetworkInterfaceTypeIPSec
= CFSTR("IPSec");
141 const CFStringRef kSCNetworkInterfaceTypeIrDA
= CFSTR("IrDA");
142 const CFStringRef kSCNetworkInterfaceTypeL2TP
= CFSTR("L2TP");
143 const CFStringRef kSCNetworkInterfaceTypeLoopback
= CFSTR("Loopback");
144 const CFStringRef kSCNetworkInterfaceTypeModem
= CFSTR("Modem");
145 const CFStringRef kSCNetworkInterfaceTypePPP
= CFSTR("PPP");
146 const CFStringRef kSCNetworkInterfaceTypePPTP
= CFSTR("PPTP");
147 const CFStringRef kSCNetworkInterfaceTypeSerial
= CFSTR("Serial");
148 const CFStringRef kSCNetworkInterfaceTypeVLAN
= CFSTR("VLAN");
149 const CFStringRef kSCNetworkInterfaceTypeVPN
= CFSTR("VPN");
150 const CFStringRef kSCNetworkInterfaceTypeWWAN
= CFSTR("WWAN");
152 const CFStringRef kSCNetworkInterfaceTypeIPv4
= CFSTR("IPv4");
154 static SCNetworkInterfacePrivate __kSCNetworkInterfaceIPv4
= {
155 INIT_CFRUNTIME_BASE(), // cfBase
156 NULL
, // interface type
158 NULL
, // localized name
159 NULL
, // localization key
160 NULL
, // localization arg1
161 NULL
, // localization arg2
162 NULL
, // [layered] interface
167 NULL
, // entity_device
168 NULL
, // entity_device_unique
170 NULL
, // entity_subtype
171 NULL
, // supported_interface_types
172 NULL
, // supported_protocol_types
174 NULL
, // addressString
176 NULL
, // configurationAction
185 { NULL
, 0, 0 }, // usb { name, vid, pid }
186 kSortUnknown
, // sort_order
187 FALSE
, // supportsBond
188 { NULL
, NULL
, NULL
}, // bond { interfaces, options, mode }
189 FALSE
, // supportsBridge
190 { NULL
, NULL
}, // bridge { interfaces, options }
191 FALSE
, // supportsVLAN
192 { NULL
, NULL
, NULL
} // vlan { interface, tag, options }
195 const SCNetworkInterfaceRef kSCNetworkInterfaceIPv4
= (SCNetworkInterfaceRef
)&__kSCNetworkInterfaceIPv4
;
197 static SCNetworkInterfacePrivate __kSCNetworkInterfaceLoopback
= {
198 INIT_CFRUNTIME_BASE(), // cfBase
199 NULL
, // interface type
201 NULL
, // localized name
202 NULL
, // localization key
203 NULL
, // localization arg1
204 NULL
, // localization arg2
205 NULL
, // [layered] interface
210 NULL
, // entity_device
211 NULL
, // entity_device_unique
213 NULL
, // entity_subtype
214 NULL
, // supported_interface_types
215 NULL
, // supported_protocol_types
217 NULL
, // addressString
219 NULL
, // configurationAction
228 { NULL
, 0, 0 }, // usb { name, vid, pid }
229 kSortUnknown
, // sort_order
230 FALSE
, // supportsBond
231 { NULL
, NULL
, NULL
}, // bond { interfaces, options, mode }
232 FALSE
, // supportsBridge
233 { NULL
, NULL
}, // bridge { interfaces, options }
234 FALSE
, // supportsVLAN
235 { NULL
, NULL
, NULL
} // vlan { interface, tag, options }
238 const SCNetworkInterfaceRef kSCNetworkInterfaceLoopback
= (SCNetworkInterfaceRef
)&__kSCNetworkInterfaceLoopback
;
240 static CFMutableSetRef vendor_interface_types
= NULL
;
243 #pragma mark SCNetworkInterface configuration details
252 #define doOverIP do6to4|doL2TP|doPPTP|doIPSec
257 #define doProxies 1<<4
258 #if !TARGET_OS_IPHONE
260 #else // !TARGET_OS_IPHONE
262 #endif // !TARGET_OS_IPHONE
264 static const struct {
265 const CFStringRef
*interface_type
;
266 const CFStringRef
*entity_hardware
;
267 Boolean per_interface_config
;
268 uint32_t supported_interfaces
;
269 const CFStringRef
*ppp_subtype
;
270 uint32_t supported_protocols
;
271 } configurations
[] = {
272 // interface type entity_hardware if config? interface types PPP sub-type interface protocols
273 // ===================================== ================= ========== =============== ======================================= =========================================
274 { &kSCNetworkInterfaceType6to4
, &kSCEntNet6to4
, FALSE
, doNone
, NULL
, doIPv6
},
275 { &kSCNetworkInterfaceTypeBluetooth
, &kSCEntNetModem
, FALSE
, doPPP
, &kSCValNetInterfaceSubTypePPPSerial
, doNone
},
276 { &kSCNetworkInterfaceTypeBond
, &kSCEntNetEthernet
, TRUE
, doNone
, NULL
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
277 { &kSCNetworkInterfaceTypeBridge
, &kSCEntNetEthernet
, TRUE
, doNone
, NULL
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
278 { &kSCNetworkInterfaceTypeEthernet
, &kSCEntNetEthernet
, TRUE
, doPPP
, &kSCValNetInterfaceSubTypePPPoE
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
279 { &kSCNetworkInterfaceTypeFireWire
, &kSCEntNetFireWire
, TRUE
, doNone
, NULL
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
280 { &kSCNetworkInterfaceTypeIEEE80211
, &kSCEntNetAirPort
, TRUE
, doPPP
, &kSCValNetInterfaceSubTypePPPoE
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
281 { &kSCNetworkInterfaceTypeIPSec
, &kSCEntNetIPSec
, FALSE
, doNone
, NULL
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
282 { &kSCNetworkInterfaceTypeIrDA
, &kSCEntNetModem
, FALSE
, doPPP
, &kSCValNetInterfaceSubTypePPPSerial
, doNone
},
283 { &kSCNetworkInterfaceTypeL2TP
, NULL
, FALSE
, doPPP
, &kSCValNetInterfaceSubTypeL2TP
, doNone
},
284 { &kSCNetworkInterfaceTypeModem
, &kSCEntNetModem
, FALSE
, doPPP
, &kSCValNetInterfaceSubTypePPPSerial
, doNone
},
285 { &kSCNetworkInterfaceTypePPP
, &kSCEntNetPPP
, FALSE
, doNone
, NULL
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
286 { &kSCNetworkInterfaceTypePPTP
, NULL
, FALSE
, doPPP
, &kSCValNetInterfaceSubTypePPTP
, doNone
},
287 { &kSCNetworkInterfaceTypeSerial
, &kSCEntNetModem
, FALSE
, doPPP
, &kSCValNetInterfaceSubTypePPPSerial
, doNone
},
288 { &kSCNetworkInterfaceTypeVLAN
, &kSCEntNetEthernet
, TRUE
, doNone
, NULL
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
289 { &kSCNetworkInterfaceTypeVPN
, &kSCEntNetVPN
, FALSE
, doNone
, NULL
, doDNS
|doIPv4
|doIPv6
|doProxies
|doSMB
},
290 { &kSCNetworkInterfaceTypeWWAN
, &kSCEntNetModem
, FALSE
, doPPP
, &kSCValNetInterfaceSubTypePPPSerial
, doNone
},
291 // ===================================== ================= ========== =============== ======================================= =========================================
292 { &kSCNetworkInterfaceTypeLoopback
, NULL
, TRUE
, doNone
, NULL
, doIPv4
|doIPv6
},
293 // ===================================== ================= ========== =============== ======================================= =========================================
294 { &kSCNetworkInterfaceTypeIPv4
, NULL
, FALSE
, doOverIP
, NULL
, doNone
}
298 #define NETWORKINTERFACE_LOCALIZATIONS CFSTR("NetworkInterface")
299 static CFBundleRef bundle
= NULL
;
302 static CFTypeID __kSCNetworkInterfaceTypeID
= _kCFRuntimeNotATypeID
;
305 static const CFRuntimeClass __SCNetworkInterfaceClass
= {
307 "SCNetworkInterface", // className
310 __SCNetworkInterfaceDeallocate
, // dealloc
311 __SCNetworkInterfaceEqual
, // equal
312 __SCNetworkInterfaceHash
, // hash
313 NULL
, // copyFormattingDesc
314 __SCNetworkInterfaceCopyDescription
// copyDebugDesc
318 static pthread_once_t initialized
= PTHREAD_ONCE_INIT
;
319 static pthread_once_t iokit_quiet
= PTHREAD_ONCE_INIT
;
322 static mach_port_t masterPort
= MACH_PORT_NULL
;
326 __SCNetworkInterfaceCopyDescription(CFTypeRef cf
)
328 CFAllocatorRef allocator
= CFGetAllocator(cf
);
329 CFMutableStringRef result
;
330 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)cf
;
332 result
= CFStringCreateMutable(allocator
, 0);
333 CFStringAppendFormat(result
, NULL
, CFSTR("<SCNetworkInterface %p [%p]> {"), cf
, allocator
);
334 CFStringAppendFormat(result
, NULL
, CFSTR("type = %@"), interfacePrivate
->interface_type
);
335 CFStringAppendFormat(result
, NULL
, CFSTR(", entity_device = %@"), interfacePrivate
->entity_device
);
336 if (interfacePrivate
->entity_device_unique
!= NULL
) {
337 CFStringAppendFormat(result
, NULL
, CFSTR("+%@"), interfacePrivate
->entity_device_unique
);
339 CFStringAppendFormat(result
, NULL
, CFSTR(", entity_type = %@"), interfacePrivate
->entity_type
);
340 if (interfacePrivate
->entity_subtype
!= NULL
) {
341 CFStringAppendFormat(result
, NULL
, CFSTR(" / %@"), interfacePrivate
->entity_subtype
);
343 if (interfacePrivate
->name
!= NULL
) {
344 CFStringAppendFormat(result
, NULL
, CFSTR(", name = %@"), interfacePrivate
->name
);
346 if (interfacePrivate
->localized_name
!= NULL
) {
347 CFStringAppendFormat(result
, NULL
, CFSTR(", name(l) = %@"), interfacePrivate
->localized_name
);
349 if (interfacePrivate
->localized_key
!= NULL
) {
350 CFStringAppendFormat(result
, NULL
, CFSTR(", name(k) = \"%@\""), interfacePrivate
->localized_key
);
351 if (interfacePrivate
->localized_arg1
!= NULL
) {
352 CFStringAppendFormat(result
, NULL
, CFSTR("+\"%@\""), interfacePrivate
->localized_arg1
);
354 if (interfacePrivate
->localized_arg2
!= NULL
) {
355 CFStringAppendFormat(result
, NULL
, CFSTR("+\"%@\""), interfacePrivate
->localized_arg2
);
359 if (interfacePrivate
->address
!= NULL
) {
364 CFStringAppendFormat(result
, NULL
, CFSTR(", address = 0x"));
366 data
= CFDataGetBytePtr(interfacePrivate
->address
);
367 dataLen
= CFDataGetLength(interfacePrivate
->address
);
368 for (i
= 0; i
< dataLen
; i
++) {
369 CFStringAppendFormat(result
, NULL
, CFSTR("%02x"), data
[i
]);
372 CFStringAppendFormat(result
, NULL
, CFSTR(", builtin = %s"), interfacePrivate
->builtin
? "TRUE" : "FALSE");
373 if (interfacePrivate
->hidden
) {
374 CFStringAppendFormat(result
, NULL
, CFSTR(", hidden = TRUE"));
376 if (interfacePrivate
->modemIsV92
) {
377 CFStringAppendFormat(result
, NULL
, CFSTR(", v.92"));
379 if (interfacePrivate
->location
!= NULL
) {
380 CFStringAppendFormat(result
, NULL
, CFSTR(", location = %@"), interfacePrivate
->location
);
382 if (interfacePrivate
->path
!= NULL
) {
383 CFStringAppendFormat(result
, NULL
, CFSTR(", path = %@"), interfacePrivate
->path
);
385 if (interfacePrivate
->entryID
!= 0) {
386 CFStringAppendFormat(result
, NULL
, CFSTR(", entryID = 0x%llx"), interfacePrivate
->entryID
);
388 if (interfacePrivate
->type
!= NULL
) {
389 CFStringAppendFormat(result
, NULL
, CFSTR(", type = %@"), interfacePrivate
->type
);
391 if (interfacePrivate
->unit
!= NULL
) {
392 CFStringAppendFormat(result
, NULL
, CFSTR(", unit = %@"), interfacePrivate
->unit
);
394 if ((interfacePrivate
->usb
.vid
!= NULL
) || (interfacePrivate
->usb
.pid
!= NULL
)) {
398 if (!isA_CFNumber(interfacePrivate
->usb
.pid
) ||
399 !CFNumberGetValue(interfacePrivate
->usb
.vid
, kCFNumberIntType
, &pid
)) {
402 if (!isA_CFNumber(interfacePrivate
->usb
.vid
) ||
403 !CFNumberGetValue(interfacePrivate
->usb
.vid
, kCFNumberIntType
, &vid
)) {
407 if (interfacePrivate
->usb
.name
!= NULL
) {
408 CFStringAppendFormat(result
, NULL
, CFSTR(", USB name = %@"),
409 interfacePrivate
->usb
.name
);
412 CFStringAppendFormat(result
, NULL
, CFSTR(", USB vid/pid = 0x%0x/0x%0x"),
413 interfacePrivate
->usb
.vid
,
414 interfacePrivate
->usb
.pid
);
416 if (interfacePrivate
->configurationAction
!= NULL
) {
417 CFStringAppendFormat(result
, NULL
, CFSTR(", action = %@"), interfacePrivate
->configurationAction
);
419 if (interfacePrivate
->overrides
!= NULL
) {
420 CFStringAppendFormat(result
, NULL
, CFSTR(", overrides = %p"), interfacePrivate
->overrides
);
422 CFStringAppendFormat(result
, NULL
, CFSTR(", order = %d"), interfacePrivate
->sort_order
);
423 if (interfacePrivate
->prefs
!= NULL
) {
424 CFStringAppendFormat(result
, NULL
, CFSTR(", prefs = %p"), interfacePrivate
->prefs
);
426 if (interfacePrivate
->serviceID
!= NULL
) {
427 CFStringAppendFormat(result
, NULL
, CFSTR(", service = %@"), interfacePrivate
->serviceID
);
429 if (interfacePrivate
->interface
!= NULL
) {
430 CFStringAppendFormat(result
, NULL
, CFSTR(", interface = %@"), interfacePrivate
->interface
);
432 if (interfacePrivate
->unsaved
!= NULL
) {
433 CFStringAppendFormat(result
, NULL
, CFSTR(", unsaved = %@"), interfacePrivate
->unsaved
);
436 if (interfacePrivate
->bond
.interfaces
!= NULL
) {
440 n
= CFArrayGetCount(interfacePrivate
->bond
.interfaces
);
441 for (i
= 0; i
< n
; i
++) {
442 SCNetworkInterfaceRef member
;
444 member
= CFArrayGetValueAtIndex(interfacePrivate
->bond
.interfaces
, i
);
445 CFStringAppendFormat(result
, NULL
,
447 (i
== 0) ? ", interfaces = " : ", ",
448 SCNetworkInterfaceGetBSDName(member
));
451 if (interfacePrivate
->bond
.mode
!= NULL
) {
452 CFStringAppendFormat(result
, NULL
, CFSTR(", mode = %@"), interfacePrivate
->bond
.mode
);
454 if (interfacePrivate
->bond
.options
!= NULL
) {
455 CFStringAppendFormat(result
, NULL
, CFSTR(", options = %@"), interfacePrivate
->bond
.options
);
458 if (interfacePrivate
->bridge
.interfaces
!= NULL
) {
462 n
= CFArrayGetCount(interfacePrivate
->bridge
.interfaces
);
463 for (i
= 0; i
< n
; i
++) {
464 SCNetworkInterfaceRef member
;
466 member
= CFArrayGetValueAtIndex(interfacePrivate
->bridge
.interfaces
, i
);
467 CFStringAppendFormat(result
, NULL
,
469 (i
== 0) ? ", interfaces = " : ", ",
470 SCNetworkInterfaceGetBSDName(member
));
473 if (interfacePrivate
->bridge
.options
!= NULL
) {
474 CFStringAppendFormat(result
, NULL
, CFSTR(", options = %@"), interfacePrivate
->bridge
.options
);
477 if (interfacePrivate
->vlan
.interface
!= NULL
) {
478 CFStringAppendFormat(result
, NULL
,
479 CFSTR(", interface = %@"),
480 SCNetworkInterfaceGetBSDName(interfacePrivate
->vlan
.interface
));
482 if (interfacePrivate
->vlan
.tag
!= NULL
) {
483 CFStringAppendFormat(result
, NULL
, CFSTR(", tag = %@"), interfacePrivate
->vlan
.tag
);
485 if (interfacePrivate
->vlan
.options
!= NULL
) {
486 CFStringAppendFormat(result
, NULL
, CFSTR(", options = %@"), interfacePrivate
->vlan
.options
);
489 CFStringAppendFormat(result
, NULL
, CFSTR("}"));
496 __SCNetworkInterfaceDeallocate(CFTypeRef cf
)
498 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)cf
;
500 /* release resources */
502 if (interfacePrivate
->name
!= NULL
)
503 CFRelease(interfacePrivate
->name
);
505 if (interfacePrivate
->localized_name
!= NULL
)
506 CFRelease(interfacePrivate
->localized_name
);
508 if (interfacePrivate
->localized_arg1
!= NULL
)
509 CFRelease(interfacePrivate
->localized_arg1
);
511 if (interfacePrivate
->localized_arg2
!= NULL
)
512 CFRelease(interfacePrivate
->localized_arg2
);
514 if (interfacePrivate
->interface
!= NULL
)
515 CFRelease(interfacePrivate
->interface
);
517 if (interfacePrivate
->prefs
!= NULL
)
518 CFRelease(interfacePrivate
->prefs
);
520 if (interfacePrivate
->store
!= NULL
)
521 CFRelease(interfacePrivate
->store
);
523 if (interfacePrivate
->serviceID
!= NULL
)
524 CFRelease(interfacePrivate
->serviceID
);
526 if (interfacePrivate
->unsaved
!= NULL
)
527 CFRelease(interfacePrivate
->unsaved
);
529 if (interfacePrivate
->entity_device
!= NULL
)
530 CFRelease(interfacePrivate
->entity_device
);
532 if (interfacePrivate
->entity_device_unique
!= NULL
)
533 CFRelease(interfacePrivate
->entity_device_unique
);
535 if (interfacePrivate
->supported_interface_types
!= NULL
)
536 CFRelease(interfacePrivate
->supported_interface_types
);
538 if (interfacePrivate
->supported_protocol_types
!= NULL
)
539 CFRelease(interfacePrivate
->supported_protocol_types
);
541 if (interfacePrivate
->address
!= NULL
)
542 CFRelease(interfacePrivate
->address
);
544 if (interfacePrivate
->addressString
!= NULL
)
545 CFRelease(interfacePrivate
->addressString
);
547 if (interfacePrivate
->configurationAction
!= NULL
)
548 CFRelease(interfacePrivate
->configurationAction
);
550 if (interfacePrivate
->location
!= NULL
)
551 CFRelease(interfacePrivate
->location
);
553 if (interfacePrivate
->path
!= NULL
)
554 CFRelease(interfacePrivate
->path
);
556 if (interfacePrivate
->overrides
!= NULL
)
557 CFRelease(interfacePrivate
->overrides
);
559 if (interfacePrivate
->type
!= NULL
)
560 CFRelease(interfacePrivate
->type
);
562 if (interfacePrivate
->unit
!= NULL
)
563 CFRelease(interfacePrivate
->unit
);
565 if (interfacePrivate
->usb
.name
!= NULL
)
566 CFRelease(interfacePrivate
->usb
.name
);
568 if (interfacePrivate
->usb
.pid
!= NULL
)
569 CFRelease(interfacePrivate
->usb
.pid
);
571 if (interfacePrivate
->usb
.vid
!= NULL
)
572 CFRelease(interfacePrivate
->usb
.vid
);
574 if (interfacePrivate
->bond
.interfaces
!= NULL
)
575 CFRelease(interfacePrivate
->bond
.interfaces
);
577 if (interfacePrivate
->bond
.mode
!= NULL
)
578 CFRelease(interfacePrivate
->bond
.mode
);
580 if (interfacePrivate
->bond
.options
!= NULL
)
581 CFRelease(interfacePrivate
->bond
.options
);
583 if (interfacePrivate
->bridge
.interfaces
!= NULL
)
584 CFRelease(interfacePrivate
->bridge
.interfaces
);
586 if (interfacePrivate
->bridge
.options
!= NULL
)
587 CFRelease(interfacePrivate
->bridge
.options
);
589 if (interfacePrivate
->vlan
.interface
!= NULL
)
590 CFRelease(interfacePrivate
->vlan
.interface
);
592 if (interfacePrivate
->vlan
.tag
!= NULL
)
593 CFRelease(interfacePrivate
->vlan
.tag
);
595 if (interfacePrivate
->vlan
.options
!= NULL
)
596 CFRelease(interfacePrivate
->vlan
.options
);
603 __SCNetworkInterfaceEqual(CFTypeRef cf1
, CFTypeRef cf2
)
605 SCNetworkInterfacePrivateRef if1
= (SCNetworkInterfacePrivateRef
)cf1
;
606 SCNetworkInterfacePrivateRef if2
= (SCNetworkInterfacePrivateRef
)cf2
;
611 if (!CFEqual(if1
->interface_type
, if2
->interface_type
)) {
612 return FALSE
; // if not the same interface type
615 if (!_SC_CFEqual(if1
->entity_device
, if2
->entity_device
)) {
616 return FALSE
; // if not the same device
619 if ((if1
->entity_device_unique
!= NULL
) && (if2
->entity_device_unique
!= NULL
)) {
620 if (!_SC_CFEqual(if1
->entity_device_unique
, if2
->entity_device_unique
)) {
621 return FALSE
; // if not the same device unique identifier
623 } else if ((if1
->entity_device_unique
!= NULL
) || (if2
->entity_device_unique
!= NULL
)) {
627 name1
= __SCNetworkInterfaceGetNonLocalizedDisplayName((SCNetworkInterfaceRef
)if1
);
628 name2
= __SCNetworkInterfaceGetNonLocalizedDisplayName((SCNetworkInterfaceRef
)if2
);
629 if ((name1
!= NULL
) && (name2
!= NULL
) && !_SC_CFEqual(name1
, name2
)) {
630 return FALSE
; // if same device but not the same display name
634 if (CFEqual(if1
->interface_type
, kSCNetworkInterfaceTypeBond
)) {
635 if (!_SC_CFEqual(if1
->bond
.interfaces
, if2
->bond
.interfaces
)) {
636 return FALSE
; // if not the same interfaces
638 if (!_SC_CFEqual(if1
->bond
.mode
, if2
->bond
.mode
)) {
639 return FALSE
; // if not the same mode
643 if (CFEqual(if1
->interface_type
, kSCNetworkInterfaceTypeBridge
)) {
644 if (!_SC_CFEqual(if1
->bridge
.interfaces
, if2
->bridge
.interfaces
)) {
645 return FALSE
; // if not the same interfaces
649 if (CFEqual(if1
->interface_type
, kSCNetworkInterfaceTypeVLAN
)) {
650 if (!_SC_CFEqual(if1
->vlan
.interface
, if2
->vlan
.interface
)) {
651 return FALSE
; // if not the same physical interface
653 if (!_SC_CFEqual(if1
->vlan
.tag
, if2
->vlan
.tag
)) {
654 return FALSE
; // if not the same tag
658 if (!_SC_CFEqual(if1
->interface
, if2
->interface
)) {
659 return FALSE
; // if not the same layering
667 __SCNetworkInterfaceHash(CFTypeRef cf
)
670 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)cf
;
672 if (interfacePrivate
->entity_device
!= NULL
) {
673 if (interfacePrivate
->entity_device_unique
== NULL
) {
674 hash
= CFHash(interfacePrivate
->entity_device
);
678 str
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@+%@"),
679 interfacePrivate
->entity_device
,
680 interfacePrivate
->entity_device_unique
);
691 __SCNetworkInterfaceInitialize(void)
696 __kSCNetworkInterfaceTypeID
= _CFRuntimeRegisterClass(&__SCNetworkInterfaceClass
);
698 // initialize __kSCNetworkInterfaceIPv4
699 _CFRuntimeInitStaticInstance(&__kSCNetworkInterfaceIPv4
, __kSCNetworkInterfaceTypeID
);
700 __kSCNetworkInterfaceIPv4
.interface_type
= kSCNetworkInterfaceTypeIPv4
;
701 __kSCNetworkInterfaceIPv4
.localized_key
= CFSTR("ipv4");
703 // initialize __kSCNetworkInterfaceLoopback
704 _CFRuntimeInitStaticInstance(&__kSCNetworkInterfaceLoopback
, __kSCNetworkInterfaceTypeID
);
705 __kSCNetworkInterfaceLoopback
.interface_type
= kSCNetworkInterfaceTypeLoopback
;
706 __kSCNetworkInterfaceLoopback
.localized_key
= CFSTR("loopback");
707 __kSCNetworkInterfaceLoopback
.entity_device
= CFRetain(CFSTR("lo0"));
708 __kSCNetworkInterfaceLoopback
.entity_type
= kSCValNetInterfaceTypeLoopback
;
710 // get CFBundleRef for SystemConfiguration.framework
711 bundle
= _SC_CFBundleGet();
713 // get mach port used to communication with IOKit
714 kr
= IOMasterPort(MACH_PORT_NULL
, &masterPort
);
715 if (kr
!= KERN_SUCCESS
) {
716 SCLog(TRUE
, LOG_DEBUG
,
717 CFSTR("__SCNetworkInterfaceInitialize(), could not get IOMasterPort, kr = 0x%x"),
726 SCNetworkInterfacePrivateRef
727 __SCNetworkInterfaceCreatePrivate(CFAllocatorRef allocator
,
728 SCNetworkInterfaceRef interface
,
729 SCPreferencesRef prefs
,
730 CFStringRef serviceID
)
732 SCNetworkInterfacePrivateRef interfacePrivate
;
735 /* initialize runtime */
736 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
738 /* allocate target */
739 size
= sizeof(SCNetworkInterfacePrivate
) - sizeof(CFRuntimeBase
);
740 interfacePrivate
= (SCNetworkInterfacePrivateRef
)_CFRuntimeCreateInstance(allocator
,
741 __kSCNetworkInterfaceTypeID
,
744 if (interfacePrivate
== NULL
) {
748 interfacePrivate
->interface_type
= NULL
;
749 interfacePrivate
->name
= NULL
;
750 interfacePrivate
->localized_name
= NULL
;
751 interfacePrivate
->localized_key
= NULL
;
752 interfacePrivate
->localized_arg1
= NULL
;
753 interfacePrivate
->localized_arg2
= NULL
;
754 interfacePrivate
->interface
= (interface
!= NULL
) ? CFRetain(interface
) : NULL
;
755 interfacePrivate
->prefs
= (prefs
!= NULL
) ? CFRetain(prefs
) : NULL
;
756 interfacePrivate
->store
= NULL
;
757 interfacePrivate
->serviceID
= (serviceID
!= NULL
) ? CFRetain(serviceID
) : NULL
;
758 interfacePrivate
->unsaved
= NULL
;
759 interfacePrivate
->entity_device
= NULL
;
760 interfacePrivate
->entity_device_unique
= NULL
;
761 interfacePrivate
->entity_type
= NULL
;
762 interfacePrivate
->entity_subtype
= NULL
;
763 interfacePrivate
->supported_interface_types
= NULL
;
764 interfacePrivate
->supported_protocol_types
= NULL
;
765 interfacePrivate
->address
= NULL
;
766 interfacePrivate
->addressString
= NULL
;
767 interfacePrivate
->builtin
= FALSE
;
768 interfacePrivate
->configurationAction
= NULL
;
769 interfacePrivate
->hidden
= FALSE
;
770 interfacePrivate
->location
= NULL
;
771 interfacePrivate
->path
= NULL
;
772 interfacePrivate
->entryID
= 0;
773 interfacePrivate
->overrides
= NULL
;
774 interfacePrivate
->modemIsV92
= FALSE
;
775 interfacePrivate
->type
= NULL
;
776 interfacePrivate
->unit
= NULL
;
777 interfacePrivate
->usb
.name
= NULL
;
778 interfacePrivate
->usb
.vid
= NULL
;
779 interfacePrivate
->usb
.pid
= NULL
;
780 interfacePrivate
->sort_order
= kSortUnknown
;
782 interfacePrivate
->supportsBond
= FALSE
;
783 interfacePrivate
->bond
.interfaces
= NULL
;
784 interfacePrivate
->bond
.mode
= NULL
;
785 interfacePrivate
->bond
.options
= NULL
;
787 interfacePrivate
->supportsBridge
= FALSE
;
788 interfacePrivate
->bridge
.interfaces
= NULL
;
789 interfacePrivate
->bridge
.options
= NULL
;
791 interfacePrivate
->supportsVLAN
= FALSE
;
792 interfacePrivate
->vlan
.interface
= NULL
;
793 interfacePrivate
->vlan
.tag
= NULL
;
794 interfacePrivate
->vlan
.options
= NULL
;
796 return interfacePrivate
;
802 __SCNetworkInterfaceSupportsVLAN(CFStringRef bsd_if
)
806 struct if_msghdr
* ifm
;
807 char * if_name
= NULL
;
808 unsigned int if_index
;
810 Boolean vlanOK
= FALSE
;
812 // get the interface index
813 if_name
= _SC_cfstring_to_cstring(bsd_if
, NULL
, 0, kCFStringEncodingASCII
);
814 if (if_name
== NULL
) {
815 return FALSE
; // if conversion error
817 if_index
= if_nametoindex(if_name
);
819 goto done
; // if unknown interface
822 // get information for the specified interface
827 mib
[4] = NET_RT_IFLIST
;
828 mib
[5] = if_index
; /* ask for exactly one interface */
830 if (sysctl(mib
, 6, NULL
, &buf_len
, NULL
, 0) == -1) {
831 SCLog(TRUE
, LOG_ERR
, CFSTR("sysctl() size failed: %s"), strerror(errno
));
834 buf
= CFAllocatorAllocate(NULL
, buf_len
, 0);
835 if (sysctl(mib
, 6, buf
, &buf_len
, NULL
, 0) == -1) {
836 SCLog(TRUE
, LOG_ERR
, CFSTR("sysctl() failed: %s"), strerror(errno
));
840 // check the link type and hwassist flags
841 // ALIGN: buf is aligned
842 ifm
= (struct if_msghdr
*)(void *)buf
;
843 switch (ifm
->ifm_type
) {
845 #if defined(IF_HWASSIST_VLAN_TAGGING) && defined(IF_HWASSIST_VLAN_MTU)
846 struct if_data
*if_data
= &ifm
->ifm_data
;
848 if (if_data
->ifi_hwassist
& (IF_HWASSIST_VLAN_TAGGING
| IF_HWASSIST_VLAN_MTU
)) {
858 if (if_name
!= NULL
) CFAllocatorDeallocate(NULL
, if_name
);
859 if (buf
!= NULL
) CFAllocatorDeallocate(NULL
, buf
);
866 SCNetworkInterfacePrivateRef
867 _SCBondInterfaceCreatePrivate(CFAllocatorRef allocator
,
870 SCNetworkInterfacePrivateRef interfacePrivate
;
872 interfacePrivate
= __SCNetworkInterfaceCreatePrivate(allocator
, NULL
, NULL
, NULL
);
873 if (interfacePrivate
== NULL
) {
877 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeBond
;
878 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
879 interfacePrivate
->entity_device
= CFStringCreateCopy(allocator
, bond_if
);
880 interfacePrivate
->builtin
= TRUE
;
881 interfacePrivate
->supportsVLAN
= __SCNetworkInterfaceSupportsVLAN(bond_if
);
882 interfacePrivate
->sort_order
= kSortBond
;
884 interfacePrivate
->localized_key
= CFSTR("bond");
885 interfacePrivate
->localized_arg1
= CFRetain(interfacePrivate
->entity_device
);
887 interfacePrivate
->bond
.interfaces
= CFArrayCreate(NULL
, NULL
, 0, &kCFTypeArrayCallBacks
);
888 // interfacePrivate->bond.mode = NULL;
889 // interfacePrivate->bond.options = NULL;
891 return interfacePrivate
;
896 SCNetworkInterfacePrivateRef
897 _SCBridgeInterfaceCreatePrivate(CFAllocatorRef allocator
,
898 CFStringRef bridge_if
)
900 SCNetworkInterfacePrivateRef interfacePrivate
;
902 interfacePrivate
= __SCNetworkInterfaceCreatePrivate(allocator
, NULL
, NULL
, NULL
);
903 if (interfacePrivate
== NULL
) {
907 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeBridge
;
908 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
909 interfacePrivate
->entity_device
= CFStringCreateCopy(allocator
, bridge_if
);
910 interfacePrivate
->builtin
= TRUE
;
911 interfacePrivate
->supportsVLAN
= __SCNetworkInterfaceSupportsVLAN(bridge_if
);
912 interfacePrivate
->sort_order
= kSortBridge
;
914 interfacePrivate
->localized_key
= CFSTR("bridge");
915 interfacePrivate
->localized_arg1
= CFRetain(interfacePrivate
->entity_device
);
917 interfacePrivate
->bridge
.interfaces
= CFArrayCreate(NULL
, NULL
, 0, &kCFTypeArrayCallBacks
);
918 // interfacePrivate->bridge.options = NULL;
920 return interfacePrivate
;
925 SCNetworkInterfacePrivateRef
926 _SCVLANInterfaceCreatePrivate(CFAllocatorRef allocator
,
929 SCNetworkInterfacePrivateRef interfacePrivate
;
931 interfacePrivate
= __SCNetworkInterfaceCreatePrivate(allocator
, NULL
, NULL
, NULL
);
932 if (interfacePrivate
== NULL
) {
936 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeVLAN
;
937 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
938 interfacePrivate
->entity_device
= CFStringCreateCopy(allocator
, vlan_if
);
939 interfacePrivate
->builtin
= TRUE
;
940 interfacePrivate
->sort_order
= kSortVLAN
;
942 interfacePrivate
->localized_key
= CFSTR("vlan");
943 interfacePrivate
->localized_arg1
= CFRetain(interfacePrivate
->entity_device
);
945 // interfacePrivate->vlan.interface = NULL;
946 // interfacePrivate->vlan.tag = NULL;
947 // interfacePrivate->vlan.options = NULL;
949 return interfacePrivate
;
954 #pragma mark Interface ordering
957 static CF_RETURNS_RETAINED CFArrayRef
958 split_path(CFStringRef path
)
960 CFArrayRef components
;
961 CFMutableStringRef nPath
;
963 // turn '@'s into '/'s
964 nPath
= CFStringCreateMutableCopy(NULL
, 0, path
);
965 (void) CFStringFindAndReplace(nPath
,
968 CFRangeMake(0, CFStringGetLength(nPath
)),
971 // split path into components to be compared
972 components
= CFStringCreateArrayBySeparatingStrings(NULL
, nPath
, CFSTR("/"));
980 _SCNetworkInterfaceCompare(const void *val1
, const void *val2
, void *context
)
982 SCNetworkInterfacePrivateRef dev1
= (SCNetworkInterfacePrivateRef
)val1
;
983 SCNetworkInterfacePrivateRef dev2
= (SCNetworkInterfacePrivateRef
)val2
;
984 CFComparisonResult res
= kCFCompareEqualTo
;
986 /* sort by interface type */
987 if (dev1
->sort_order
!= dev2
->sort_order
) {
988 if (dev1
->sort_order
< dev2
->sort_order
) {
989 res
= kCFCompareLessThan
;
991 res
= kCFCompareGreaterThan
;
996 /* built-in interfaces sort first */
997 if (dev1
->builtin
!= dev2
->builtin
) {
999 res
= kCFCompareLessThan
;
1001 res
= kCFCompareGreaterThan
;
1006 /* ... and then, sort built-in interfaces by "location" */
1007 if (dev1
->builtin
) {
1008 if (dev1
->location
!= dev2
->location
) {
1009 if (isA_CFString(dev1
->location
)) {
1010 if (isA_CFString(dev2
->location
)) {
1011 res
= CFStringCompare(dev1
->location
, dev2
->location
, 0);
1013 res
= kCFCompareLessThan
;
1016 res
= kCFCompareGreaterThan
;
1019 if (res
!= kCFCompareEqualTo
) {
1025 /* ... and, then sort by IOPathMatch */
1026 if ((dev1
->path
!= NULL
) && (dev2
->path
!= NULL
)) {
1027 CFArrayRef elements1
;
1028 CFArrayRef elements2
;
1034 elements1
= split_path(dev1
->path
);
1035 n1
= CFArrayGetCount(elements1
);
1037 elements2
= split_path(dev2
->path
);
1038 n2
= CFArrayGetCount(elements2
);
1040 n
= (n1
<= n2
) ? n1
: n2
;
1041 for (i
= 0; i
< n
; i
++) {
1050 e1
= CFArrayGetValueAtIndex(elements1
, i
);
1051 e2
= CFArrayGetValueAtIndex(elements2
, i
);
1053 str
= _SC_cfstring_to_cstring(e1
, NULL
, 0, kCFStringEncodingUTF8
);
1055 q1
= strtoq(str
, &end
, 16);
1056 isNum
= ((*str
!= '\0') && (*end
== '\0') && (errno
== 0));
1057 CFAllocatorDeallocate(NULL
, str
);
1060 // if e1 is a valid numeric string
1061 str
= _SC_cfstring_to_cstring(e2
, NULL
, 0, kCFStringEncodingUTF8
);
1063 q2
= strtoq(str
, &end
, 16);
1064 isNum
= ((*str
!= '\0') && (*end
== '\0') && (errno
== 0));
1065 CFAllocatorDeallocate(NULL
, str
);
1068 // if e2 is also a valid numeric string
1071 res
= kCFCompareEqualTo
;
1073 } else if (q1
< q2
) {
1074 res
= kCFCompareLessThan
;
1076 res
= kCFCompareGreaterThan
;
1082 res
= CFStringCompare(e1
, e2
, 0);
1083 if (res
!= kCFCompareEqualTo
) {
1088 if (res
== kCFCompareEqualTo
) {
1090 res
= kCFCompareLessThan
;
1091 } else if (n1
< n2
) {
1092 res
= kCFCompareGreaterThan
;
1096 CFRelease(elements1
);
1097 CFRelease(elements2
);
1099 if (res
!= kCFCompareEqualTo
) {
1104 /* ... and, then sort by BSD interface name */
1105 if ((dev1
->entity_device
!= NULL
) && (dev2
->entity_device
!= NULL
)) {
1106 res
= CFStringCompare(dev1
->entity_device
, dev2
->entity_device
, 0);
1107 if (res
!= kCFCompareEqualTo
) {
1112 /* ... and lastly, sort by BSD interface unique identifier */
1113 if ((dev1
->entity_device_unique
!= NULL
) && (dev2
->entity_device_unique
!= NULL
)) {
1114 res
= CFStringCompare(dev1
->entity_device_unique
, dev2
->entity_device_unique
, 0);
1115 // if (res != kCFCompareEqualTo) {
1125 sort_interfaces(CFMutableArrayRef all_interfaces
)
1127 int n
= CFArrayGetCount(all_interfaces
);
1133 CFArraySortValues(all_interfaces
, CFRangeMake(0, n
), _SCNetworkInterfaceCompare
, NULL
);
1140 __SCNetworkInterfaceOrder(SCNetworkInterfaceRef interface
)
1142 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
1144 return interfacePrivate
->sort_order
;
1149 #pragma mark Interface details
1153 IOCopyCFStringValue(CFTypeRef ioVal
)
1155 if (isA_CFString(ioVal
)) {
1156 return CFStringCreateCopy(NULL
, ioVal
);
1159 if (isA_CFData(ioVal
)) {
1160 return CFStringCreateWithCString(NULL
,
1161 (const char *)CFDataGetBytePtr(ioVal
),
1162 kCFStringEncodingUTF8
);
1170 IODictionaryCopyCFStringValue(CFDictionaryRef io_dict
, CFStringRef io_key
)
1174 ioVal
= CFDictionaryGetValue(io_dict
, io_key
);
1175 return IOCopyCFStringValue(ioVal
);
1180 IOStringValueHasPrefix(CFTypeRef ioVal
, CFStringRef prefix
)
1182 Boolean match
= FALSE
;
1183 CFIndex prefixLen
= CFStringGetLength(prefix
);
1184 CFStringRef str
= NULL
;
1186 if (!isA_CFString(ioVal
)) {
1187 if (isA_CFData(ioVal
)) {
1188 str
= CFStringCreateWithCStringNoCopy(NULL
,
1189 (const char *)CFDataGetBytePtr(ioVal
),
1190 kCFStringEncodingUTF8
,
1198 if ((ioVal
!= NULL
) &&
1199 (CFStringGetLength(ioVal
) >= prefixLen
) &&
1200 (CFStringCompareWithOptions(ioVal
,
1202 CFRangeMake(0, prefixLen
),
1203 kCFCompareCaseInsensitive
) == kCFCompareEqualTo
)) {
1207 if (str
!= NULL
) CFRelease(str
);
1212 static const struct {
1213 const CFStringRef name
;
1214 const CFStringRef slot
;
1215 } slot_mappings
[] = {
1217 { CFSTR("A1") , CFSTR("1") },
1218 { CFSTR("B1") , CFSTR("2") },
1219 { CFSTR("C1") , CFSTR("3") },
1221 // Blue&White G3, Yikes G4
1222 { CFSTR("J12"), CFSTR("1") },
1223 { CFSTR("J11"), CFSTR("2") },
1224 { CFSTR("J10"), CFSTR("3") },
1225 { CFSTR("J9"), CFSTR("4") },
1228 { CFSTR("A") , CFSTR("1") },
1229 { CFSTR("B") , CFSTR("2") },
1230 { CFSTR("C") , CFSTR("3") },
1231 { CFSTR("D") , CFSTR("4") },
1233 // Digital Audio G4 (and later models)
1234 { CFSTR("1") , CFSTR("1") },
1235 { CFSTR("2") , CFSTR("2") },
1236 { CFSTR("3") , CFSTR("3") },
1237 { CFSTR("4") , CFSTR("4") },
1238 { CFSTR("5") , CFSTR("5") }
1242 static const CFStringRef slot_prefixes
[] = {
1243 CFSTR("thunderbolt slot "),
1249 static CF_RETURNS_RETAINED CFStringRef
1250 pci_slot(io_registry_entry_t interface
, CFTypeRef
*pci_slot_name
)
1253 io_registry_entry_t parent
;
1254 CFMutableStringRef slot
;
1255 CFTypeRef slot_name
;
1258 if (pci_slot_name
!= NULL
) *pci_slot_name
= NULL
;
1260 slot_name
= IORegistryEntryCreateCFProperty(interface
, CFSTR("AAPL,slot-name"), NULL
, 0);
1261 if (slot_name
!= NULL
) {
1264 slot
= CFStringCreateMutable(NULL
, 0);
1265 if (isA_CFString(slot_name
)) {
1266 if (pci_slot_name
!= NULL
) *pci_slot_name
= CFStringCreateCopy(NULL
, slot_name
);
1267 CFStringAppend(slot
, slot_name
);
1268 } else if (isA_CFData(slot_name
)) {
1269 if (pci_slot_name
!= NULL
) *pci_slot_name
= CFDataCreateCopy(NULL
, slot_name
);
1270 CFStringAppendCString(slot
,
1271 (const char *)CFDataGetBytePtr(slot_name
),
1272 kCFStringEncodingUTF8
);
1275 for (i
= 0; i
< sizeof(slot_prefixes
)/sizeof(slot_prefixes
[0]); i
++) {
1278 len
= CFStringGetLength(slot_prefixes
[i
]);
1279 if (CFStringGetLength(slot
) > len
) {
1280 (void) CFStringFindAndReplace(slot
,
1283 CFRangeMake(0, len
),
1284 kCFCompareCaseInsensitive
|kCFCompareAnchored
);
1288 for (i
= 0; i
< sizeof(slot_mappings
)/sizeof(slot_mappings
[0]); i
++) {
1289 if (CFStringCompare(slot
,
1290 slot_mappings
[i
].name
,
1291 kCFCompareCaseInsensitive
) == kCFCompareEqualTo
) {
1293 slot
= (CFMutableStringRef
)CFRetain(slot_mappings
[i
].slot
);
1298 CFRelease(slot_name
);
1301 kr
= IORegistryEntryGetParentEntry(interface
, kIOServicePlane
, &parent
);
1303 case kIOReturnSuccess
: {
1304 CFTypeRef parent_pci_slot_name
= NULL
;
1305 CFStringRef parent_slot
;
1307 parent_slot
= pci_slot(parent
, &parent_pci_slot_name
);
1308 if (parent_slot
!= NULL
) {
1309 if (slot
!= NULL
) CFRelease(slot
);
1310 slot
= (CFMutableStringRef
)parent_slot
;
1312 if (pci_slot_name
!= NULL
) {
1313 if (*pci_slot_name
!= NULL
) CFRelease(*pci_slot_name
);
1314 *pci_slot_name
= parent_pci_slot_name
;
1316 CFRelease(parent_pci_slot_name
);
1320 IOObjectRelease(parent
);
1323 case kIOReturnNoDevice
:
1324 // if we have hit the root node
1327 SCLog(TRUE
, LOG_DEBUG
, CFSTR("pci_slot IORegistryEntryGetParentEntry() failed, kr = 0x%x"), kr
);
1335 static CFComparisonResult
1336 compare_bsdNames(const void *val1
, const void *val2
, void *context
)
1338 CFStringRef bsd1
= (CFStringRef
)val1
;
1339 CFStringRef bsd2
= (CFStringRef
)val2
;
1341 return CFStringCompare(bsd1
, bsd2
, 0);
1345 static CF_RETURNS_RETAINED CFStringRef
1346 pci_port(CFTypeRef slot_name
, int ift
, CFStringRef bsdName
)
1349 CFStringRef port_name
= NULL
;
1350 CFMutableArrayRef port_names
;
1353 CFStringRef match_keys
[2];
1354 CFTypeRef match_vals
[2];
1355 CFDictionaryRef match_dict
;
1356 CFDictionaryRef matching
;
1357 io_registry_entry_t slot
;
1358 io_iterator_t slot_iterator
= MACH_PORT_NULL
;
1360 match_keys
[0] = CFSTR("AAPL,slot-name");
1361 match_vals
[0] = slot_name
;
1363 match_dict
= CFDictionaryCreate(NULL
,
1364 (const void **)match_keys
,
1365 (const void **)match_vals
,
1367 &kCFTypeDictionaryKeyCallBacks
,
1368 &kCFTypeDictionaryValueCallBacks
);
1370 match_keys
[0] = CFSTR(kIOProviderClassKey
);
1371 match_vals
[0] = CFSTR("IOPCIDevice");
1373 match_keys
[1] = CFSTR(kIOPropertyMatchKey
);
1374 match_vals
[1] = match_dict
;
1376 // note: the "matching" dictionary will be consumed by the following
1377 matching
= CFDictionaryCreate(NULL
,
1378 (const void **)match_keys
,
1379 (const void **)match_vals
,
1380 sizeof(match_keys
)/sizeof(match_keys
[0]),
1381 &kCFTypeDictionaryKeyCallBacks
,
1382 &kCFTypeDictionaryValueCallBacks
);
1383 CFRelease(match_dict
);
1385 kr
= IOServiceGetMatchingServices(masterPort
, matching
, &slot_iterator
);
1386 if (kr
!= kIOReturnSuccess
) {
1387 SCLog(TRUE
, LOG_DEBUG
, CFSTR("pci_port IOServiceGetMatchingServices() failed, kr = 0x%x"), kr
);
1388 return MACH_PORT_NULL
;
1391 port_names
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1393 while ((slot
= IOIteratorNext(slot_iterator
)) != MACH_PORT_NULL
) {
1394 io_registry_entry_t child
;
1395 io_iterator_t child_iterator
= MACH_PORT_NULL
;
1397 kr
= IORegistryEntryCreateIterator(slot
,
1399 kIORegistryIterateRecursively
,
1401 if (kr
!= kIOReturnSuccess
) {
1402 SCLog(TRUE
, LOG_DEBUG
, CFSTR("pci_port IORegistryEntryCreateIterator() failed, kr = 0x%x"), kr
);
1403 CFRelease(port_names
);
1404 return MACH_PORT_NULL
;
1407 while ((child
= IOIteratorNext(child_iterator
)) != MACH_PORT_NULL
) {
1408 if (IOObjectConformsTo(child
, kIONetworkInterfaceClass
)) {
1409 CFNumberRef child_if_type
;
1410 int child_ift
= ift
;
1412 child_if_type
= IORegistryEntryCreateCFProperty(child
,
1413 CFSTR(kIOInterfaceType
),
1416 if (child_if_type
!= NULL
) {
1417 if (!isA_CFNumber(child_if_type
) ||
1418 !CFNumberGetValue(child_if_type
, kCFNumberIntType
, &child_ift
)) {
1419 // assume that it's a match
1422 CFRelease(child_if_type
);
1425 if (ift
== child_ift
) {
1426 CFStringRef if_bsdName
;
1428 if_bsdName
= IORegistryEntryCreateCFProperty(child
,
1429 CFSTR(kIOBSDNameKey
),
1432 if (if_bsdName
!= NULL
) {
1433 CFArrayAppendValue(port_names
, if_bsdName
);
1434 CFRelease(if_bsdName
);
1438 IOObjectRelease(child
);
1440 IOObjectRelease(child_iterator
);
1441 IOObjectRelease(slot
);
1443 IOObjectRelease(slot_iterator
);
1445 n
= CFArrayGetCount(port_names
);
1447 CFArraySortValues(port_names
, CFRangeMake(0, n
), compare_bsdNames
, NULL
);
1448 n
= CFArrayGetFirstIndexOfValue(port_names
, CFRangeMake(0, n
), bsdName
);
1449 if (n
!= kCFNotFound
) {
1450 port_name
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), n
+ 1);
1454 CFRelease(port_names
);
1460 pci_slot_info(io_registry_entry_t interface
, int ift
, CFStringRef
*slot_name
, CFStringRef
*port_name
)
1462 CFStringRef bsd_name
;
1464 CFTypeRef pci_slot_name
;
1469 bsd_name
= IORegistryEntryCreateCFProperty(interface
, CFSTR(kIOBSDNameKey
), NULL
, 0);
1470 if (bsd_name
== NULL
) {
1474 *slot_name
= pci_slot(interface
, &pci_slot_name
);
1475 if (*slot_name
!= NULL
) {
1476 if (pci_slot_name
!= NULL
) {
1477 *port_name
= pci_port(pci_slot_name
, ift
, bsd_name
);
1478 CFRelease(pci_slot_name
);
1483 CFRelease(bsd_name
);
1489 isBuiltin(io_registry_entry_t interface
)
1493 slot
= pci_slot(interface
, NULL
);
1495 // interfaces which have a "slot" are not built-in
1505 isBluetoothBuiltin(Boolean
*haveController
)
1507 Boolean builtin
= FALSE
;
1508 io_object_t hciController
;
1509 io_iterator_t iter
= MACH_PORT_NULL
;
1512 kr
= IOServiceGetMatchingServices(masterPort
,
1513 IOServiceMatching("IOBluetoothHCIController"),
1515 if ((kr
!= kIOReturnSuccess
) || (iter
== MACH_PORT_NULL
)) {
1516 if (kr
!= kIOReturnSuccess
) {
1517 SCLog(TRUE
, LOG_DEBUG
, CFSTR("isBluetoothBuiltin IOServiceGetMatchingServices() failed, kr = 0x%x"), kr
);
1519 *haveController
= FALSE
;
1522 *haveController
= TRUE
;
1524 hciController
= IOIteratorNext(iter
);
1525 IOObjectRelease(iter
);
1526 if(hciController
!= MACH_PORT_NULL
) {
1527 CFNumberRef idVendor
;
1529 idVendor
= IORegistryEntryCreateCFProperty(hciController
, CFSTR(kUSBVendorID
), NULL
, 0);
1530 if (idVendor
!= NULL
) {
1533 if (isA_CFNumber(idVendor
) &&
1534 CFNumberGetValue(idVendor
, kCFNumberIntType
, &idVendorVal
) &&
1535 (idVendorVal
== kIOUSBVendorIDAppleComputer
)) {
1539 CFRelease(idVendor
);
1542 IOObjectRelease(hciController
);
1550 isThunderbolt(io_registry_entry_t interface
)
1554 val
= IORegistryEntrySearchCFProperty(interface
,
1556 CFSTR(kPCIThunderboltString
),
1558 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
1569 processUSBInterface(SCNetworkInterfacePrivateRef interfacePrivate
,
1570 io_registry_entry_t interface
,
1571 CFDictionaryRef interface_dict
,
1572 io_registry_entry_t controller
,
1573 CFDictionaryRef controller_dict
,
1574 io_registry_entry_t bus
,
1575 CFDictionaryRef bus_dict
)
1578 interfacePrivate
->usb
.name
= IORegistryEntrySearchCFProperty(interface
,
1580 CFSTR(kUSBProductString
),
1582 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
1583 interfacePrivate
->usb
.vid
= IORegistryEntrySearchCFProperty(interface
,
1585 CFSTR(kUSBVendorID
),
1587 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
1588 interfacePrivate
->usb
.pid
= IORegistryEntrySearchCFProperty(interface
,
1590 CFSTR(kUSBProductID
),
1592 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
1599 update_interface_name(SCNetworkInterfacePrivateRef interfacePrivate
,
1600 io_registry_entry_t interface
,
1603 Boolean updated
= FALSE
;
1606 // check if a "Product Name" has been provided
1607 val
= IORegistryEntrySearchCFProperty(interface
,
1609 CFSTR(kIOPropertyProductNameKey
),
1611 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
1612 if ((val
== NULL
) && useUSBInfo
&& (interfacePrivate
->usb
.name
!= NULL
)) {
1613 // else, use "USB Product Name" if available
1614 val
= CFRetain(interfacePrivate
->usb
.name
);
1617 CFStringRef productName
;
1619 productName
= IOCopyCFStringValue(val
);
1622 if (productName
!= NULL
) {
1623 if (CFStringGetLength(productName
) > 0) {
1624 // if we have a [somewhat reasonable?] product name
1625 if (interfacePrivate
->name
!= NULL
) {
1626 CFRelease(interfacePrivate
->name
);
1628 interfacePrivate
->name
= CFRetain(productName
);
1629 if (interfacePrivate
->localized_name
!= NULL
) {
1630 CFRelease(interfacePrivate
->localized_name
);
1632 interfacePrivate
->localized_name
= copy_interface_string(bundle
, productName
, TRUE
);
1637 CFRelease(productName
);
1646 #pragma mark Interface enumeration
1649 typedef Boolean (*processInterface
)(SCNetworkInterfacePrivateRef interfacePrivate
,
1650 io_registry_entry_t interface
,
1651 CFDictionaryRef interface_dict
,
1652 io_registry_entry_t controller
,
1653 CFDictionaryRef controller_dict
,
1654 io_registry_entry_t bus
,
1655 CFDictionaryRef bus_dict
);
1659 merge_override(SCNetworkInterfacePrivateRef interfacePrivate
,
1660 io_registry_entry_t interface
,
1661 CFStringRef override
)
1666 key
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("Device%@Overrides"), override
);
1667 val
= IORegistryEntrySearchCFProperty(interface
,
1671 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
1674 if (isA_CFDictionary(val
)) {
1675 if (interfacePrivate
->overrides
== NULL
) {
1676 interfacePrivate
->overrides
= CFDictionaryCreateMutable(NULL
,
1678 &kCFTypeDictionaryKeyCallBacks
,
1679 &kCFTypeDictionaryValueCallBacks
);
1681 CFDictionarySetValue(interfacePrivate
->overrides
, override
, val
);
1691 processNetworkInterface(SCNetworkInterfacePrivateRef interfacePrivate
,
1692 io_registry_entry_t interface
,
1693 CFDictionaryRef interface_dict
,
1694 io_registry_entry_t controller
,
1695 CFDictionaryRef controller_dict
,
1696 io_registry_entry_t bus
,
1697 CFDictionaryRef bus_dict
)
1707 num
= CFDictionaryGetValue(interface_dict
, CFSTR(kIOInterfaceType
));
1708 if (isA_CFNumber(num
) &&
1709 CFNumberGetValue(num
, kCFNumberIntType
, &ift
)) {
1710 interfacePrivate
->type
= CFRetain(num
);
1712 SCLog(TRUE
, LOG_DEBUG
, CFSTR("processNetworkInterface() failed, no interface type"));
1720 if ((IOObjectConformsTo(controller
, "IO80211Controller")) ||
1721 (IOObjectConformsTo(controller
, "AirPortPCI" )) ||
1722 (IOObjectConformsTo(controller
, "AirPortDriver" ))) {
1723 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeIEEE80211
;
1724 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1725 interfacePrivate
->sort_order
= kSortAirPort
;
1726 } else if (IOObjectConformsTo(controller
, "IOBluetoothBNEPDriver")) {
1727 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
1728 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1729 interfacePrivate
->sort_order
= kSortBluetoothPAN_GN
;
1730 } else if (IOObjectConformsTo(controller
, "AppleUSBEthernetHost")) {
1731 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
1732 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1733 interfacePrivate
->sort_order
= kSortTethered
;
1734 } else if (IOObjectConformsTo(controller
, "AppleUSBCDCECMData")) {
1735 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
1736 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1737 interfacePrivate
->sort_order
= kSortWWANEthernet
;
1740 if (interfacePrivate
->interface_type
== NULL
) {
1741 val
= IORegistryEntrySearchCFProperty(interface
,
1743 CFSTR(kIOUserEthernetInterfaceRoleKey
),
1745 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
1747 if (isA_CFString(val
)) {
1748 if (CFEqual(val
, CFSTR("Bluetooth PAN"))) {
1749 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
1750 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1751 interfacePrivate
->sort_order
= kSortBluetoothPAN_GN
;
1752 } else if (CFEqual(val
, CFSTR("Bluetooth PAN-NAP"))) {
1753 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
1754 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1755 interfacePrivate
->sort_order
= kSortBluetoothPAN_NAP
;
1756 } else if (CFEqual(val
, CFSTR("Bluetooth P2P"))) {
1757 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
1758 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1759 interfacePrivate
->sort_order
= kSortBluetoothPAN_U
;
1767 if (interfacePrivate
->interface_type
== NULL
) {
1768 str
= IODictionaryCopyCFStringValue(bus_dict
, CFSTR("name"));
1770 if (CFEqual(str
, CFSTR("radio"))) {
1771 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
; // ??
1772 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1773 interfacePrivate
->sort_order
= kSortOtherWireless
;
1780 if (interfacePrivate
->interface_type
== NULL
) {
1781 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
1782 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeEthernet
;
1783 interfacePrivate
->sort_order
= kSortEthernet
;
1785 // BOND support only enabled for ethernet devices
1786 interfacePrivate
->supportsBond
= TRUE
;
1789 // enable Bridge support
1790 interfacePrivate
->supportsBridge
= TRUE
;
1793 val
= isA_CFBoolean(CFDictionaryGetValue(interface_dict
, CFSTR(kIOBuiltin
)));
1795 val
= isA_CFBoolean(CFDictionaryGetValue(interface_dict
, CFSTR(kIOPrimaryInterface
)));
1798 interfacePrivate
->builtin
= CFBooleanGetValue(val
);
1800 interfacePrivate
->builtin
= isBuiltin(interface
);
1803 if (!interfacePrivate
->builtin
&&
1804 CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeIEEE80211
)) {
1805 // always treat AirPort interfaces as built-in
1806 interfacePrivate
->builtin
= TRUE
;
1810 interfacePrivate
->location
= IODictionaryCopyCFStringValue(interface_dict
, CFSTR(kIOLocation
));
1813 num
= CFDictionaryGetValue(controller_dict
, CFSTR(kIOFeatures
));
1814 if (isA_CFNumber(num
) &&
1815 CFNumberGetValue(num
, kCFNumberIntType
, & iVal
)) {
1816 if (iVal
& (kIONetworkFeatureHardwareVlan
| kIONetworkFeatureSoftwareVlan
)) {
1817 interfacePrivate
->supportsVLAN
= TRUE
;
1822 if (CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeIEEE80211
)) {
1823 interfacePrivate
->localized_key
= CFSTR("airport");
1824 } else if (interfacePrivate
->sort_order
== kSortBluetoothPAN_GN
) {
1825 interfacePrivate
->localized_key
= CFSTR("bluetooth-pan-gn");
1826 } else if (interfacePrivate
->sort_order
== kSortBluetoothPAN_NAP
) {
1827 interfacePrivate
->localized_key
= CFSTR("bluetooth-pan-nap");
1828 } else if (interfacePrivate
->sort_order
== kSortBluetoothPAN_U
) {
1829 interfacePrivate
->localized_key
= CFSTR("bluetooth-pan-u");
1830 } else if (interfacePrivate
->sort_order
== kSortOtherWireless
) {
1831 interfacePrivate
->localized_key
= CFSTR("wireless");
1832 interfacePrivate
->localized_arg1
= CFRetain(CFSTR("")); // ??
1833 } else if (interfacePrivate
->builtin
) {
1834 if ((interfacePrivate
->location
== NULL
) ||
1835 (CFStringGetLength(interfacePrivate
->location
) == 0)) {
1836 interfacePrivate
->localized_key
= CFSTR("ether");
1838 interfacePrivate
->localized_key
= CFSTR("multiether");
1839 interfacePrivate
->localized_arg1
= CFRetain(interfacePrivate
->location
);
1842 CFStringRef provider
;
1844 // check provider class
1845 provider
= IORegistryEntrySearchCFProperty(interface
,
1847 CFSTR(kIOProviderClassKey
),
1849 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
1850 if (provider
!= NULL
) {
1851 if (CFEqual(provider
, CFSTR("IOPCIDevice"))) {
1852 CFStringRef port_name
;
1853 CFStringRef slot_name
;
1855 // set interface "name"
1856 if (!update_interface_name(interfacePrivate
, interface
, FALSE
) &&
1857 pci_slot_info(interface
, ift
, &slot_name
, &port_name
)) {
1858 if (isThunderbolt(interface
)) {
1859 if (port_name
== NULL
) {
1860 interfacePrivate
->localized_key
= CFSTR("thunderbolt-ether");
1861 interfacePrivate
->localized_arg1
= slot_name
;
1863 interfacePrivate
->localized_key
= CFSTR("thunderbolt-multiether");
1864 interfacePrivate
->localized_arg1
= slot_name
;
1865 interfacePrivate
->localized_arg2
= port_name
;
1869 if (port_name
== NULL
) {
1870 interfacePrivate
->localized_key
= CFSTR("pci-ether");
1871 interfacePrivate
->localized_arg1
= slot_name
;
1873 interfacePrivate
->localized_key
= CFSTR("pci-multiether");
1874 interfacePrivate
->localized_arg1
= slot_name
;
1875 interfacePrivate
->localized_arg2
= port_name
;
1879 } else if (CFEqual(provider
, CFSTR("IOUSBDevice")) ||
1880 CFEqual(provider
, CFSTR("IOUSBInterface"))) {
1881 // get USB info (if available)
1882 processUSBInterface(interfacePrivate
,
1890 // set interface "name"
1891 if (!update_interface_name(interfacePrivate
, interface
, TRUE
)) {
1892 interfacePrivate
->localized_key
= CFSTR("usb-ether");
1893 interfacePrivate
->localized_arg1
= IODictionaryCopyCFStringValue(interface_dict
, CFSTR(kIOBSDNameKey
));
1896 CFRelease(provider
);
1899 if (interfacePrivate
->localized_key
== NULL
) {
1900 // if no provider, not a PCI device, or no slot information
1901 interfacePrivate
->localized_key
= CFSTR("generic-ether");
1902 interfacePrivate
->localized_arg1
= IODictionaryCopyCFStringValue(interface_dict
, CFSTR(kIOBSDNameKey
));
1909 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeFireWire
;
1912 interfacePrivate
->entity_type
= kSCValNetInterfaceTypeFireWire
;
1915 interfacePrivate
->builtin
= isBuiltin(interface
);
1918 interfacePrivate
->sort_order
= kSortFireWire
;
1921 if (interfacePrivate
->builtin
) {
1922 interfacePrivate
->localized_key
= CFSTR("firewire");
1924 CFStringRef port_name
;
1925 CFStringRef slot_name
;
1927 // set interface "name"
1928 if (!update_interface_name(interfacePrivate
, interface
, FALSE
) &&
1929 pci_slot_info(interface
, ift
, &slot_name
, &port_name
)) {
1930 if (isThunderbolt(interface
)) {
1931 if (port_name
== NULL
) {
1932 interfacePrivate
->localized_key
= CFSTR("thunderbolt-firewire");
1933 interfacePrivate
->localized_arg1
= slot_name
;
1935 interfacePrivate
->localized_key
= CFSTR("thunderbolt-multifirewire");
1936 interfacePrivate
->localized_arg1
= slot_name
;
1937 interfacePrivate
->localized_arg2
= port_name
;
1940 if (port_name
== NULL
) {
1941 interfacePrivate
->localized_key
= CFSTR("pci-firewire");
1942 interfacePrivate
->localized_arg1
= slot_name
;
1944 interfacePrivate
->localized_key
= CFSTR("pci-multifirewire");
1945 interfacePrivate
->localized_arg1
= slot_name
;
1946 interfacePrivate
->localized_arg2
= port_name
;
1954 SCLog(TRUE
, LOG_DEBUG
, CFSTR("processNetworkInterface() failed, unknown interface type = %d"), ift
);
1959 interfacePrivate
->entity_device
= IODictionaryCopyCFStringValue(interface_dict
, CFSTR(kIOBSDNameKey
));
1961 // Hardware (MAC) address
1962 data
= CFDictionaryGetValue(controller_dict
, CFSTR(kIOMACAddress
));
1963 if (isA_CFData(data
)) {
1964 interfacePrivate
->address
= CFRetain(data
);
1968 num
= CFDictionaryGetValue(interface_dict
, CFSTR(kIOInterfaceUnit
));
1969 if (isA_CFNumber(num
) &&
1970 CFNumberGetValue(num
, kCFNumberIntType
, & iVal
)) {
1971 interfacePrivate
->unit
= CFRetain(num
);
1974 // configuration [PPP] template override (now deprecated, use NetworkConfigurationOverrides)
1975 merge_override(interfacePrivate
, interface
, kSCNetworkInterfaceTypePPP
);
1982 set_connection_script(SCNetworkInterfacePrivateRef interfacePrivate
, CFStringRef script
)
1984 CFDictionaryRef dict
;
1985 CFMutableDictionaryRef newDict
;
1987 if (interfacePrivate
->overrides
== NULL
) {
1988 interfacePrivate
->overrides
= CFDictionaryCreateMutable(NULL
,
1990 &kCFTypeDictionaryKeyCallBacks
,
1991 &kCFTypeDictionaryValueCallBacks
);
1994 dict
= CFDictionaryGetValue(interfacePrivate
->overrides
, kSCNetworkInterfaceTypeModem
);
1996 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
1998 newDict
= CFDictionaryCreateMutable(NULL
,
2000 &kCFTypeDictionaryKeyCallBacks
,
2001 &kCFTypeDictionaryValueCallBacks
);
2003 if (script
!= NULL
) {
2004 CFDictionarySetValue(newDict
, kSCPropNetModemConnectionScript
, script
);
2006 CFDictionaryRemoveValue(newDict
, kSCPropNetModemConnectionScript
);
2008 if (CFDictionaryGetCount(newDict
) > 0) {
2009 CFDictionarySetValue(interfacePrivate
->overrides
, kSCNetworkInterfaceTypeModem
, newDict
);
2011 CFDictionaryRemoveValue(interfacePrivate
->overrides
, kSCNetworkInterfaceTypeModem
);
2015 if (CFDictionaryGetCount(interfacePrivate
->overrides
) == 0) {
2016 CFRelease(interfacePrivate
->overrides
);
2017 interfacePrivate
->overrides
= NULL
;
2024 is_valid_connection_script(CFStringRef script
)
2026 char ccl
[MAXPATHLEN
];
2027 char path
[MAXPATHLEN
];
2028 NSSearchPathEnumerationState state
;
2030 (void) _SC_cfstring_to_cstring(script
,
2033 kCFStringEncodingUTF8
);
2035 state
= NSStartSearchPathEnumeration(NSLibraryDirectory
,
2036 NSLocalDomainMask
|NSSystemDomainMask
);
2037 while ((state
= NSGetNextSearchPathEnumeration(state
, path
))) {
2039 struct stat statBuf
;
2041 if (ccl
[0] == '/') {
2042 path
[0] = '\0'; // if modemCCL is a full path
2044 strlcat(path
, "/Modem Scripts/", sizeof(path
));
2046 strlcat(path
, ccl
, sizeof(path
));
2048 if (stat(path
, &statBuf
) != 0) {
2049 if (errno
== ENOENT
) {
2053 SCLog(TRUE
, LOG_DEBUG
,
2054 CFSTR("processSerialInterface stat() failed: %s"),
2058 if (S_ISREG(statBuf
.st_mode
)) {
2059 // if we have a valid CCL script
2063 #define BUNDLE_EXT ".ccl"
2064 #define BUNDLE_EXT_LEN sizeof(BUNDLE_EXT) - 1
2069 if ((n
<= BUNDLE_EXT_LEN
) ||
2070 (strstr(&path
[n
- BUNDLE_EXT_LEN
], BUNDLE_EXT
) == NULL
)) {
2071 strlcat(path
, BUNDLE_EXT
, sizeof(path
));
2072 if (stat(path
, &statBuf
) != 0) {
2073 if (errno
== ENOENT
) {
2077 SCLog(TRUE
, LOG_DEBUG
,
2078 CFSTR("processSerialInterface stat() failed: %s"),
2083 if (S_ISDIR(statBuf
.st_mode
)) {
2084 // if we have a valid CCL bundle
2094 processSerialInterface(SCNetworkInterfacePrivateRef interfacePrivate
,
2095 io_registry_entry_t interface
,
2096 CFDictionaryRef interface_dict
,
2097 io_registry_entry_t controller
,
2098 CFDictionaryRef controller_dict
,
2099 io_registry_entry_t bus
,
2100 CFDictionaryRef bus_dict
)
2102 CFStringRef base
= NULL
;
2104 Boolean isModem
= FALSE
;
2105 Boolean isWWAN
= FALSE
;
2106 CFStringRef modemCCL
= NULL
;
2111 val
= IORegistryEntrySearchCFProperty(interface
,
2113 kSCNetworkInterfaceHiddenPortKey
,
2115 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
2118 return FALSE
; // if this interface should not be exposed
2121 // check if initializing
2122 val
= IORegistryEntrySearchCFProperty(interface
,
2124 kSCNetworkInterfaceInitializingKey
,
2126 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
2128 Boolean initializing
;
2130 initializing
= isA_CFBoolean(val
) && CFBooleanGetValue(val
);
2133 return FALSE
; // if this interface is still initializing
2138 val
= IORegistryEntrySearchCFProperty(interface
,
2142 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
2144 isWWAN
= isA_CFBoolean(val
) && CFBooleanGetValue(val
);
2149 interfacePrivate
->entity_device
= IODictionaryCopyCFStringValue(interface_dict
, CFSTR(kIOTTYDeviceKey
));
2150 if (interfacePrivate
->entity_device
== NULL
) {
2154 base
= IODictionaryCopyCFStringValue(interface_dict
, CFSTR(kIOTTYBaseNameKey
));
2156 base
= CFRetain(interfacePrivate
->entity_device
);
2162 * Exclude ports named "irda" because otherwise the IrDA ports on the
2163 * original iMac (rev's A through D) show up as serial ports. Given
2164 * that only the rev A actually had an IrDA port, and Mac OS X doesn't
2165 * even support it, these ports definitely shouldn't be listed.
2167 if (CFStringCompare(base
,
2169 kCFCompareCaseInsensitive
) == kCFCompareEqualTo
) {
2173 if (IOStringValueHasPrefix(base
, CFSTR("bluetooth"))) {
2174 Boolean haveController
= FALSE
;
2177 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeBluetooth
;
2178 interfacePrivate
->sort_order
= kSortBluetooth
;
2179 interfacePrivate
->builtin
= isBluetoothBuiltin(&haveController
);
2180 if (!haveController
) {
2181 // if device with no controller present
2184 } else if (IOStringValueHasPrefix(base
, CFSTR("irda-ircomm"))) {
2186 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeIrDA
;
2187 interfacePrivate
->sort_order
= kSortIrDA
;
2188 } else if (isWWAN
) {
2190 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeWWAN
;
2191 interfacePrivate
->sort_order
= kSortWWAN
;
2194 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeModem
;
2195 interfacePrivate
->sort_order
= kSortModem
;
2198 val
= IORegistryEntrySearchCFProperty(interface
,
2200 CFSTR(kIODeviceSupportsHoldKey
),
2202 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
2206 if (isA_CFNumber(val
) &&
2207 CFNumberGetValue(val
, kCFNumberSInt32Type
, &v92
)) {
2208 interfacePrivate
->modemIsV92
= (v92
== 1);
2215 interfacePrivate
->entity_type
= kSCEntNetModem
;
2217 // Entity (Hardware)
2218 ift
= CFDictionaryGetValue(interface_dict
, CFSTR(kIOSerialBSDTypeKey
));
2219 if (!isA_CFString(ift
)) {
2223 if (CFEqual(ift
, CFSTR(kIOSerialBSDModemType
))) {
2227 if (CFEqual(base
, CFSTR("modem"))) {
2228 interfacePrivate
->builtin
= TRUE
;
2229 interfacePrivate
->sort_order
= kSortInternalModem
;
2230 } else if (CFEqual(base
, CFSTR("usbmodem"))) {
2231 interfacePrivate
->sort_order
= kSortUSBModem
;
2233 } else if (CFEqual(ift
, CFSTR(kIOSerialBSDRS232Type
))) {
2235 interfacePrivate
->sort_order
= kSortSerialPort
;
2240 // configuration [PPP] template override (now deprecated, use NetworkConfigurationOverrides)
2241 merge_override(interfacePrivate
, interface
, kSCNetworkInterfaceTypePPP
);
2243 // configuration [Modem] template override (now deprecated, use NetworkConfigurationOverrides)
2244 merge_override(interfacePrivate
, interface
, kSCNetworkInterfaceTypeModem
);
2246 // look for modem CCL, unique identifier
2247 if (interfacePrivate
->overrides
!= NULL
) {
2248 val
= CFDictionaryGetValue(interfacePrivate
->overrides
, kSCNetworkInterfaceTypeModem
);
2250 CFStringRef uniqueID
;
2252 modemCCL
= CFDictionaryGetValue(val
, kSCPropNetModemConnectionScript
);
2253 modemCCL
= isA_CFString(modemCCL
);
2255 uniqueID
= CFDictionaryGetValue(val
, CFSTR("UniqueIdentifier"));
2256 uniqueID
= isA_CFString(uniqueID
);
2257 if (uniqueID
!= NULL
) {
2258 // retain the device's base name and the unique id
2259 CFRelease(interfacePrivate
->entity_device
);
2260 interfacePrivate
->entity_device
= CFRetain(base
);
2261 interfacePrivate
->entity_device_unique
= CFStringCreateCopy(NULL
, uniqueID
);
2266 // if not part of the NetworkConfigurationOverrides/DeviceModemOverrides, look
2267 // a bit harder for the modem CCL
2268 if (modemCCL
== NULL
) {
2269 val
= IORegistryEntrySearchCFProperty(interface
,
2273 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
2275 modemCCL
= IOCopyCFStringValue(val
);
2276 if (modemCCL
!= NULL
) {
2277 set_connection_script(interfacePrivate
, modemCCL
);
2278 CFRelease(modemCCL
);
2286 if (CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeIrDA
)) {
2287 interfacePrivate
->localized_key
= CFSTR("irda");
2288 } else if (CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeBluetooth
)) {
2289 interfacePrivate
->localized_key
= CFSTR("bluetooth");
2291 CFStringRef localized
= NULL
;
2292 CFStringRef name
= NULL
;
2293 CFMutableStringRef port
;
2295 port
= CFStringCreateMutableCopy(NULL
, 0, base
);
2296 CFStringLowercase(port
, NULL
);
2299 CFStringAppend(port
, CFSTR("-port"));
2302 // set non-localized name
2303 if (bundle
!= NULL
) {
2304 name
= copy_interface_string(bundle
, port
, FALSE
);
2307 if (!CFEqual(port
, name
)) {
2308 // if [English] localization available
2309 interfacePrivate
->name
= name
;
2311 // if no [English] localization available, use TTY base name
2313 interfacePrivate
->name
= CFStringCreateCopy(NULL
, base
);
2316 interfacePrivate
->name
= CFStringCreateCopy(NULL
, base
);
2319 // set localized name
2320 if (bundle
!= NULL
) {
2321 localized
= copy_interface_string(bundle
, port
, TRUE
);
2323 if (localized
!= NULL
) {
2324 if (!CFEqual(port
, localized
)) {
2325 // if localization available
2326 interfacePrivate
->localized_name
= localized
;
2328 // if no localization available, use TTY base name
2329 CFRelease(localized
);
2330 interfacePrivate
->localized_name
= CFStringCreateCopy(NULL
, base
);
2333 interfacePrivate
->localized_name
= CFStringCreateCopy(NULL
, base
);
2336 if (!isModem
|| !CFEqual(base
, CFSTR("modem"))) {
2337 // get USB info (if available)
2338 processUSBInterface(interfacePrivate
,
2346 // set interface "name"
2347 if (update_interface_name(interfacePrivate
, interface
, TRUE
)) {
2348 // if "ModemCCL" not provided, also check if the product/interface
2349 // name matches a CCL script
2350 if ((modemCCL
== NULL
) &&
2351 is_valid_connection_script(interfacePrivate
->name
)) {
2352 set_connection_script(interfacePrivate
, interfacePrivate
->name
);
2364 if (!ok
&& (interfacePrivate
->entity_device
!= NULL
)) {
2365 CFRelease(interfacePrivate
->entity_device
);
2366 interfacePrivate
->entity_device
= NULL
;
2368 if (base
!= NULL
) CFRelease(base
);
2374 static SCNetworkInterfaceRef
2375 createInterface(io_registry_entry_t interface
, processInterface func
)
2377 io_registry_entry_t bus
= MACH_PORT_NULL
;
2378 CFMutableDictionaryRef bus_dict
= NULL
;
2379 io_registry_entry_t controller
= MACH_PORT_NULL
;
2380 CFMutableDictionaryRef controller_dict
= NULL
;
2381 SCNetworkInterfacePrivateRef interfacePrivate
= NULL
;
2382 CFMutableDictionaryRef interface_dict
= NULL
;
2386 uint64_t entryID
= 0;
2388 kr
= IORegistryEntryGetPath(interface
, kIOServicePlane
, path
);
2389 if (kr
!= kIOReturnSuccess
) {
2390 SCLog(TRUE
, LOG_DEBUG
, CFSTR("createInterface IORegistryEntryGetPath() failed, kr = 0x%x"), kr
);
2394 kr
= IORegistryEntryCreateCFProperties(interface
, &interface_dict
, NULL
, kNilOptions
);
2395 if (kr
!= kIOReturnSuccess
) {
2396 SCLog(TRUE
, LOG_DEBUG
, CFSTR("createInterface IORegistryEntryCreateCFProperties() failed, kr = 0x%x"), kr
);
2400 /* get the controller node */
2401 kr
= IORegistryEntryGetParentEntry(interface
, kIOServicePlane
, &controller
);
2402 if (kr
!= KERN_SUCCESS
) {
2403 SCLog(TRUE
, LOG_DEBUG
, CFSTR("createInterface IORegistryEntryGetParentEntry() failed, kr = 0x%x"), kr
);
2407 /* get the dictionary associated with the node */
2408 kr
= IORegistryEntryCreateCFProperties(controller
, &controller_dict
, NULL
, kNilOptions
);
2409 if (kr
!= KERN_SUCCESS
) {
2410 SCLog(TRUE
, LOG_DEBUG
, CFSTR("createInterface IORegistryEntryCreateCFProperties() failed, kr = 0x%x"), kr
);
2414 /* get the bus node */
2415 kr
= IORegistryEntryGetParentEntry(controller
, kIOServicePlane
, &bus
);
2416 if (kr
!= KERN_SUCCESS
) {
2417 SCLog(TRUE
, LOG_DEBUG
, CFSTR("createInterface IORegistryEntryGetParentEntry() failed, kr = 0x%x"), kr
);
2421 /* get the dictionary associated with the node */
2422 kr
= IORegistryEntryCreateCFProperties(bus
, &bus_dict
, NULL
, kNilOptions
);
2423 if (kr
!= KERN_SUCCESS
) {
2424 SCLog(TRUE
, LOG_DEBUG
, CFSTR("createInterface IORegistryEntryCreateCFProperties() failed, kr = 0x%x"), kr
);
2428 /* get the registry entry ID */
2429 kr
= IORegistryEntryGetRegistryEntryID(interface
, &entryID
);
2430 if (kr
!= KERN_SUCCESS
) {
2431 SCLog(TRUE
, LOG_DEBUG
, CFSTR("createInterface IORegistryEntryGetRegistryEntryID() failed, kr = 0x%x"), kr
);
2435 interfacePrivate
= __SCNetworkInterfaceCreatePrivate(NULL
, NULL
, NULL
, NULL
);
2436 interfacePrivate
->path
= (path
!= NULL
) ? CFStringCreateWithCString(NULL
, path
, kCFStringEncodingUTF8
) : NULL
;
2437 interfacePrivate
->entryID
= entryID
;
2439 // configuration [PPP, Modem, DNS, IPv4, IPv6, Proxies, SMB] template overrides
2440 val
= IORegistryEntrySearchCFProperty(interface
,
2442 kSCNetworkInterfaceNetworkConfigurationOverridesKey
,
2444 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
2446 if (isA_CFDictionary(val
)) {
2447 interfacePrivate
->overrides
= CFDictionaryCreateMutableCopy(NULL
, 0, val
);
2452 if ((*func
)(interfacePrivate
, interface
, interface_dict
, controller
, controller_dict
, bus
, bus_dict
)) {
2453 /* get user-notification / auto-configuration preference */
2454 val
= IORegistryEntrySearchCFProperty(interface
,
2456 kSCNetworkInterfaceConfigurationActionKey
,
2458 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
2460 if (isA_CFString(val
)) {
2461 interfacePrivate
->configurationAction
= CFRetain(val
);
2466 /* get HiddenConfiguration preference */
2467 val
= IORegistryEntrySearchCFProperty(interface
,
2469 kSCNetworkInterfaceHiddenConfigurationKey
,
2471 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
2473 interfacePrivate
->hidden
= TRUE
;
2477 CFRelease(interfacePrivate
);
2478 interfacePrivate
= NULL
;
2483 if (interface_dict
!= NULL
) CFRelease(interface_dict
);
2485 if (controller
!= MACH_PORT_NULL
) IOObjectRelease(controller
);
2486 if (controller_dict
!= NULL
) CFRelease(controller_dict
);
2488 if (bus
!= MACH_PORT_NULL
) IOObjectRelease(bus
);
2489 if (bus_dict
!= NULL
) CFRelease(bus_dict
);
2491 return (SCNetworkInterfaceRef
)interfacePrivate
;
2495 static CF_RETURNS_RETAINED CFArrayRef
2496 findMatchingInterfaces(CFDictionaryRef matching
, processInterface func
)
2498 CFMutableArrayRef interfaces
;
2499 io_registry_entry_t interface
;
2501 io_iterator_t iterator
= MACH_PORT_NULL
;
2504 * A reference to the "matching" dictionary will be consumed by the
2505 * the call to IOServiceGetMatchingServices so we bump up the retain
2510 kr
= IOServiceGetMatchingServices(masterPort
, matching
, &iterator
);
2511 if (kr
!= kIOReturnSuccess
) {
2512 SCLog(TRUE
, LOG_DEBUG
, CFSTR("findMatchingInterfaces IOServiceGetMatchingServices() failed, kr = 0x%x"), kr
);
2516 interfaces
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2518 while ((interface
= IOIteratorNext(iterator
)) != MACH_PORT_NULL
) {
2519 SCNetworkInterfaceRef match
;
2521 match
= createInterface(interface
, func
);
2522 if (match
!= NULL
) {
2523 CFArrayAppendValue(interfaces
, match
);
2527 IOObjectRelease(interface
);
2530 IOObjectRelease(iterator
);
2537 #pragma mark helper functions
2541 findConfiguration(CFStringRef interface_type
)
2545 for (i
= 0; i
< sizeof(configurations
)/sizeof(configurations
[0]); i
++) {
2546 if (CFEqual(interface_type
, *configurations
[i
].interface_type
)) {
2557 __SCNetworkInterfaceGetDefaultConfigurationType(SCNetworkInterfaceRef interface
)
2559 CFIndex interfaceIndex
;
2560 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
2562 if (interfacePrivate
->serviceID
== NULL
) {
2563 // if not associated with a service (yet)
2564 _SCErrorSet(kSCStatusInvalidArgument
);
2568 interfaceIndex
= findConfiguration(interfacePrivate
->interface_type
);
2569 if (interfaceIndex
== kCFNotFound
) {
2570 // unknown interface type, use per-service configuration preferences
2571 return interfacePrivate
->interface_type
; // entity
2574 if (configurations
[interfaceIndex
].entity_hardware
!= NULL
) {
2575 // if configuration information can be associated with this interface type
2576 return *configurations
[interfaceIndex
].entity_hardware
;
2579 _SCErrorSet(kSCStatusInvalidArgument
);
2586 __SCNetworkInterfaceIsValidExtendedConfigurationType(SCNetworkInterfaceRef interface
,
2587 CFStringRef extendedType
,
2588 Boolean requirePerInterface
)
2590 CFStringRef defaultType
;
2591 CFIndex extendedIndex
;
2592 CFIndex interfaceIndex
;
2593 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
2594 Boolean isL2TP
= FALSE
;
2597 defaultType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
2598 if (defaultType
== NULL
) {
2602 if (CFEqual(extendedType
, defaultType
)) {
2603 // extended and default configuration types cannot conflict
2607 interfaceIndex
= findConfiguration(interfacePrivate
->interface_type
);
2608 if (interfaceIndex
== kCFNotFound
) {
2609 // configuration information for unknown interface type's
2610 // are stored along with the service and we don't allow
2611 // per-service extended configurations
2615 if (CFEqual(extendedType
, kSCEntNetIPSec
)) {
2616 CFStringRef interfaceType
;
2618 interfaceType
= SCNetworkInterfaceGetInterfaceType(interface
);
2619 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypePPP
)) {
2620 SCNetworkInterfaceRef child
;
2622 child
= SCNetworkInterfaceGetInterface(interface
);
2623 if (child
!= NULL
) {
2624 interfaceType
= SCNetworkInterfaceGetInterfaceType(child
);
2625 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeL2TP
)) {
2632 if (requirePerInterface
&&
2633 !configurations
[interfaceIndex
].per_interface_config
&&
2635 // we don't allow per-service extended configurations (except
2636 // that we do allow IPSec as an extended type for PPP->L2TP)
2640 extendedIndex
= findConfiguration(extendedType
);
2641 if ((extendedIndex
!= kCFNotFound
) && !isL2TP
) {
2642 // extended type cannot match a known interface type (except
2643 // that we do allow IPSec as an extended type for PPP->L2TP)
2649 * Do we match specific/known extended configuration types (e.g. EAPOL)
2650 * and ensure that any non-standard extended configuration types be of
2651 * the form com.myCompany.myType?
2660 _SCErrorSet(kSCStatusInvalidArgument
);
2667 CFStringRef defaultType
;
2668 CFMutableArrayRef types
;
2669 } extendedConfiguration
, *extendedConfigurationRef
;
2673 __addExtendedConfigurationType(const void *key
, const void *value
, void *context
)
2675 CFStringRef extendedType
= (CFStringRef
)key
;
2676 extendedConfigurationRef myContextRef
= (extendedConfigurationRef
)context
;
2678 if (CFEqual(extendedType
, myContextRef
->defaultType
)) {
2679 // do not include the default configuration type
2683 if (CFArrayContainsValue(myContextRef
->types
,
2684 CFRangeMake(0, CFArrayGetCount(myContextRef
->types
)),
2686 // if extendedType already has already been added
2690 CFArrayAppendValue(myContextRef
->types
, extendedType
);
2696 static CF_RETURNS_RETAINED CFArrayRef
2697 extendedConfigurationTypes(SCNetworkInterfaceRef interface
)
2700 CFIndex interfaceIndex
;
2701 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
2702 extendedConfiguration myContext
;
2703 SCNetworkServiceRef service
;
2707 myContext
.defaultType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
2708 if (myContext
.defaultType
== NULL
) {
2709 myContext
.types
= NULL
;
2713 myContext
.types
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2715 if (interfacePrivate
->serviceID
== NULL
) {
2716 // if not associated with a service (yet)
2720 interfaceIndex
= findConfiguration(interfacePrivate
->interface_type
);
2721 if (interfaceIndex
== kCFNotFound
) {
2722 // we don't allow per-service extended configurations
2726 if (!configurations
[interfaceIndex
].per_interface_config
) {
2727 // known interface type but we still don't allow
2728 // per-service extended configurations
2732 service
= (SCNetworkServiceRef
)__SCNetworkServiceCreatePrivate(NULL
,
2733 interfacePrivate
->prefs
,
2734 interfacePrivate
->serviceID
,
2737 sets
= SCNetworkSetCopyAll(interfacePrivate
->prefs
);
2738 n
= (sets
!= NULL
) ? CFArrayGetCount(sets
) : 0;
2740 for (i
= 0; i
< n
; i
++) {
2741 CFDictionaryRef configs
;
2744 CFArrayRef services
;
2745 SCNetworkSetRef set
;
2747 set
= CFArrayGetValueAtIndex(sets
, i
);
2748 services
= SCNetworkSetCopyServices(set
);
2749 found
= CFArrayContainsValue(services
,
2750 CFRangeMake(0, CFArrayGetCount(services
)),
2752 CFRelease(services
);
2758 // add stored extended configuration types
2759 path
= SCPreferencesPathKeyCreateSetNetworkInterfaceEntity(NULL
, // allocator
2760 SCNetworkSetGetSetID(set
), // set
2761 interfacePrivate
->entity_device
, // service
2763 configs
= __getPrefsConfiguration(interfacePrivate
->prefs
, path
);
2765 if (isA_CFDictionary(configs
)) {
2766 CFDictionaryApplyFunction(configs
,
2767 __addExtendedConfigurationType
,
2771 // add not-yet-stored extended configuration types
2772 if (interfacePrivate
->unsaved
!= NULL
) {
2773 CFDictionaryApplyFunction(interfacePrivate
->unsaved
,
2774 __addExtendedConfigurationType
,
2782 if (sets
!= NULL
) CFRelease(sets
);
2786 return myContext
.types
;
2791 copyConfigurationPaths(SCNetworkInterfacePrivateRef interfacePrivate
,
2792 CFStringRef extendedType
)
2794 CFMutableArrayRef array
;
2796 CFIndex interfaceIndex
;
2799 SCNetworkServiceRef service
;
2802 array
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2804 interfaceIndex
= findConfiguration(interfacePrivate
->interface_type
);
2805 if (interfaceIndex
== kCFNotFound
) {
2806 // unknown interface type, use per-service configuration preferences
2807 path
= SCPreferencesPathKeyCreateNetworkServiceEntity(NULL
, // allocator
2808 interfacePrivate
->serviceID
, // service
2809 extendedType
); // entity
2810 CFArrayAppendValue(array
, path
);
2815 if (!configurations
[interfaceIndex
].per_interface_config
) {
2816 // known interface type, per-service configuration preferences
2817 path
= SCPreferencesPathKeyCreateNetworkServiceEntity(NULL
, // allocator
2818 interfacePrivate
->serviceID
, // service
2819 extendedType
); // entity
2820 CFArrayAppendValue(array
, path
);
2825 // known interface type, per-interface configuration preferences
2827 // 1. look for all sets which contain the associated service
2828 // 2. add a per-set path for the interface configuration for
2831 service
= (SCNetworkServiceRef
)__SCNetworkServiceCreatePrivate(NULL
,
2832 interfacePrivate
->prefs
,
2833 interfacePrivate
->serviceID
,
2834 (SCNetworkInterfaceRef
)interfacePrivate
);
2836 sets
= SCNetworkSetCopyAll(interfacePrivate
->prefs
);
2837 n
= (sets
!= NULL
) ? CFArrayGetCount(sets
) : 0;
2839 for (i
= 0; i
< n
; i
++) {
2840 CFArrayRef services
;
2841 SCNetworkSetRef set
;
2843 set
= CFArrayGetValueAtIndex(sets
, i
);
2844 services
= SCNetworkSetCopyServices(set
);
2845 if (CFArrayContainsValue(services
,
2846 CFRangeMake(0, CFArrayGetCount(services
)),
2848 path
= SCPreferencesPathKeyCreateSetNetworkInterfaceEntity(NULL
, // allocator
2849 SCNetworkSetGetSetID(set
), // set
2850 interfacePrivate
->entity_device
, // service
2851 extendedType
); // entity
2852 CFArrayAppendValue(array
, path
);
2855 CFRelease(services
);
2858 if (CFArrayGetCount(array
) == 0) {
2864 if (sets
!= NULL
) CFRelease(sets
);
2870 #pragma mark SCNetworkInterface <--> preferences entity
2875 __SCNetworkInterfaceCopyInterfaceEntity(SCNetworkInterfaceRef interface
)
2877 CFMutableDictionaryRef entity
;
2878 CFIndex interfaceIndex
;
2879 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
2881 entity
= CFDictionaryCreateMutable(NULL
,
2883 &kCFTypeDictionaryKeyCallBacks
,
2884 &kCFTypeDictionaryValueCallBacks
);
2885 if (interfacePrivate
->entity_type
!= NULL
) {
2886 CFDictionarySetValue(entity
,
2887 kSCPropNetInterfaceType
,
2888 interfacePrivate
->entity_type
);
2890 if (interfacePrivate
->entity_subtype
!= NULL
) {
2891 CFDictionarySetValue(entity
,
2892 kSCPropNetInterfaceSubType
,
2893 interfacePrivate
->entity_subtype
);
2895 if (interfacePrivate
->entity_device
!= NULL
) {
2896 CFDictionarySetValue(entity
,
2897 kSCPropNetInterfaceDeviceName
,
2898 interfacePrivate
->entity_device
);
2900 if (interfacePrivate
->entity_device_unique
!= NULL
) {
2901 CFDictionarySetValue(entity
,
2902 CFSTR("DeviceUniqueIdentifier"),
2903 interfacePrivate
->entity_device_unique
);
2905 if (interfacePrivate
->hidden
) {
2906 CFDictionarySetValue(entity
,
2907 kSCNetworkInterfaceHiddenConfigurationKey
,
2911 // match the "hardware" with the lowest layer
2913 SCNetworkInterfaceRef nextInterface
;
2915 nextInterface
= SCNetworkInterfaceGetInterface(interface
);
2916 if (nextInterface
== NULL
) {
2920 interface
= nextInterface
;
2922 interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
2924 if (CFEqual(interface
, kSCNetworkInterfaceIPv4
)) {
2928 interfaceIndex
= findConfiguration(interfacePrivate
->interface_type
);
2929 if (interfaceIndex
!= kCFNotFound
) {
2930 if (configurations
[interfaceIndex
].entity_hardware
!= NULL
) {
2931 CFDictionarySetValue(entity
,
2932 kSCPropNetInterfaceHardware
,
2933 *configurations
[interfaceIndex
].entity_hardware
);
2936 CFDictionarySetValue(entity
,
2937 kSCPropNetInterfaceHardware
,
2938 interfacePrivate
->interface_type
);
2941 // add the localized display name (which will only be used when/if the
2942 // interface is removed from the system)
2943 CFDictionarySetValue(entity
,
2944 kSCPropUserDefinedName
,
2945 SCNetworkInterfaceGetLocalizedDisplayName(interface
));
2947 // note that this is a V.92 capable modem
2948 if (CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeModem
) &&
2949 interfacePrivate
->modemIsV92
) {
2953 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &one
);
2954 CFDictionarySetValue(entity
,
2955 kSCPropNetInterfaceSupportsModemOnHold
,
2964 static SCNetworkInterfaceRef
2965 findInterface(CFArrayRef interfaces
, CFStringRef match_if
)
2970 n
= CFArrayGetCount(interfaces
);
2971 for (i
= 0; i
< n
; i
++) {
2972 SCNetworkInterfaceRef interface
= CFArrayGetValueAtIndex(interfaces
, i
);
2973 CFStringRef interfaceName
;
2975 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
2976 if ((interfaceName
!= NULL
) && CFEqual(interfaceName
, match_if
)) {
2977 CFRetain(interface
);
2985 #if !TARGET_OS_IPHONE
2986 static SCNetworkInterfaceRef
2987 findBondInterface(SCPreferencesRef prefs
, CFStringRef ifDevice
)
2990 SCNetworkInterfaceRef interface
= NULL
;
2992 if (prefs
== NULL
) {
2996 // check if the interface is an Ethernet Bond
2997 bonds
= SCBondInterfaceCopyAll(prefs
);
2998 if (bonds
!= NULL
) {
2999 interface
= findInterface(bonds
, ifDevice
);
3004 #endif // !TARGET_OS_IPHONE
3006 static SCNetworkInterfaceRef
3007 findBridgeInterface(SCPreferencesRef prefs
, CFStringRef ifDevice
)
3010 SCNetworkInterfaceRef interface
= NULL
;
3012 if (prefs
== NULL
) {
3016 // check if the interface is an bridge
3017 bridges
= SCBridgeInterfaceCopyAll(prefs
);
3018 if (bridges
!= NULL
) {
3019 interface
= findInterface(bridges
, ifDevice
);
3025 static SCNetworkInterfaceRef
3026 findVLANInterface(SCPreferencesRef prefs
, CFStringRef ifDevice
)
3028 SCNetworkInterfaceRef interface
= NULL
;
3031 if (prefs
== NULL
) {
3035 // check if the interface is a VLAN
3036 vlans
= SCVLANInterfaceCopyAll(prefs
);
3037 if (vlans
!= NULL
) {
3038 interface
= findInterface(vlans
, ifDevice
);
3045 SCNetworkInterfaceRef
3046 _SCNetworkInterfaceCreateWithBSDName(CFAllocatorRef allocator
,
3047 CFStringRef bsdName
,
3050 CFMutableDictionaryRef entity
;
3051 SCNetworkInterfaceRef interface
;
3053 entity
= CFDictionaryCreateMutable(NULL
,
3055 &kCFTypeDictionaryKeyCallBacks
,
3056 &kCFTypeDictionaryValueCallBacks
);
3057 CFDictionarySetValue(entity
, kSCPropNetInterfaceDeviceName
, bsdName
);
3059 #if !TARGET_OS_IPHONE
3060 if ((flags
& kIncludeBondInterfaces
) == 0) {
3061 CFDictionarySetValue(entity
, CFSTR("_NO_BOND_INTERFACES_"), kCFBooleanTrue
);
3063 #endif // !TARGET_OS_IPHONE
3065 if ((flags
& kIncludeBridgeInterfaces
) == 0) {
3066 CFDictionarySetValue(entity
, CFSTR("_NO_BRIDGE_INTERFACES_"), kCFBooleanTrue
);
3069 if ((flags
& kIncludeVLANInterfaces
) == 0) {
3070 CFDictionarySetValue(entity
, CFSTR("_NO_VLAN_INTERFACES_"), kCFBooleanTrue
);
3073 interface
= _SCNetworkInterfaceCreateWithEntity(NULL
, entity
, NULL
);
3081 __SCNetworkInterfaceSetService(SCNetworkInterfaceRef interface
,
3082 SCNetworkServiceRef service
)
3084 SCNetworkInterfacePrivateRef interfacePrivate
;
3085 SCNetworkServicePrivateRef servicePrivate
;
3087 interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
3088 if (interfacePrivate
->prefs
!= NULL
) {
3089 CFRelease(interfacePrivate
->prefs
);
3090 interfacePrivate
->prefs
= NULL
;
3092 if (interfacePrivate
->serviceID
!= NULL
) {
3093 CFRelease(interfacePrivate
->serviceID
);
3094 interfacePrivate
->serviceID
= NULL
;
3097 servicePrivate
= (SCNetworkServicePrivateRef
)service
;
3098 if (servicePrivate
->prefs
!= NULL
) {
3099 interfacePrivate
->prefs
= CFRetain(servicePrivate
->prefs
);
3101 if (servicePrivate
->serviceID
!= NULL
) {
3102 interfacePrivate
->serviceID
= CFRetain(servicePrivate
->serviceID
);
3110 _SCNetworkInterfaceMatchesName(CFStringRef name
, CFStringRef key
)
3115 if (bundle
== NULL
) {
3120 if (!isA_CFString(name
)) {
3121 // if no interface "name"
3125 // check non-localized name for a match
3126 str
= copy_interface_string(bundle
, key
, FALSE
);
3128 match
= CFEqual(name
, str
);
3135 // check localized name for a match
3136 str
= copy_interface_string(bundle
, key
, TRUE
);
3138 match
= CFEqual(name
, str
);
3149 SCNetworkInterfaceRef
3150 _SCNetworkInterfaceCreateWithEntity(CFAllocatorRef allocator
,
3151 CFDictionaryRef interface_entity
,
3152 SCNetworkServiceRef service
)
3154 SCNetworkInterfacePrivateRef interfacePrivate
= NULL
;
3155 CFStringRef ifDevice
;
3156 CFStringRef ifName
= NULL
;
3157 CFStringRef ifSubType
;
3159 CFStringRef ifUnique
;
3160 CFArrayRef matching_interfaces
= NULL
;
3162 /* initialize runtime (and kSCNetworkInterfaceIPv4) */
3163 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
3165 ifType
= CFDictionaryGetValue(interface_entity
, kSCPropNetInterfaceType
);
3166 if (ifType
== NULL
) {
3168 * The interface "Type" was not specified. We'll make an
3169 * assumption that this is an "Ethernet" interface. If a
3170 * real interface exists with the provided interface name
3171 * then the actual type will be set accordingly. If not, we'll
3172 * end up crafting an "Ethernet" SCNetworkInterface which
3173 * will keep the rest of the configuration APIs happy.
3175 ifType
= kSCValNetInterfaceTypeEthernet
;
3178 if (!isA_CFString(ifType
)) {
3182 ifSubType
= CFDictionaryGetValue(interface_entity
, kSCPropNetInterfaceSubType
);
3183 if (CFEqual(ifType
, kSCValNetInterfaceTypePPP
) ||
3184 CFEqual(ifType
, kSCValNetInterfaceTypeVPN
)) {
3185 if (!isA_CFString(ifSubType
)) {
3190 ifDevice
= CFDictionaryGetValue(interface_entity
, kSCPropNetInterfaceDeviceName
);
3191 ifUnique
= CFDictionaryGetValue(interface_entity
, CFSTR("DeviceUniqueIdentifier"));
3193 if (CFEqual(ifType
, kSCValNetInterfaceTypeEthernet
) ||
3194 CFEqual(ifType
, kSCValNetInterfaceTypeFireWire
) ||
3195 (CFEqual(ifType
, kSCValNetInterfaceTypePPP
) && CFEqual(ifSubType
, kSCValNetInterfaceSubTypePPPoE
))) {
3196 char bsdName
[IFNAMSIZ
];
3197 CFMutableDictionaryRef matching
;
3199 if (!isA_CFString(ifDevice
)) {
3203 if (CFEqual(ifDevice
, CFSTR("lo0"))) { // for _SCNetworkInterfaceCreateWithBSDName
3204 interfacePrivate
= __SCNetworkInterfaceCreateCopy(NULL
, kSCNetworkInterfaceLoopback
, NULL
, NULL
);
3208 if (_SC_cfstring_to_cstring(ifDevice
, bsdName
, sizeof(bsdName
), kCFStringEncodingASCII
) == NULL
) {
3212 matching
= IOBSDNameMatching(masterPort
, 0, bsdName
);
3213 if (matching
== NULL
) {
3216 matching_interfaces
= findMatchingInterfaces(matching
, processNetworkInterface
);
3217 CFRelease(matching
);
3218 } else if (CFEqual(ifType
, kSCValNetInterfaceTypePPP
)) {
3219 if (CFEqual(ifSubType
, kSCValNetInterfaceSubTypePPPSerial
)) {
3220 CFDictionaryRef matching
;
3221 CFStringRef match_keys
[2];
3222 CFStringRef match_vals
[2];
3224 if (!isA_CFString(ifDevice
)) {
3228 match_keys
[0] = CFSTR(kIOProviderClassKey
);
3229 match_vals
[0] = CFSTR(kIOSerialBSDServiceValue
);
3231 match_keys
[1] = CFSTR(kIOTTYBaseNameKey
);
3232 match_vals
[1] = ifDevice
;
3234 matching
= CFDictionaryCreate(NULL
,
3235 (const void **)match_keys
,
3236 (const void **)match_vals
,
3237 sizeof(match_keys
)/sizeof(match_keys
[0]),
3238 &kCFTypeDictionaryKeyCallBacks
,
3239 &kCFTypeDictionaryValueCallBacks
);
3240 matching_interfaces
= findMatchingInterfaces(matching
, processSerialInterface
);
3241 CFRelease(matching
);
3243 if (ifUnique
== NULL
) {
3245 Boolean useDeviceName
= TRUE
;
3247 n
= (matching_interfaces
!= NULL
) ? CFArrayGetCount(matching_interfaces
) : 0;
3251 for (i
= 0; i
< n
; i
++) {
3252 SCNetworkInterfacePrivateRef scanPrivate
;
3254 scanPrivate
= (SCNetworkInterfacePrivateRef
)CFArrayGetValueAtIndex(matching_interfaces
, i
);
3255 if (scanPrivate
->entity_device_unique
!= NULL
) {
3256 useDeviceName
= FALSE
;
3262 if (useDeviceName
) {
3263 if (matching_interfaces
!= NULL
) {
3264 CFRelease(matching_interfaces
);
3267 match_keys
[1] = CFSTR(kIOTTYDeviceKey
);
3268 matching
= CFDictionaryCreate(NULL
,
3269 (const void **)match_keys
,
3270 (const void **)match_vals
,
3271 sizeof(match_keys
)/sizeof(match_keys
[0]),
3272 &kCFTypeDictionaryKeyCallBacks
,
3273 &kCFTypeDictionaryValueCallBacks
);
3274 matching_interfaces
= findMatchingInterfaces(matching
, processSerialInterface
);
3275 CFRelease(matching
);
3278 } else if (CFEqual(ifSubType
, kSCValNetInterfaceSubTypeL2TP
)) {
3279 interfacePrivate
= (SCNetworkInterfacePrivateRef
)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
,
3280 kSCNetworkInterfaceTypeL2TP
);
3281 } else if (CFEqual(ifSubType
, kSCValNetInterfaceSubTypePPTP
)) {
3282 interfacePrivate
= (SCNetworkInterfacePrivateRef
)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
,
3283 kSCNetworkInterfaceTypePPTP
);
3285 // XXX do we allow non-Apple variants of PPP??? XXX
3286 interfacePrivate
= (SCNetworkInterfacePrivateRef
)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
,
3289 } else if (CFEqual(ifType
, kSCValNetInterfaceType6to4
)) {
3290 if (!isA_CFString(ifDevice
)) {
3294 interfacePrivate
= (SCNetworkInterfacePrivateRef
)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
,
3295 kSCNetworkInterfaceType6to4
);
3296 } else if (CFEqual(ifType
, kSCValNetInterfaceTypeIPSec
)) {
3297 interfacePrivate
= (SCNetworkInterfacePrivateRef
)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
,
3298 kSCNetworkInterfaceTypeIPSec
);
3299 } else if (CFEqual(ifType
, kSCValNetInterfaceTypeLoopback
)) {
3300 interfacePrivate
= __SCNetworkInterfaceCreateCopy(NULL
, kSCNetworkInterfaceLoopback
, NULL
, NULL
);
3301 } else if (CFEqual(ifType
, kSCValNetInterfaceTypeVPN
)) {
3302 if (CFStringFind(ifSubType
, CFSTR("."), 0).location
!= kCFNotFound
) {
3303 interfacePrivate
= (SCNetworkInterfacePrivateRef
)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
,
3306 } else if ((CFStringFind(ifType
, CFSTR("."), 0).location
!= kCFNotFound
) && (ifDevice
== NULL
)) {
3307 interfacePrivate
= (SCNetworkInterfacePrivateRef
)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
,
3311 if (matching_interfaces
!= NULL
) {
3313 SCPreferencesRef prefs
;
3315 n
= CFArrayGetCount(matching_interfaces
);
3318 interfacePrivate
= (SCNetworkInterfacePrivateRef
)CFArrayGetValueAtIndex(matching_interfaces
, 0);
3319 if (_SC_CFEqual(ifUnique
, interfacePrivate
->entity_device_unique
)) {
3320 // if the unique ID's match
3321 CFRetain(interfacePrivate
);
3325 interfacePrivate
= NULL
;
3328 if (!CFEqual(ifType
, kSCValNetInterfaceTypeEthernet
)) {
3331 prefs
= SCPreferencesCreate(NULL
, CFSTR("SCNetworkInterface"), NULL
);
3332 if (prefs
== NULL
) {
3335 #if !TARGET_OS_IPHONE
3336 if (!CFDictionaryContainsKey(interface_entity
, CFSTR("_NO_BOND_INTERFACES_"))) {
3337 interfacePrivate
= (SCNetworkInterfacePrivateRef
)findBondInterface(prefs
, ifDevice
);
3339 #endif // !TARGET_OS_IPHONE
3340 if ((interfacePrivate
== NULL
)
3341 && !CFDictionaryContainsKey(interface_entity
, CFSTR("_NO_BRIDGE_INTERFACES_"))) {
3342 interfacePrivate
= (SCNetworkInterfacePrivateRef
)findBridgeInterface(prefs
, ifDevice
);
3345 if ((interfacePrivate
== NULL
)
3346 && !CFDictionaryContainsKey(interface_entity
, CFSTR("_NO_VLAN_INTERFACES_"))) {
3347 interfacePrivate
= (SCNetworkInterfacePrivateRef
)findVLANInterface(prefs
, ifDevice
);
3352 if (ifUnique
!= NULL
) {
3355 // we are looking for an interface with a unique ID
3356 // so let's try to focus our choices
3357 for (i
= 0; i
< n
; i
++) {
3358 SCNetworkInterfacePrivateRef scanPrivate
;
3360 scanPrivate
= (SCNetworkInterfacePrivateRef
)CFArrayGetValueAtIndex(matching_interfaces
, i
);
3361 if (_SC_CFEqual(ifUnique
, scanPrivate
->entity_device_unique
)) {
3362 if (interfacePrivate
!= NULL
) {
3363 // if we've matched more than one interface
3364 interfacePrivate
= NULL
;
3367 interfacePrivate
= scanPrivate
;
3370 } else if (CFDictionaryGetValueIfPresent(interface_entity
,
3371 kSCPropUserDefinedName
,
3372 (const void **)&ifName
)) {
3375 // we don't have a unique ID but do have an interface
3376 // name. If the matching interfaces do have IDs than
3377 // we can try to focus our choices using the name
3378 for (i
= 0; i
< n
; i
++) {
3379 SCNetworkInterfacePrivateRef scanPrivate
;
3381 scanPrivate
= (SCNetworkInterfacePrivateRef
)CFArrayGetValueAtIndex(matching_interfaces
, i
);
3382 if (scanPrivate
->entity_device_unique
!= NULL
) {
3383 SCNetworkInterfaceRef scan
= (SCNetworkInterfaceRef
)scanPrivate
;
3384 CFStringRef scanName
;
3386 scanName
= __SCNetworkInterfaceGetNonLocalizedDisplayName(scan
);
3387 if ((scanName
!= NULL
) && !_SC_CFEqual(ifName
, scanName
)) {
3388 continue; // if not the same display name
3392 if (interfacePrivate
!= NULL
) {
3393 // if we've matched more than one interface
3394 interfacePrivate
= NULL
;
3397 interfacePrivate
= scanPrivate
;
3400 if (interfacePrivate
== NULL
) {
3401 SCLog(TRUE
, LOG_ERR
, CFSTR("_SCNetworkInterfaceCreateWithEntity() failed, more than one interface matches %@"), ifDevice
);
3402 interfacePrivate
= (SCNetworkInterfacePrivateRef
)CFArrayGetValueAtIndex(matching_interfaces
, 0);
3404 CFRetain(interfacePrivate
);
3407 CFRelease(matching_interfaces
);
3412 if (interfacePrivate
== NULL
) {
3414 * if device not present on this system
3416 interfacePrivate
= __SCNetworkInterfaceCreatePrivate(NULL
, NULL
, NULL
, NULL
);
3417 interfacePrivate
->entity_type
= ifType
;
3418 interfacePrivate
->entity_subtype
= ifSubType
;
3419 interfacePrivate
->entity_device
= (ifDevice
!= NULL
) ? CFStringCreateCopy(NULL
, ifDevice
) : NULL
;
3420 interfacePrivate
->entity_device_unique
= (ifUnique
!= NULL
) ? CFStringCreateCopy(NULL
, ifUnique
) : NULL
;
3422 if (CFEqual(ifType
, kSCValNetInterfaceTypeEthernet
)) {
3423 CFStringRef entity_hardware
;
3425 entity_hardware
= CFDictionaryGetValue(interface_entity
, kSCPropNetInterfaceHardware
);
3426 if (isA_CFString((entity_hardware
)) &&
3427 CFEqual(entity_hardware
, kSCEntNetAirPort
)) {
3428 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeIEEE80211
;
3429 interfacePrivate
->localized_key
= CFSTR("airport");
3430 interfacePrivate
->sort_order
= kSortAirPort
;
3434 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
3436 name
= CFDictionaryGetValue(interface_entity
, kSCPropUserDefinedName
);
3437 if (_SCNetworkInterfaceMatchesName(name
, CFSTR("iPhone"))) {
3438 interfacePrivate
->localized_key
= CFSTR("iPhone");
3439 interfacePrivate
->sort_order
= kSortTethered
;
3440 } else if (_SCNetworkInterfaceMatchesName(name
, CFSTR("bluetooth-pan-gn"))) {
3441 interfacePrivate
->localized_key
= CFSTR("bluetooth-pan-gn");
3442 interfacePrivate
->sort_order
= kSortBluetoothPAN_GN
;
3443 } else if (_SCNetworkInterfaceMatchesName(name
, CFSTR("bluetooth-pan-nap"))) {
3444 interfacePrivate
->localized_key
= CFSTR("bluetooth-pan-nap");
3445 interfacePrivate
->sort_order
= kSortBluetoothPAN_NAP
;
3446 } else if (_SCNetworkInterfaceMatchesName(name
, CFSTR("bluetooth-pan-u"))) {
3447 interfacePrivate
->localized_key
= CFSTR("bluetooth-pan-u");
3448 interfacePrivate
->sort_order
= kSortBluetoothPAN_U
;
3450 interfacePrivate
->sort_order
= kSortEthernet
;
3453 } else if (CFEqual(ifType
, kSCValNetInterfaceTypeFireWire
)) {
3454 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeFireWire
;
3455 interfacePrivate
->sort_order
= kSortFireWire
;
3456 } else if (CFEqual(ifType
, kSCValNetInterfaceTypePPP
)) {
3457 if (CFEqual(ifSubType
, kSCValNetInterfaceSubTypePPPoE
)) {
3458 CFStringRef entity_hardware
;
3460 entity_hardware
= CFDictionaryGetValue(interface_entity
, kSCPropNetInterfaceHardware
);
3461 if (isA_CFString((entity_hardware
)) &&
3462 CFEqual(entity_hardware
, kSCEntNetAirPort
)) {
3463 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeIEEE80211
;
3464 interfacePrivate
->sort_order
= kSortAirPort
;
3466 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeEthernet
;
3467 interfacePrivate
->sort_order
= kSortEthernet
;
3469 } else if (CFEqual(ifSubType
, kSCValNetInterfaceSubTypePPPSerial
)) {
3470 if (CFStringHasPrefix(ifDevice
, CFSTR("Bluetooth"))) {
3471 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeBluetooth
;
3472 interfacePrivate
->sort_order
= kSortBluetooth
;
3473 } else if (CFStringHasPrefix(ifDevice
, CFSTR("irda"))) {
3474 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeIrDA
;
3475 interfacePrivate
->sort_order
= kSortIrDA
;
3476 } else if (CFStringHasPrefix(ifDevice
, CFSTR("wwan"))) {
3477 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeWWAN
;
3478 interfacePrivate
->sort_order
= kSortWWAN
;
3480 interfacePrivate
->interface_type
= kSCNetworkInterfaceTypeModem
;
3481 interfacePrivate
->sort_order
= kSortModem
;
3484 SCNetworkInterfaceRef child
;
3487 CFRelease(interfacePrivate
);
3488 child
= SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
, ifSubType
);
3489 interfacePrivate
= (SCNetworkInterfacePrivateRef
)child
;
3490 if (interfacePrivate
== NULL
) {
3494 } else if (CFEqual(ifType
, kSCValNetInterfaceTypeVPN
)) {
3495 SCNetworkInterfaceRef child
;
3497 CFRelease(interfacePrivate
);
3498 child
= SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4
, ifSubType
);
3499 interfacePrivate
= (SCNetworkInterfacePrivateRef
)child
;
3500 if (interfacePrivate
== NULL
) {
3503 } else if (CFStringFind(ifType
, CFSTR("."), 0).location
!= kCFNotFound
) {
3504 // if vendor interface
3505 if (vendor_interface_types
== NULL
) {
3506 vendor_interface_types
= CFSetCreateMutable(NULL
, 0, &kCFTypeSetCallBacks
);
3508 CFSetAddValue(vendor_interface_types
, ifType
);
3510 interfacePrivate
->interface_type
= CFSetGetValue(vendor_interface_types
, ifType
);
3512 // if unknown interface
3513 CFRelease(interfacePrivate
);
3514 interfacePrivate
= NULL
;
3518 if (CFDictionaryContainsKey(interface_entity
, kSCNetworkInterfaceHiddenConfigurationKey
)) {
3519 interfacePrivate
->hidden
= TRUE
;
3523 if (service
!= NULL
) {
3524 __SCNetworkInterfaceSetService((SCNetworkInterfaceRef
)interfacePrivate
,
3527 #if !TARGET_OS_IPHONE
3528 // set prefs & serviceID to Bond member interfaces
3529 if (CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeBond
)) {
3534 members
= SCBondInterfaceGetMemberInterfaces((SCNetworkInterfaceRef
)interfacePrivate
);
3535 n
= (members
!= NULL
) ? CFArrayGetCount(members
) : 0;
3536 for (i
= 0; i
< n
; i
++) {
3537 SCNetworkInterfaceRef member
;
3539 member
= CFArrayGetValueAtIndex(members
, i
);
3540 __SCNetworkInterfaceSetService(member
, service
);
3543 #endif // !TARGET_OS_IPHONE
3545 // set prefs & serviceID to Bridge member interfaces
3546 if (CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeBridge
)) {
3551 members
= SCBridgeInterfaceGetMemberInterfaces((SCNetworkInterfaceRef
)interfacePrivate
);
3552 n
= (members
!= NULL
) ? CFArrayGetCount(members
) : 0;
3553 for (i
= 0; i
< n
; i
++) {
3554 SCNetworkInterfaceRef member
;
3556 member
= CFArrayGetValueAtIndex(members
, i
);
3557 __SCNetworkInterfaceSetService(member
, service
);
3561 // set prefs & serviceID to VLAN pyhsical interface
3562 if (CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeVLAN
)) {
3563 SCNetworkInterfaceRef vlan_physical
;
3565 vlan_physical
= SCVLANInterfaceGetPhysicalInterface((SCNetworkInterfaceRef
)interfacePrivate
);
3566 if (vlan_physical
!= NULL
) {
3567 __SCNetworkInterfaceSetService(vlan_physical
, service
);
3572 if (CFEqual(ifType
, kSCValNetInterfaceTypePPP
)) {
3573 SCNetworkInterfaceRef parent
;
3576 parent
= SCNetworkInterfaceCreateWithInterface((SCNetworkInterfaceRef
)interfacePrivate
,
3577 kSCNetworkInterfaceTypePPP
);
3578 CFRelease(interfacePrivate
);
3579 interfacePrivate
= (SCNetworkInterfacePrivateRef
)parent
;
3580 } else if (CFEqual(ifType
, kSCValNetInterfaceTypeVPN
)) {
3581 SCNetworkInterfaceRef parent
;
3584 parent
= SCNetworkInterfaceCreateWithInterface((SCNetworkInterfaceRef
)interfacePrivate
,
3585 kSCNetworkInterfaceTypeVPN
);
3586 CFRelease(interfacePrivate
);
3587 interfacePrivate
= (SCNetworkInterfacePrivateRef
)parent
;
3590 return (SCNetworkInterfaceRef
)interfacePrivate
;
3595 #pragma mark SCNetworkInterface APIs
3600 __SCNetworkInterfaceCopyAll_IONetworkInterface(void)
3602 CFDictionaryRef matching
;
3603 CFArrayRef new_interfaces
;
3605 // get Ethernet, Firewire, and AirPort interfaces
3607 matching
= IOServiceMatching(kIONetworkInterfaceClass
);
3608 new_interfaces
= findMatchingInterfaces(matching
, processNetworkInterface
);
3609 CFRelease(matching
);
3611 return new_interfaces
;
3617 __SCNetworkInterfaceCopyAll_Modem()
3619 CFDictionaryRef matching
;
3620 CFStringRef match_keys
[2];
3621 CFStringRef match_vals
[2];
3622 CFArrayRef new_interfaces
;
3624 match_keys
[0] = CFSTR(kIOProviderClassKey
);
3625 match_vals
[0] = CFSTR(kIOSerialBSDServiceValue
);
3627 match_keys
[1] = CFSTR(kIOSerialBSDTypeKey
);
3628 match_vals
[1] = CFSTR(kIOSerialBSDModemType
);
3630 matching
= CFDictionaryCreate(NULL
,
3631 (const void **)match_keys
,
3632 (const void **)match_vals
,
3633 sizeof(match_keys
)/sizeof(match_keys
[0]),
3634 &kCFTypeDictionaryKeyCallBacks
,
3635 &kCFTypeDictionaryValueCallBacks
);
3636 new_interfaces
= findMatchingInterfaces(matching
, processSerialInterface
);
3637 CFRelease(matching
);
3639 return new_interfaces
;
3645 __SCNetworkInterfaceCopyAll_RS232()
3647 CFDictionaryRef matching
;
3648 CFStringRef match_keys
[2];
3649 CFStringRef match_vals
[2];
3650 CFArrayRef new_interfaces
;
3652 match_keys
[0] = CFSTR(kIOProviderClassKey
);
3653 match_vals
[0] = CFSTR(kIOSerialBSDServiceValue
);
3655 match_keys
[1] = CFSTR(kIOSerialBSDTypeKey
);
3656 match_vals
[1] = CFSTR(kIOSerialBSDRS232Type
);
3658 matching
= CFDictionaryCreate(NULL
,
3659 (const void **)match_keys
,
3660 (const void **)match_vals
,
3661 sizeof(match_keys
)/sizeof(match_keys
[0]),
3662 &kCFTypeDictionaryKeyCallBacks
,
3663 &kCFTypeDictionaryValueCallBacks
);
3664 new_interfaces
= findMatchingInterfaces(matching
, processSerialInterface
);
3665 CFRelease(matching
);
3667 return new_interfaces
;
3671 #if !TARGET_OS_IPHONE
3673 addBTPANInterface(SCPreferencesRef prefs
, CFMutableArrayRef all_interfaces
)
3677 CFArrayRef services
;
3679 n
= CFArrayGetCount(all_interfaces
);
3680 for (i
= 0; i
< n
; i
++) {
3681 SCNetworkInterfaceRef interface
;
3683 interface
= CFArrayGetValueAtIndex(all_interfaces
, i
);
3684 if (_SCNetworkInterfaceIsBluetoothPAN(interface
)) {
3685 // if we already have a BT-PAN interface
3690 services
= SCNetworkServiceCopyAll(prefs
);
3691 if (services
!= NULL
) {
3692 n
= CFArrayGetCount(services
);
3693 for (i
= 0; i
< n
; i
++) {
3694 SCNetworkInterfaceRef interface
;
3695 SCNetworkServiceRef service
;
3697 service
= CFArrayGetValueAtIndex(services
, i
);
3698 interface
= SCNetworkServiceGetInterface(service
);
3699 if ((interface
!= NULL
) &&
3700 _SCNetworkInterfaceIsBluetoothPAN(interface
)) {
3701 // include BT-PAN interface
3702 CFArrayAppendValue(all_interfaces
, interface
);
3707 CFRelease(services
);
3712 #endif // !TARGET_OS_IPHONE
3716 add_interfaces(CFMutableArrayRef all_interfaces
, CFArrayRef new_interfaces
)
3721 n
= CFArrayGetCount(new_interfaces
);
3722 for (i
= 0; i
< n
; i
++) {
3723 CFStringRef bsdName
;
3724 SCNetworkInterfaceRef interface
;
3726 interface
= CFArrayGetValueAtIndex(new_interfaces
, i
);
3727 bsdName
= SCNetworkInterfaceGetBSDName(interface
);
3728 if (bsdName
!= NULL
) {
3729 CFArrayAppendValue(all_interfaces
, interface
);
3738 __waitForInterfaces()
3743 SCDynamicStoreRef store
;
3745 store
= SCDynamicStoreCreate(NULL
, CFSTR("SCNetworkInterfaceCopyAll"), NULL
, NULL
);
3746 if (store
== NULL
) {
3750 key
= SCDynamicStoreKeyCreate(NULL
, CFSTR("%@" "InterfaceNamer"), kSCDynamicStoreDomainPlugin
);
3751 keys
= CFArrayCreate(NULL
, (const void **)&key
, 1, &kCFTypeArrayCallBacks
);
3752 ok
= SCDynamicStoreSetNotificationKeys(store
, keys
, NULL
);
3755 SCLog(TRUE
, LOG_ERR
,
3756 CFSTR("SCDynamicStoreSetNotificationKeys() failed: %s"), SCErrorString(SCError()));
3761 CFArrayRef changedKeys
;
3762 CFDictionaryRef dict
;
3763 Boolean quiet
= FALSE
;
3766 dict
= SCDynamicStoreCopyValue(store
, key
);
3768 if (isA_CFDictionary(dict
) &&
3769 (CFDictionaryContainsKey(dict
, CFSTR("*QUIET*")) ||
3770 CFDictionaryContainsKey(dict
, CFSTR("*TIMEOUT*")))) {
3779 ok
= SCDynamicStoreNotifyWait(store
);
3781 SCLog(TRUE
, LOG_ERR
,
3782 CFSTR("SCDynamicStoreNotifyWait() failed: %s"), SCErrorString(SCError()));
3786 changedKeys
= SCDynamicStoreCopyNotifiedKeys(store
);
3787 if (changedKeys
!= NULL
) {
3788 CFRelease(changedKeys
);
3800 CFArrayRef
/* of SCNetworkInterfaceRef's */
3801 _SCNetworkInterfaceCopyAllWithPreferences(SCPreferencesRef prefs
)
3803 CFMutableArrayRef all_interfaces
;
3804 CFArrayRef new_interfaces
;
3805 Boolean temp_preferences
= FALSE
;
3807 /* initialize runtime */
3808 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
3810 /* wait for IOKit to quiesce */
3811 pthread_once(&iokit_quiet
, __waitForInterfaces
);
3813 all_interfaces
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3815 // get Ethernet, Firewire, and AirPort interfaces
3816 new_interfaces
= __SCNetworkInterfaceCopyAll_IONetworkInterface();
3817 if (new_interfaces
!= NULL
) {
3818 add_interfaces(all_interfaces
, new_interfaces
);
3819 CFRelease(new_interfaces
);
3822 // get Modem interfaces
3823 new_interfaces
= __SCNetworkInterfaceCopyAll_Modem();
3824 if (new_interfaces
!= NULL
) {
3825 add_interfaces(all_interfaces
, new_interfaces
);
3826 CFRelease(new_interfaces
);
3829 // get serial (RS232) interfaces
3830 new_interfaces
= __SCNetworkInterfaceCopyAll_RS232();
3831 if (new_interfaces
!= NULL
) {
3832 add_interfaces(all_interfaces
, new_interfaces
);
3833 CFRelease(new_interfaces
);
3836 // get virtual network interfaces (Bond, Bridge, VLAN)
3837 if (prefs
== NULL
) {
3838 prefs
= SCPreferencesCreate(NULL
, CFSTR("SCNetworkInterfaceCopyAll"), NULL
);
3839 if (prefs
!= NULL
) {
3840 temp_preferences
= TRUE
;
3843 if (prefs
!= NULL
) {
3844 #if !TARGET_OS_IPHONE
3845 new_interfaces
= SCBondInterfaceCopyAll(prefs
);
3846 if (new_interfaces
!= NULL
) {
3847 add_interfaces(all_interfaces
, new_interfaces
);
3848 CFRelease(new_interfaces
);
3850 #endif // !TARGET_OS_IPHONE
3852 new_interfaces
= SCBridgeInterfaceCopyAll(prefs
);
3853 if (new_interfaces
!= NULL
) {
3854 add_interfaces(all_interfaces
, new_interfaces
);
3855 CFRelease(new_interfaces
);
3858 new_interfaces
= SCVLANInterfaceCopyAll(prefs
);
3859 if (new_interfaces
!= NULL
) {
3860 add_interfaces(all_interfaces
, new_interfaces
);
3861 CFRelease(new_interfaces
);
3864 #if !TARGET_OS_IPHONE
3865 // add BT-PAN interface
3866 addBTPANInterface(prefs
, all_interfaces
);
3867 #endif // !TARGET_OS_IPHONE
3869 if (temp_preferences
) CFRelease(prefs
);
3872 // all interfaces have been identified, order and return
3873 sort_interfaces(all_interfaces
);
3875 return all_interfaces
;
3879 CFArrayRef
/* of SCNetworkInterfaceRef's */
3880 SCNetworkInterfaceCopyAll()
3882 CFArrayRef all_interfaces
;
3884 all_interfaces
= _SCNetworkInterfaceCopyAllWithPreferences(NULL
);
3885 return all_interfaces
;
3889 CFArrayRef
/* of kSCNetworkInterfaceTypeXXX CFStringRef's */
3890 SCNetworkInterfaceGetSupportedInterfaceTypes(SCNetworkInterfaceRef interface
)
3893 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
3895 if (!isA_SCNetworkInterface(interface
)) {
3896 _SCErrorSet(kSCStatusInvalidArgument
);
3900 if (interfacePrivate
->supported_interface_types
!= NULL
) {
3904 i
= findConfiguration(interfacePrivate
->interface_type
);
3905 if (i
!= kCFNotFound
) {
3906 if (configurations
[i
].supported_interfaces
!= doNone
) {
3907 interfacePrivate
->supported_interface_types
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3908 if (configurations
[i
].supported_interfaces
& do6to4
) {
3909 CFArrayAppendValue(interfacePrivate
->supported_interface_types
, kSCNetworkInterfaceType6to4
);
3911 if (configurations
[i
].supported_interfaces
& doL2TP
) {
3912 CFArrayAppendValue(interfacePrivate
->supported_interface_types
, kSCNetworkInterfaceTypeL2TP
);
3914 if (configurations
[i
].supported_interfaces
& doPPP
) {
3915 CFArrayAppendValue(interfacePrivate
->supported_interface_types
, kSCNetworkInterfaceTypePPP
);
3917 if (configurations
[i
].supported_interfaces
& doPPTP
) {
3918 CFArrayAppendValue(interfacePrivate
->supported_interface_types
, kSCNetworkInterfaceTypePPTP
);
3920 if (configurations
[i
].supported_interfaces
& doIPSec
) {
3921 CFArrayAppendValue(interfacePrivate
->supported_interface_types
, kSCNetworkInterfaceTypeIPSec
);
3925 SCNetworkInterfaceRef child
;
3927 child
= SCNetworkInterfaceGetInterface(interface
);
3928 if ((child
!= NULL
) && CFEqual(child
, kSCNetworkInterfaceIPv4
)) {
3929 interfacePrivate
->supported_interface_types
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3930 CFArrayAppendValue(interfacePrivate
->supported_interface_types
, kSCNetworkInterfaceTypeVPN
);
3936 return interfacePrivate
->supported_interface_types
;
3940 CFArrayRef
/* of kSCNetworkProtocolTypeXXX CFStringRef's */
3941 SCNetworkInterfaceGetSupportedProtocolTypes(SCNetworkInterfaceRef interface
)
3944 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
3946 if (!isA_SCNetworkInterface(interface
)) {
3947 _SCErrorSet(kSCStatusInvalidArgument
);
3951 if (interfacePrivate
->supported_protocol_types
!= NULL
) {
3955 i
= findConfiguration(interfacePrivate
->interface_type
);
3956 if (i
!= kCFNotFound
) {
3957 if (configurations
[i
].supported_protocols
!= doNone
) {
3958 interfacePrivate
->supported_protocol_types
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3959 if (configurations
[i
].supported_protocols
& doDNS
) {
3960 CFArrayAppendValue(interfacePrivate
->supported_protocol_types
, kSCNetworkProtocolTypeDNS
);
3962 if (configurations
[i
].supported_protocols
& doIPv4
) {
3963 CFArrayAppendValue(interfacePrivate
->supported_protocol_types
, kSCNetworkProtocolTypeIPv4
);
3965 if (configurations
[i
].supported_protocols
& doIPv6
) {
3966 CFArrayAppendValue(interfacePrivate
->supported_protocol_types
, kSCNetworkProtocolTypeIPv6
);
3968 if (configurations
[i
].supported_protocols
& doProxies
) {
3969 CFArrayAppendValue(interfacePrivate
->supported_protocol_types
, kSCNetworkProtocolTypeProxies
);
3971 #if !TARGET_OS_IPHONE
3972 if (configurations
[i
].supported_protocols
& doSMB
) {
3973 CFArrayAppendValue(interfacePrivate
->supported_protocol_types
, kSCNetworkProtocolTypeSMB
);
3975 #endif // !TARGET_OS_IPHONE
3981 return interfacePrivate
->supported_protocol_types
;
3985 SCNetworkInterfaceRef
3986 SCNetworkInterfaceCreateWithInterface(SCNetworkInterfaceRef child
, CFStringRef interfaceType
)
3988 SCNetworkInterfacePrivateRef childPrivate
= (SCNetworkInterfacePrivateRef
)child
;
3990 SCNetworkInterfacePrivateRef parentPrivate
;
3992 if (!isA_SCNetworkInterface(child
)) {
3993 _SCErrorSet(kSCStatusInvalidArgument
);
3997 if (!isA_CFString(interfaceType
)) {
3998 _SCErrorSet(kSCStatusInvalidArgument
);
4002 if (CFEqual(child
, kSCNetworkInterfaceLoopback
)) {
4003 // can't layer on top of loopback
4004 _SCErrorSet(kSCStatusInvalidArgument
);
4008 childIndex
= findConfiguration(childPrivate
->interface_type
);
4010 parentPrivate
= __SCNetworkInterfaceCreatePrivate(NULL
,
4012 childPrivate
->prefs
,
4013 childPrivate
->serviceID
);
4014 if (parentPrivate
== NULL
) {
4015 _SCErrorSet(kSCStatusFailed
);
4019 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypePPP
)) {
4020 parentPrivate
->interface_type
= kSCNetworkInterfaceTypePPP
;
4021 parentPrivate
->entity_type
= kSCValNetInterfaceTypePPP
;
4024 if (childIndex
!= kCFNotFound
) {
4025 if (configurations
[childIndex
].ppp_subtype
!= NULL
) {
4026 parentPrivate
->entity_subtype
= *configurations
[childIndex
].ppp_subtype
;
4028 // sorry, the child interface does not support PPP
4032 // if the child's interface type not known, use the child entities "Type"
4033 parentPrivate
->entity_subtype
= childPrivate
->entity_type
;
4036 if (childPrivate
->entity_device
!= NULL
) {
4037 parentPrivate
->entity_device
= CFStringCreateCopy(NULL
, childPrivate
->entity_device
);
4040 if (childPrivate
->entity_device_unique
!= NULL
) {
4041 parentPrivate
->entity_device_unique
= CFStringCreateCopy(NULL
, childPrivate
->entity_device_unique
);
4043 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeL2TP
)) {
4044 if ((childIndex
== kCFNotFound
) ||
4045 ((configurations
[childIndex
].supported_interfaces
& doL2TP
) != doL2TP
)) {
4046 // if the child interface does not support L2TP
4049 parentPrivate
->interface_type
= kSCNetworkInterfaceTypeL2TP
;
4050 parentPrivate
->localized_key
= CFSTR("l2tp");
4051 parentPrivate
->entity_type
= kSCEntNetL2TP
; // interface config goes into "L2TP"
4052 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypePPTP
)) {
4053 if ((childIndex
== kCFNotFound
) ||
4054 ((configurations
[childIndex
].supported_interfaces
& doPPTP
) != doPPTP
)) {
4055 // if the child interface does not support PPTP
4058 parentPrivate
->interface_type
= kSCNetworkInterfaceTypePPTP
;
4059 parentPrivate
->localized_key
= CFSTR("pptp");
4060 parentPrivate
->entity_type
= kSCEntNetPPTP
; // interface config goes into "PPTP"
4061 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceType6to4
)) {
4062 if ((childIndex
== kCFNotFound
) ||
4063 ((configurations
[childIndex
].supported_interfaces
& do6to4
) != do6to4
)) {
4064 // if the child interface does not support 6to4
4068 parentPrivate
->interface_type
= kSCNetworkInterfaceType6to4
;
4069 parentPrivate
->localized_key
= CFSTR("6to4");
4070 parentPrivate
->entity_type
= kSCValNetInterfaceType6to4
;
4071 parentPrivate
->entity_device
= CFRetain(CFSTR("stf0"));
4072 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeIPSec
)) {
4073 if ((childIndex
== kCFNotFound
) ||
4074 ((configurations
[childIndex
].supported_interfaces
& doIPSec
) != doIPSec
)) {
4075 // if the child interface does not support IPSec
4078 parentPrivate
->interface_type
= kSCNetworkInterfaceTypeIPSec
;
4079 parentPrivate
->localized_key
= CFSTR("ipsec");
4080 parentPrivate
->entity_type
= kSCValNetInterfaceTypeIPSec
;
4081 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeVPN
)) {
4082 if (childIndex
!= kCFNotFound
) {
4083 // if not a "vendor" child interface
4087 parentPrivate
->interface_type
= kSCNetworkInterfaceTypeVPN
;
4088 parentPrivate
->localized_key
= CFSTR("vpn");
4089 parentPrivate
->localized_arg1
= CFRetain(childPrivate
->entity_type
);
4090 parentPrivate
->entity_type
= kSCValNetInterfaceTypeVPN
;
4091 parentPrivate
->entity_subtype
= childPrivate
->entity_type
;
4092 if (childPrivate
->entity_device
!= NULL
) {
4093 parentPrivate
->entity_device
= CFStringCreateCopy(NULL
, childPrivate
->entity_device
);
4095 if (parentPrivate
->entity_subtype
!= NULL
) {
4096 CFArrayRef components
;
4098 CFStringRef vpnType
;
4101 // the "default" interface name is derived from the VPN type
4104 // com.apple.Apple-VPN.vpnplugin --> "Apple VPN"
4107 vpnType
= parentPrivate
->entity_subtype
;
4108 components
= CFStringCreateArrayBySeparatingStrings(NULL
, vpnType
, CFSTR("."));
4109 n
= CFArrayGetCount(components
);
4111 CFEqual(CFArrayGetValueAtIndex(components
, n
- 1), CFSTR("vpnplugin"))) {
4112 CFMutableStringRef str
;
4114 str
= CFStringCreateMutableCopy(NULL
,
4116 CFArrayGetValueAtIndex(components
, n
- 2));
4117 (void) CFStringFindAndReplace(str
,
4120 CFRangeMake(0, CFStringGetLength(str
)),
4122 parentPrivate
->localized_name
= str
;
4124 CFRelease(components
);
4126 } else if (CFStringFind(interfaceType
, CFSTR("."), 0).location
!= kCFNotFound
) {
4127 // if custom interface type
4128 if (vendor_interface_types
== NULL
) {
4129 vendor_interface_types
= CFSetCreateMutable(NULL
, 0, &kCFTypeSetCallBacks
);
4131 CFSetAddValue(vendor_interface_types
, interfaceType
);
4133 parentPrivate
->interface_type
= CFSetGetValue(vendor_interface_types
, interfaceType
);
4134 parentPrivate
->entity_type
= parentPrivate
->interface_type
; // interface config goes into a
4135 // a dictionary with the same
4136 // name as the interfaceType
4138 // unknown interface type
4142 parentPrivate
->hidden
= childPrivate
->hidden
;
4144 if (childPrivate
->overrides
!= NULL
) {
4145 parentPrivate
->overrides
= CFDictionaryCreateMutableCopy(NULL
, 0, childPrivate
->overrides
);
4148 // The following change handles the case where a user has both an Ethernet and
4149 // PPPoE network service. Because a PPPoE service is typically associated with
4150 // an ISP we want it to be sorted higher in the service order.
4151 if ((parentPrivate
->entity_subtype
!= NULL
) &&
4152 (CFEqual(parentPrivate
->entity_subtype
, kSCValNetInterfaceSubTypePPPoE
))) {
4153 if ((childPrivate
->interface_type
!= NULL
) &&
4154 (CFEqual(childPrivate
->interface_type
, kSCNetworkInterfaceTypeIEEE80211
))) {
4155 parentPrivate
->sort_order
= kSortAirportPPP
;
4157 parentPrivate
->sort_order
= kSortEthernetPPP
;
4160 // set sort order of the parent to match the child interface
4161 parentPrivate
->sort_order
= childPrivate
->sort_order
;
4164 return (SCNetworkInterfaceRef
)parentPrivate
;
4168 CFRelease(parentPrivate
);
4169 _SCErrorSet(kSCStatusInvalidArgument
);
4176 __SCNetworkInterfaceGetDefaultConfiguration(SCNetworkSetRef set
, SCNetworkInterfaceRef interface
)
4178 CFDictionaryRef config
= NULL
;
4179 CFStringRef defaultType
;
4180 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4182 /* initialize runtime (and kSCNetworkInterfaceIPv4) */
4183 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
4185 defaultType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
4186 if (defaultType
!= NULL
) {
4190 path
= SCPreferencesPathKeyCreateSetNetworkInterfaceEntity(NULL
, // allocator
4191 SCNetworkSetGetSetID(set
), // set
4192 interfacePrivate
->entity_device
, // interface
4193 defaultType
); // entity
4195 config
= __getPrefsConfiguration(interfacePrivate
->prefs
, path
);
4198 if (config
== NULL
) {
4199 // if the "set" does not have a saved configuration, use
4200 // the [template] "interface" configuration
4201 if (interfacePrivate
->unsaved
!= NULL
) {
4202 config
= CFDictionaryGetValue(interfacePrivate
->unsaved
, defaultType
);
4203 if (config
== (CFDictionaryRef
)kCFNull
) {
4208 if (isA_CFDictionary(config
) && (CFDictionaryGetCount(config
) == 0)) {
4219 static CFDictionaryRef
4220 __SCNetworkInterfaceGetConfiguration(SCNetworkInterfaceRef interface
,
4221 CFStringRef extendedType
)
4223 CFDictionaryRef config
= NULL
;
4224 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4227 /* initialize runtime (and kSCNetworkInterfaceIPv4) */
4228 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
4230 paths
= copyConfigurationPaths(interfacePrivate
, extendedType
);
4231 if (paths
!= NULL
) {
4234 path
= CFArrayGetValueAtIndex(paths
, 0);
4235 config
= __getPrefsConfiguration(interfacePrivate
->prefs
, path
);
4239 if (interfacePrivate
->unsaved
!= NULL
) {
4240 config
= CFDictionaryGetValue(interfacePrivate
->unsaved
, extendedType
);
4241 if (config
== (CFDictionaryRef
)kCFNull
) {
4247 if (isA_CFDictionary(config
) && (CFDictionaryGetCount(config
) == 0)) {
4256 SCNetworkInterfaceGetConfiguration(SCNetworkInterfaceRef interface
)
4258 CFDictionaryRef config
;
4259 CFStringRef defaultType
;
4261 if (!isA_SCNetworkInterface(interface
)) {
4262 _SCErrorSet(kSCStatusInvalidArgument
);
4266 defaultType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
4267 if (defaultType
== NULL
) {
4271 config
= __SCNetworkInterfaceGetConfiguration(interface
, defaultType
);
4272 if (config
== NULL
) {
4273 if (CFEqual(defaultType
, kSCEntNetAirPort
)) {
4274 SCNetworkInterfacePrivateRef interfacePrivate
;
4277 // if AirPort interface, check for a per-service config
4278 interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4279 path
= SCPreferencesPathKeyCreateNetworkServiceEntity(NULL
, // allocator
4280 interfacePrivate
->serviceID
, // service
4281 kSCEntNetAirPort
); // entity
4282 config
= __getPrefsConfiguration(interfacePrivate
->prefs
, path
);
4286 if (config
== NULL
) {
4287 _SCErrorSet(kSCStatusOK
);
4295 SCNetworkInterfaceGetExtendedConfiguration(SCNetworkInterfaceRef interface
,
4296 CFStringRef extendedType
)
4298 CFDictionaryRef config
;
4300 if (!isA_SCNetworkInterface(interface
)) {
4301 _SCErrorSet(kSCStatusInvalidArgument
);
4305 if (!__SCNetworkInterfaceIsValidExtendedConfigurationType(interface
, extendedType
, TRUE
)) {
4306 _SCErrorSet(kSCStatusInvalidArgument
);
4310 config
= __SCNetworkInterfaceGetConfiguration(interface
, extendedType
);
4311 if (config
== NULL
) {
4312 _SCErrorSet(kSCStatusOK
);
4320 SCNetworkInterfaceGetBSDName(SCNetworkInterfaceRef interface
)
4322 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4324 if (!isA_SCNetworkInterface(interface
)) {
4325 _SCErrorSet(kSCStatusInvalidArgument
);
4329 if ((interfacePrivate
->interface
!= NULL
) &&
4330 (interfacePrivate
->interface
!= kSCNetworkInterfaceIPv4
)) {
4331 _SCErrorSet(kSCStatusOK
);
4335 return interfacePrivate
->entity_device
;
4340 SCNetworkInterfaceGetHardwareAddressString(SCNetworkInterfaceRef interface
)
4342 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4344 if (!isA_SCNetworkInterface(interface
)) {
4345 _SCErrorSet(kSCStatusInvalidArgument
);
4349 if ((interfacePrivate
->address
!= NULL
) &&
4350 (interfacePrivate
->addressString
== NULL
)) {
4354 char mac
[sizeof("xx:xx:xx:xx:xx:xx:xx:xx")];
4357 bp
= (uint8_t *)CFDataGetBytePtr(interfacePrivate
->address
);
4358 n
= CFDataGetLength(interfacePrivate
->address
) * 3;
4360 if (n
> sizeof(mac
)) {
4361 mac_p
= CFAllocatorAllocate(NULL
, 0, n
);
4364 for (cp
= mac_p
; n
> 0; n
-= 3) {
4365 cp
+= snprintf(cp
, n
, "%2.2x:", *bp
++);
4368 interfacePrivate
->addressString
= CFStringCreateWithCString(NULL
, mac_p
, kCFStringEncodingUTF8
);
4369 if (mac_p
!= mac
) CFAllocatorDeallocate(NULL
, mac_p
);
4372 return interfacePrivate
->addressString
;
4376 SCNetworkInterfaceRef
4377 SCNetworkInterfaceGetInterface(SCNetworkInterfaceRef interface
)
4379 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4381 if (!isA_SCNetworkInterface(interface
)) {
4382 _SCErrorSet(kSCStatusInvalidArgument
);
4386 return interfacePrivate
->interface
;
4391 SCNetworkInterfaceGetInterfaceType(SCNetworkInterfaceRef interface
)
4393 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4395 if (!isA_SCNetworkInterface(interface
)) {
4396 _SCErrorSet(kSCStatusInvalidArgument
);
4400 return interfacePrivate
->interface_type
;
4405 copy_interface_string(CFBundleRef bundle
, CFStringRef key
, Boolean localized
)
4407 CFStringRef str
= NULL
;
4410 str
= CFBundleCopyLocalizedString(bundle
,
4413 NETWORKINTERFACE_LOCALIZATIONS
);
4415 str
= _SC_CFBundleCopyNonLocalizedString(bundle
,
4418 NETWORKINTERFACE_LOCALIZATIONS
);
4426 copy_display_name(SCNetworkInterfaceRef interface
, Boolean localized
, Boolean oldLocalization
)
4428 CFMutableStringRef local
;
4431 local
= CFStringCreateMutable(NULL
, 0);
4433 while (interface
!= NULL
) {
4434 Boolean added
= FALSE
;
4435 SCNetworkInterfaceRef child
= NULL
;
4436 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4438 if ((interfacePrivate
->interface
!= NULL
) &&
4439 (interfacePrivate
->interface
!= kSCNetworkInterfaceIPv4
) &&
4440 !CFEqual(interfacePrivate
->interface_type
, kSCNetworkInterfaceTypeVPN
)) {
4441 child
= interfacePrivate
->interface
;
4444 if ((bundle
!= NULL
) && (interfacePrivate
->localized_key
!= NULL
)) {
4446 CFStringRef key
= interfacePrivate
->localized_key
;
4448 if (oldLocalization
) {
4449 key
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("X-%@"),
4450 interfacePrivate
->localized_key
);
4452 fmt
= copy_interface_string(bundle
, key
, localized
);
4454 CFStringAppendFormat(local
,
4457 interfacePrivate
->localized_arg1
,
4458 interfacePrivate
->localized_arg2
);
4462 if (oldLocalization
) {
4468 (interfacePrivate
->prefs
!= NULL
) &&
4469 (interfacePrivate
->serviceID
!= NULL
) &&
4471 CFDictionaryRef entity
;
4474 // check for (and use) the name of the interface when it
4475 // was last available
4476 path
= SCPreferencesPathKeyCreateNetworkServiceEntity(NULL
,
4477 interfacePrivate
->serviceID
,
4478 kSCEntNetInterface
);
4479 entity
= SCPreferencesPathGetValue(interfacePrivate
->prefs
, path
);
4481 if (isA_CFDictionary(entity
)) {
4484 name
= CFDictionaryGetValue(entity
, kSCPropUserDefinedName
);
4485 if (isA_CFString(name
)) {
4486 CFStringAppend(local
, name
);
4493 // create (non-)localized name based on the interface type
4494 CFStringAppend(local
, interfacePrivate
->interface_type
);
4496 // ... and, if this is a leaf node, the interface device
4497 if ((interfacePrivate
->entity_device
!= NULL
) && (child
== NULL
)) {
4498 CFStringAppendFormat(local
, NULL
, CFSTR(" (%@)"), interfacePrivate
->entity_device
);
4502 if (child
!= NULL
) {
4503 // if this interface is layered over another
4504 CFStringAppend(local
, CFSTR(" --> "));
4510 name
= CFStringCreateCopy(NULL
, local
);
4517 #if !TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR
4520 __SCNetworkInterfaceCopyXLocalizedDisplayName(SCNetworkInterfaceRef interface
)
4524 if (!isA_SCNetworkInterface(interface
)) {
4525 _SCErrorSet(kSCStatusInvalidArgument
);
4529 name
= copy_display_name(interface
, TRUE
, TRUE
);
4536 __SCNetworkInterfaceCopyXNonLocalizedDisplayName(SCNetworkInterfaceRef interface
)
4538 CFStringRef localized_name
;
4540 if (!isA_SCNetworkInterface(interface
)) {
4541 _SCErrorSet(kSCStatusInvalidArgument
);
4545 localized_name
= copy_display_name(interface
, FALSE
, TRUE
);
4546 return localized_name
;
4548 #endif // !TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR
4553 __SCNetworkInterfaceGetNonLocalizedDisplayName(SCNetworkInterfaceRef interface
)
4555 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4557 if (!isA_SCNetworkInterface(interface
)) {
4558 _SCErrorSet(kSCStatusInvalidArgument
);
4562 if (interfacePrivate
->name
== NULL
) {
4563 interfacePrivate
->name
= copy_display_name(interface
, FALSE
, FALSE
);
4566 return interfacePrivate
->name
;
4571 SCNetworkInterfaceGetLocalizedDisplayName(SCNetworkInterfaceRef interface
)
4573 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4575 if (!isA_SCNetworkInterface(interface
)) {
4576 _SCErrorSet(kSCStatusInvalidArgument
);
4580 if (interfacePrivate
->localized_name
== NULL
) {
4581 interfacePrivate
->localized_name
= copy_display_name(interface
, TRUE
, FALSE
);
4584 return interfacePrivate
->localized_name
;
4590 __SCNetworkInterfaceGetTemplateOverrides(SCNetworkInterfaceRef interface
, CFStringRef overrideType
)
4592 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4593 CFDictionaryRef overrides
= NULL
;
4595 if (interfacePrivate
->overrides
!= NULL
) {
4596 overrides
= CFDictionaryGetValue(interfacePrivate
->overrides
, overrideType
);
4604 SCNetworkInterfaceGetTypeID(void)
4606 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
); /* initialize runtime */
4607 return __kSCNetworkInterfaceTypeID
;
4613 __SCNetworkInterfaceSetDefaultConfiguration(SCNetworkSetRef set
,
4614 SCNetworkInterfaceRef interface
,
4615 CFStringRef defaultType
,
4616 CFDictionaryRef config
,
4619 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4622 /* initialize runtime (and kSCNetworkInterfaceIPv4) */
4623 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
4625 if (defaultType
== NULL
) {
4626 defaultType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
4627 if (defaultType
== NULL
) {
4632 if (isA_CFDictionary(config
) && (CFDictionaryGetCount(config
) == 0)) {
4639 path
= SCPreferencesPathKeyCreateSetNetworkInterfaceEntity(NULL
, // allocator
4640 SCNetworkSetGetSetID(set
), // set
4641 interfacePrivate
->entity_device
, // interface
4642 defaultType
); // entity
4644 ok
= __setPrefsConfiguration(interfacePrivate
->prefs
, path
, config
, FALSE
);
4647 // if configuration has been saved
4648 if (interfacePrivate
->unsaved
!= NULL
) {
4649 CFDictionaryRemoveValue(interfacePrivate
->unsaved
, defaultType
);
4650 if (CFDictionaryGetCount(interfacePrivate
->unsaved
) == 0) {
4651 CFRelease(interfacePrivate
->unsaved
);
4652 interfacePrivate
->unsaved
= NULL
;
4658 if (config
== NULL
) {
4659 // remember that we are clearing the configuration
4660 config
= (CFDictionaryRef
)kCFNull
;
4663 if (interfacePrivate
->unsaved
== NULL
) {
4664 interfacePrivate
->unsaved
= CFDictionaryCreateMutable(NULL
,
4666 &kCFTypeDictionaryKeyCallBacks
,
4667 &kCFTypeDictionaryValueCallBacks
);
4669 CFDictionarySetValue(interfacePrivate
->unsaved
, defaultType
, config
);
4672 _SCErrorSet(kSCStatusNoKey
);
4683 __SCNetworkInterfaceSetConfiguration(SCNetworkInterfaceRef interface
,
4684 CFStringRef extendedType
,
4685 CFDictionaryRef config
,
4688 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4692 /* initialize runtime (and kSCNetworkInterfaceIPv4) */
4693 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
4695 if (extendedType
== NULL
) {
4696 extendedType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
4697 if (extendedType
== NULL
) {
4702 if (isA_CFDictionary(config
) && (CFDictionaryGetCount(config
) == 0)) {
4706 paths
= copyConfigurationPaths(interfacePrivate
, extendedType
);
4707 if (paths
!= NULL
) {
4711 n
= CFArrayGetCount(paths
);
4712 for (i
= 0; i
< n
; i
++) {
4715 path
= CFArrayGetValueAtIndex(paths
, i
);
4716 ok
= __setPrefsConfiguration(interfacePrivate
->prefs
, path
, config
, FALSE
);
4723 // if configuration has been saved
4724 if (interfacePrivate
->unsaved
!= NULL
) {
4725 CFDictionaryRemoveValue(interfacePrivate
->unsaved
, extendedType
);
4726 if (CFDictionaryGetCount(interfacePrivate
->unsaved
) == 0) {
4727 CFRelease(interfacePrivate
->unsaved
);
4728 interfacePrivate
->unsaved
= NULL
;
4736 if (config
== NULL
) {
4737 // remember that we are clearing the configuration
4738 config
= (CFDictionaryRef
)kCFNull
;
4741 if (interfacePrivate
->unsaved
== NULL
) {
4742 interfacePrivate
->unsaved
= CFDictionaryCreateMutable(NULL
,
4744 &kCFTypeDictionaryKeyCallBacks
,
4745 &kCFTypeDictionaryValueCallBacks
);
4747 CFDictionarySetValue(interfacePrivate
->unsaved
, extendedType
, config
);
4750 _SCErrorSet(kSCStatusNoKey
);
4759 SCNetworkInterfaceSetConfiguration(SCNetworkInterfaceRef interface
, CFDictionaryRef config
)
4761 CFStringRef defaultType
;
4763 if (!isA_SCNetworkInterface(interface
)) {
4764 _SCErrorSet(kSCStatusInvalidArgument
);
4768 defaultType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
4769 if (defaultType
== NULL
) {
4773 return __SCNetworkInterfaceSetConfiguration(interface
, defaultType
, config
, FALSE
);
4778 SCNetworkInterfaceSetExtendedConfiguration(SCNetworkInterfaceRef interface
,
4779 CFStringRef extendedType
,
4780 CFDictionaryRef config
)
4782 if (!isA_SCNetworkInterface(interface
)) {
4783 _SCErrorSet(kSCStatusInvalidArgument
);
4787 if (!__SCNetworkInterfaceIsValidExtendedConfigurationType(interface
, extendedType
, TRUE
)) {
4791 return __SCNetworkInterfaceSetConfiguration(interface
, extendedType
, config
, FALSE
);
4796 #pragma mark SCNetworkInterface [Refresh Configuration] API
4799 #ifndef kSCEntNetRefreshConfiguration
4800 #define kSCEntNetRefreshConfiguration CFSTR("RefreshConfiguration")
4801 #endif // kSCEntNetRefreshConfiguration
4804 _SCNetworkInterfaceForceConfigurationRefresh(CFStringRef ifName
)
4809 if (!isA_CFString(ifName
)) {
4810 _SCErrorSet(kSCStatusInvalidArgument
);
4814 key
= SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL
,
4815 kSCDynamicStoreDomainState
,
4817 kSCEntNetRefreshConfiguration
);
4818 ok
= SCDynamicStoreNotifyValue(NULL
, key
);
4825 __SCNetworkInterfaceForceConfigurationRefresh_helper(SCPreferencesRef prefs
, CFStringRef ifName
)
4827 CFDataRef data
= NULL
;
4829 SCPreferencesPrivateRef prefsPrivate
= (SCPreferencesPrivateRef
)prefs
;
4830 uint32_t status
= kSCStatusOK
;
4831 CFDataRef reply
= NULL
;
4833 if (prefsPrivate
->helper_port
== MACH_PORT_NULL
) {
4834 ok
= __SCPreferencesCreate_helper(prefs
);
4840 // serialize the interface name
4841 ok
= _SCSerializeString(ifName
, &data
, NULL
, NULL
);
4846 // have the helper "refresh" the configuration
4847 status
= kSCStatusOK
;
4849 ok
= _SCHelperExec(prefsPrivate
->helper_port
,
4850 SCHELPER_MSG_INTERFACE_REFRESH
,
4854 if (data
!= NULL
) CFRelease(data
);
4859 if (status
!= kSCStatusOK
) {
4868 if (prefsPrivate
->helper_port
!= MACH_PORT_NULL
) {
4869 _SCHelperClose(&prefsPrivate
->helper_port
);
4872 status
= kSCStatusAccessError
;
4877 _SCErrorSet(status
);
4883 SCNetworkInterfaceForceConfigurationRefresh(SCNetworkInterfaceRef interface
)
4886 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
4888 if (!isA_SCNetworkInterface(interface
)) {
4889 _SCErrorSet(kSCStatusInvalidArgument
);
4893 ifName
= SCNetworkInterfaceGetBSDName(interface
);
4894 if (ifName
== NULL
) {
4895 _SCErrorSet(kSCStatusInvalidArgument
);
4899 if (interfacePrivate
->prefs
!= NULL
) {
4900 SCPreferencesRef prefs
= interfacePrivate
->prefs
;
4901 SCPreferencesPrivateRef prefsPrivate
= (SCPreferencesPrivateRef
)prefs
;
4903 if (prefsPrivate
->authorizationData
!= NULL
) {
4904 return __SCNetworkInterfaceForceConfigurationRefresh_helper(prefs
, ifName
);
4908 return _SCNetworkInterfaceForceConfigurationRefresh(ifName
);
4913 SCNetworkInterfaceRefreshConfiguration(CFStringRef ifName
)
4915 return _SCNetworkInterfaceForceConfigurationRefresh(ifName
);
4920 #pragma mark SCNetworkInterface Password APIs
4924 getPasswordID(CFDictionaryRef config
, CFStringRef serviceID
)
4926 CFStringRef unique_id
= NULL
;
4928 if (config
!= NULL
) {
4929 CFStringRef encryption
;
4931 encryption
= CFDictionaryGetValue(config
, kSCPropNetPPPAuthPasswordEncryption
);
4932 if (isA_CFString(encryption
) &&
4933 CFEqual(encryption
, kSCValNetPPPAuthPasswordEncryptionKeychain
)) {
4934 unique_id
= CFDictionaryGetValue(config
, kSCPropNetPPPAuthPassword
);
4937 if (unique_id
== NULL
) {
4938 unique_id
= serviceID
;
4946 copySharedSecretID(CFDictionaryRef config
, CFStringRef serviceID
)
4948 CFMutableStringRef shared_id
= NULL
;
4950 if (config
!= NULL
) {
4951 CFStringRef encryption
;
4953 encryption
= CFDictionaryGetValue(config
, kSCPropNetIPSecSharedSecretEncryption
);
4954 if (isA_CFString(encryption
) &&
4955 CFEqual(encryption
, kSCValNetIPSecSharedSecretEncryptionKeychain
)) {
4956 shared_id
= (CFMutableStringRef
)CFDictionaryGetValue(config
, kSCPropNetIPSecSharedSecret
);
4957 if (shared_id
!= NULL
) {
4958 CFRetain(shared_id
);
4963 if (shared_id
== NULL
) {
4964 CFStringRef unique_id
;
4966 unique_id
= getPasswordID(config
, serviceID
);
4967 shared_id
= CFStringCreateMutableCopy(NULL
, 0, unique_id
);
4968 CFStringAppend(shared_id
, CFSTR(".SS"));
4976 copyXAuthID(CFDictionaryRef config
, CFStringRef serviceID
)
4978 CFMutableStringRef xauth_id
= NULL
;
4980 if (config
!= NULL
) {
4981 CFStringRef encryption
;
4983 encryption
= CFDictionaryGetValue(config
, kSCPropNetIPSecXAuthPasswordEncryption
);
4984 if (isA_CFString(encryption
) &&
4985 CFEqual(encryption
, kSCValNetIPSecXAuthPasswordEncryptionKeychain
)) {
4986 xauth_id
= (CFMutableStringRef
)CFDictionaryGetValue(config
, kSCPropNetIPSecXAuthPassword
);
4987 if (xauth_id
!= NULL
) {
4993 if (xauth_id
== NULL
) {
4994 CFStringRef unique_id
;
4996 unique_id
= getPasswordID(config
, serviceID
);
4997 xauth_id
= CFStringCreateMutableCopy(NULL
, 0, unique_id
);
4998 CFStringAppend(xauth_id
, CFSTR(".XAUTH"));
5006 checkInterfacePassword(SCNetworkInterfaceRef interface
,
5007 SCNetworkInterfacePasswordType passwordType
,
5008 SCPreferencesRef
*prefs
,
5009 CFStringRef
*serviceID
)
5011 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
5013 if (!isA_SCNetworkInterface(interface
)) {
5017 *serviceID
= interfacePrivate
->serviceID
;
5018 if (*serviceID
== NULL
) {
5022 *prefs
= interfacePrivate
->prefs
;
5023 if (*prefs
== NULL
) {
5027 switch (passwordType
) {
5028 case kSCNetworkInterfacePasswordTypePPP
: {
5029 CFStringRef interfaceType
;
5031 interfaceType
= SCNetworkInterfaceGetInterfaceType(interface
);
5032 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypePPP
)) {
5040 case kSCNetworkInterfacePasswordTypeIPSecSharedSecret
: {
5041 CFStringRef interfaceType
;
5043 interfaceType
= SCNetworkInterfaceGetInterfaceType(interface
);
5044 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypePPP
)) {
5045 interface
= SCNetworkInterfaceGetInterface(interface
);
5046 if (interface
!= NULL
) {
5047 interfaceType
= SCNetworkInterfaceGetInterfaceType(interface
);
5048 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeL2TP
)) {
5049 // if PPP->L2TP interface
5053 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeIPSec
)) {
5054 // if IPSec interface
5061 case kSCNetworkInterfacePasswordTypeEAPOL
: {
5065 case kSCNetworkInterfacePasswordTypeIPSecXAuth
: {
5066 CFStringRef interfaceType
;
5068 interfaceType
= SCNetworkInterfaceGetInterfaceType(interface
);
5069 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeIPSec
)) {
5070 // if IPSec interface
5077 case kSCNetworkInterfacePasswordTypeVPN
: {
5078 CFStringRef interfaceType
;
5080 interfaceType
= SCNetworkInterfaceGetInterfaceType(interface
);
5081 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeVPN
)) {
5097 _SCErrorSet(kSCStatusInvalidArgument
);
5103 SCNetworkInterfaceCheckPassword(SCNetworkInterfaceRef interface
,
5104 SCNetworkInterfacePasswordType passwordType
)
5106 Boolean exists
= FALSE
;
5107 SCPreferencesRef prefs
= NULL
;
5108 CFStringRef serviceID
= NULL
;
5110 if (!checkInterfacePassword(interface
, passwordType
, &prefs
, &serviceID
)) {
5114 switch (passwordType
) {
5115 case kSCNetworkInterfacePasswordTypePPP
: {
5116 CFDictionaryRef config
;
5117 CFStringRef unique_id
;
5119 // get configuration
5120 config
= SCNetworkInterfaceGetConfiguration(interface
);
5123 unique_id
= getPasswordID(config
, serviceID
);
5126 exists
= __extract_password(prefs
,
5128 kSCPropNetPPPAuthPassword
,
5129 kSCPropNetPPPAuthPasswordEncryption
,
5130 kSCValNetPPPAuthPasswordEncryptionKeychain
,
5136 case kSCNetworkInterfacePasswordTypeIPSecSharedSecret
: {
5137 CFDictionaryRef config
;
5139 CFStringRef shared_id
;
5141 // get configuration
5142 extended
= CFEqual(SCNetworkInterfaceGetInterfaceType(interface
), kSCNetworkInterfaceTypePPP
);
5144 config
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetIPSec
);
5146 config
= SCNetworkInterfaceGetConfiguration(interface
);
5149 // get sharedSecret ID
5150 shared_id
= copySharedSecretID(config
, serviceID
);
5153 exists
= __extract_password(prefs
,
5155 kSCPropNetIPSecSharedSecret
,
5156 kSCPropNetIPSecSharedSecretEncryption
,
5157 kSCValNetIPSecSharedSecretEncryptionKeychain
,
5160 CFRelease(shared_id
);
5164 case kSCNetworkInterfacePasswordTypeEAPOL
: {
5165 CFDictionaryRef config
;
5166 CFStringRef unique_id
= NULL
;
5168 // get configuration
5169 config
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetEAPOL
);
5171 // get 802.1X identifier
5172 if (config
!= NULL
) {
5173 unique_id
= CFDictionaryGetValue(config
, kEAPClientPropUserPasswordKeychainItemID
);
5175 if (!isA_CFString(unique_id
)) {
5180 exists
= _SCPreferencesSystemKeychainPasswordItemExists(prefs
, unique_id
);
5184 case kSCNetworkInterfacePasswordTypeIPSecXAuth
: {
5185 CFDictionaryRef config
;
5186 CFStringRef xauth_id
;
5188 // get configuration
5189 config
= SCNetworkInterfaceGetConfiguration(interface
);
5192 xauth_id
= copyXAuthID(config
, serviceID
);
5195 exists
= __extract_password(prefs
,
5197 kSCPropNetIPSecXAuthPassword
,
5198 kSCPropNetIPSecXAuthPasswordEncryption
,
5199 kSCValNetIPSecXAuthPasswordEncryptionKeychain
,
5202 CFRelease(xauth_id
);
5206 case kSCNetworkInterfacePasswordTypeVPN
: {
5207 CFDictionaryRef config
;
5210 // get configuration
5211 config
= SCNetworkInterfaceGetConfiguration(interface
);
5214 vpn_id
= getPasswordID(config
, serviceID
);
5217 exists
= __extract_password(prefs
,
5219 kSCPropNetVPNAuthPassword
,
5220 kSCPropNetVPNAuthPasswordEncryption
,
5221 kSCValNetVPNAuthPasswordEncryptionKeychain
,
5228 _SCErrorSet(kSCStatusInvalidArgument
);
5237 SCNetworkInterfaceCopyPassword(SCNetworkInterfaceRef interface
,
5238 SCNetworkInterfacePasswordType passwordType
)
5240 CFDataRef password
= NULL
;
5241 SCPreferencesRef prefs
= NULL
;
5242 CFStringRef serviceID
= NULL
;
5244 if (!checkInterfacePassword(interface
, passwordType
, &prefs
, &serviceID
)) {
5248 switch (passwordType
) {
5249 case kSCNetworkInterfacePasswordTypePPP
: {
5250 CFDictionaryRef config
;
5251 CFStringRef unique_id
;
5253 // get configuration
5254 config
= SCNetworkInterfaceGetConfiguration(interface
);
5257 unique_id
= getPasswordID(config
, serviceID
);
5260 (void) __extract_password(prefs
,
5262 kSCPropNetPPPAuthPassword
,
5263 kSCPropNetPPPAuthPasswordEncryption
,
5264 kSCValNetPPPAuthPasswordEncryptionKeychain
,
5270 case kSCNetworkInterfacePasswordTypeIPSecSharedSecret
: {
5271 CFDictionaryRef config
;
5273 CFStringRef shared_id
;
5275 // get configuration
5276 extended
= CFEqual(SCNetworkInterfaceGetInterfaceType(interface
), kSCNetworkInterfaceTypePPP
);
5278 config
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetIPSec
);
5280 config
= SCNetworkInterfaceGetConfiguration(interface
);
5283 // get sharedSecret ID
5284 shared_id
= copySharedSecretID(config
, serviceID
);
5287 (void) __extract_password(prefs
,
5289 kSCPropNetIPSecSharedSecret
,
5290 kSCPropNetIPSecSharedSecretEncryption
,
5291 kSCValNetIPSecSharedSecretEncryptionKeychain
,
5295 CFRelease(shared_id
);
5299 case kSCNetworkInterfacePasswordTypeEAPOL
: {
5300 CFDictionaryRef config
;
5301 CFStringRef unique_id
= NULL
;
5303 // get configuration
5304 config
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetEAPOL
);
5306 // get 802.1X identifier
5307 if (config
!= NULL
) {
5308 unique_id
= CFDictionaryGetValue(config
, kEAPClientPropUserPasswordKeychainItemID
);
5310 if (!isA_CFString(unique_id
)) {
5311 _SCErrorSet(kSCStatusFailed
);
5316 password
= _SCPreferencesSystemKeychainPasswordItemCopy(prefs
, unique_id
);
5320 case kSCNetworkInterfacePasswordTypeIPSecXAuth
: {
5321 CFDictionaryRef config
;
5322 CFStringRef xauth_id
;
5324 // get configuration
5325 config
= SCNetworkInterfaceGetConfiguration(interface
);
5328 xauth_id
= copyXAuthID(config
, serviceID
);
5331 (void) __extract_password(prefs
,
5333 kSCPropNetIPSecXAuthPassword
,
5334 kSCPropNetIPSecXAuthPasswordEncryption
,
5335 kSCValNetIPSecXAuthPasswordEncryptionKeychain
,
5338 CFRelease(xauth_id
);
5342 case kSCNetworkInterfacePasswordTypeVPN
: {
5343 CFDictionaryRef config
;
5346 // get configuration
5347 config
= SCNetworkInterfaceGetConfiguration(interface
);
5350 vpn_id
= getPasswordID(config
, serviceID
);
5353 (void) __extract_password(prefs
,
5355 kSCPropNetVPNAuthPassword
,
5356 kSCPropNetVPNAuthPasswordEncryption
,
5357 kSCValNetVPNAuthPasswordEncryptionKeychain
,
5364 _SCErrorSet(kSCStatusInvalidArgument
);
5373 SCNetworkInterfaceRemovePassword(SCNetworkInterfaceRef interface
,
5374 SCNetworkInterfacePasswordType passwordType
)
5377 SCPreferencesRef prefs
= NULL
;
5378 CFStringRef serviceID
= NULL
;
5380 if (!checkInterfacePassword(interface
, passwordType
, &prefs
, &serviceID
)) {
5384 switch (passwordType
) {
5385 case kSCNetworkInterfacePasswordTypePPP
: {
5386 CFDictionaryRef config
;
5387 CFDictionaryRef newConfig
= NULL
;
5388 CFStringRef unique_id
;
5390 // get configuration
5391 config
= SCNetworkInterfaceGetConfiguration(interface
);
5394 unique_id
= getPasswordID(config
, serviceID
);
5397 ok
= __remove_password(prefs
,
5399 kSCPropNetPPPAuthPassword
,
5400 kSCPropNetPPPAuthPasswordEncryption
,
5401 kSCValNetPPPAuthPasswordEncryptionKeychain
,
5405 ok
= SCNetworkInterfaceSetConfiguration(interface
, newConfig
);
5406 if (newConfig
!= NULL
) CFRelease(newConfig
);
5412 case kSCNetworkInterfacePasswordTypeIPSecSharedSecret
: {
5413 CFDictionaryRef config
;
5415 CFDictionaryRef newConfig
= NULL
;
5416 CFStringRef shared_id
;
5418 // get configuration
5419 extended
= CFEqual(SCNetworkInterfaceGetInterfaceType(interface
), kSCNetworkInterfaceTypePPP
);
5421 config
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetIPSec
);
5423 config
= SCNetworkInterfaceGetConfiguration(interface
);
5426 // get sharedSecret ID
5427 shared_id
= copySharedSecretID(config
, serviceID
);
5430 ok
= __remove_password(prefs
,
5432 kSCPropNetIPSecSharedSecret
,
5433 kSCPropNetIPSecSharedSecretEncryption
,
5434 kSCValNetIPSecSharedSecretEncryptionKeychain
,
5439 ok
= SCNetworkInterfaceSetExtendedConfiguration(interface
,
5443 ok
= SCNetworkInterfaceSetConfiguration(interface
,
5446 if (newConfig
!= NULL
) CFRelease(newConfig
);
5449 CFRelease(shared_id
);
5453 case kSCNetworkInterfacePasswordTypeEAPOL
: {
5454 CFDictionaryRef config
;
5455 CFStringRef unique_id
= NULL
;
5457 // get configuration
5458 config
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetEAPOL
);
5460 // get 802.1X identifier
5461 if (config
!= NULL
) {
5462 unique_id
= CFDictionaryGetValue(config
, kEAPClientPropUserPasswordKeychainItemID
);
5464 if (!isA_CFString(unique_id
)) {
5465 _SCErrorSet(kSCStatusFailed
);
5470 ok
= _SCPreferencesSystemKeychainPasswordItemRemove(prefs
, unique_id
);
5474 case kSCNetworkInterfacePasswordTypeIPSecXAuth
: {
5475 CFDictionaryRef config
;
5476 CFDictionaryRef newConfig
= NULL
;
5477 CFStringRef xauth_id
;
5479 // get configuration
5480 config
= SCNetworkInterfaceGetConfiguration(interface
);
5483 xauth_id
= copyXAuthID(config
, serviceID
);
5486 ok
= __remove_password(prefs
,
5488 kSCPropNetIPSecXAuthPassword
,
5489 kSCPropNetIPSecXAuthPasswordEncryption
,
5490 kSCValNetIPSecXAuthPasswordEncryptionKeychain
,
5494 ok
= SCNetworkInterfaceSetConfiguration(interface
, newConfig
);
5495 if (newConfig
!= NULL
) CFRelease(newConfig
);
5498 CFRelease(xauth_id
);
5502 case kSCNetworkInterfacePasswordTypeVPN
: {
5503 CFDictionaryRef config
;
5504 CFDictionaryRef newConfig
= NULL
;
5507 // get configuration
5508 config
= SCNetworkInterfaceGetConfiguration(interface
);
5511 vpn_id
= getPasswordID(config
, serviceID
);
5514 ok
= __remove_password(prefs
,
5516 kSCPropNetVPNAuthPassword
,
5517 kSCPropNetVPNAuthPasswordEncryption
,
5518 kSCValNetVPNAuthPasswordEncryptionKeychain
,
5522 ok
= SCNetworkInterfaceSetConfiguration(interface
, newConfig
);
5523 if (newConfig
!= NULL
) CFRelease(newConfig
);
5529 _SCErrorSet(kSCStatusInvalidArgument
);
5538 SCNetworkInterfaceSetPassword(SCNetworkInterfaceRef interface
,
5539 SCNetworkInterfacePasswordType passwordType
,
5541 CFDictionaryRef options
)
5543 CFStringRef account
= NULL
;
5544 CFDictionaryRef config
;
5545 CFStringRef description
= NULL
;
5546 CFStringRef label
= NULL
;
5548 SCPreferencesRef prefs
= NULL
;
5549 CFStringRef serviceID
= NULL
;
5551 if (!checkInterfacePassword(interface
, passwordType
, &prefs
, &serviceID
)) {
5555 switch (passwordType
) {
5556 case kSCNetworkInterfacePasswordTypePPP
: {
5557 SCNetworkServiceRef service
= NULL
;
5558 CFStringRef unique_id
;
5560 // get configuration
5561 config
= SCNetworkInterfaceGetConfiguration(interface
);
5564 unique_id
= getPasswordID(config
, serviceID
);
5566 // get "Account", "Name", "Kind"
5567 if (config
!= NULL
) {
5568 // auth name --> keychain "Account"
5569 account
= CFDictionaryGetValue(config
, kSCPropNetPPPAuthName
);
5571 // PPP [user defined] "name" --> keychain "Name"
5572 label
= CFDictionaryGetValue(config
, kSCPropUserDefinedName
);
5575 if (label
== NULL
) {
5576 // service name --> keychain "Name"
5577 service
= (SCNetworkServiceRef
)__SCNetworkServiceCreatePrivate(NULL
,
5582 label
= SCNetworkServiceGetName(service
);
5583 if (label
== NULL
) {
5584 // interface name --> keychain "Name"
5585 label
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
5589 if (bundle
!= NULL
) {
5590 // "PPP Password" --> keychain "Kind"
5591 description
= CFBundleCopyLocalizedString(bundle
,
5592 CFSTR("KEYCHAIN_KIND_PPP_PASSWORD"),
5593 CFSTR("PPP Password"),
5598 ok
= _SCPreferencesSystemKeychainPasswordItemSet(prefs
,
5600 (label
!= NULL
) ? label
: CFSTR("Network Connection"),
5601 (description
!= NULL
) ? description
: CFSTR("PPP Password"),
5606 CFMutableDictionaryRef newConfig
;
5608 if (config
!= NULL
) {
5609 newConfig
= CFDictionaryCreateMutableCopy(NULL
, 0, config
);
5611 newConfig
= CFDictionaryCreateMutable(NULL
,
5613 &kCFTypeDictionaryKeyCallBacks
,
5614 &kCFTypeDictionaryValueCallBacks
);
5616 CFDictionarySetValue(newConfig
,
5617 kSCPropNetPPPAuthPassword
,
5619 CFDictionarySetValue(newConfig
,
5620 kSCPropNetPPPAuthPasswordEncryption
,
5621 kSCValNetPPPAuthPasswordEncryptionKeychain
);
5622 ok
= SCNetworkInterfaceSetConfiguration(interface
, newConfig
);
5623 CFRelease(newConfig
);
5626 if (description
!= NULL
) CFRelease(description
);
5627 if (service
!= NULL
) CFRelease(service
);
5631 case kSCNetworkInterfacePasswordTypeIPSecSharedSecret
: {
5632 CFDictionaryRef baseConfig
= NULL
;
5634 SCNetworkServiceRef service
= NULL
;
5635 CFStringRef shared_id
;
5637 // get configuration
5638 extended
= CFEqual(SCNetworkInterfaceGetInterfaceType(interface
), kSCNetworkInterfaceTypePPP
);
5639 config
= SCNetworkInterfaceGetConfiguration(interface
);
5641 baseConfig
= config
;
5642 config
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetIPSec
);
5645 // get sharedSecret ID
5646 shared_id
= copySharedSecretID(config
, serviceID
);
5648 // get "Account", "Name", "Kind"
5649 if (config
!= NULL
) {
5650 CFStringRef localIdentifier
;
5651 CFStringRef localIdentifierType
;
5653 if (CFDictionaryGetValueIfPresent(config
,
5654 kSCPropNetIPSecLocalIdentifierType
,
5655 (const void **)&localIdentifierType
)
5656 && CFEqual(localIdentifierType
, kSCValNetIPSecLocalIdentifierTypeKeyID
)
5657 && CFDictionaryGetValueIfPresent(config
,
5658 kSCPropNetIPSecLocalIdentifier
,
5659 (const void **)&localIdentifier
)
5660 && isA_CFString(localIdentifier
)) {
5661 // local identifier --> keychain "Account"
5662 account
= localIdentifier
;
5665 // PPP [user defined] "name" --> keychain "Name"
5667 label
= CFDictionaryGetValue(config
, kSCPropUserDefinedName
);
5669 if (baseConfig
!= NULL
) {
5670 label
= CFDictionaryGetValue(baseConfig
, kSCPropUserDefinedName
);
5675 if (label
== NULL
) {
5676 // service name --> keychain "Name"
5677 service
= (SCNetworkServiceRef
)__SCNetworkServiceCreatePrivate(NULL
,
5682 label
= SCNetworkServiceGetName(service
);
5683 if (label
== NULL
) {
5684 // interface name --> keychain "Name"
5685 label
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
5689 if (bundle
!= NULL
) {
5690 // "IPSec Shared Secret" --> keychain "Kind"
5691 description
= CFBundleCopyLocalizedString(bundle
,
5692 CFSTR("KEYCHAIN_KIND_IPSEC_SHARED_SECRET"),
5693 CFSTR("IPSec Shared Secret"),
5698 ok
= _SCPreferencesSystemKeychainPasswordItemSet(prefs
,
5700 (label
!= NULL
) ? label
: CFSTR("Network Connection"),
5701 (description
!= NULL
) ? description
: CFSTR("IPSec Shared Secret"),
5706 CFMutableDictionaryRef newConfig
= NULL
;
5708 if (config
!= NULL
) {
5709 newConfig
= CFDictionaryCreateMutableCopy(NULL
, 0, config
);
5711 newConfig
= CFDictionaryCreateMutable(NULL
,
5713 &kCFTypeDictionaryKeyCallBacks
,
5714 &kCFTypeDictionaryValueCallBacks
);
5716 CFDictionarySetValue(newConfig
,
5717 kSCPropNetIPSecSharedSecret
,
5719 CFDictionarySetValue(newConfig
,
5720 kSCPropNetIPSecSharedSecretEncryption
,
5721 kSCValNetIPSecSharedSecretEncryptionKeychain
);
5723 ok
= SCNetworkInterfaceSetExtendedConfiguration(interface
,
5727 ok
= SCNetworkInterfaceSetConfiguration(interface
, newConfig
);
5729 CFRelease(newConfig
);
5732 if (description
!= NULL
) CFRelease(description
);
5733 if (service
!= NULL
) CFRelease(service
);
5734 CFRelease(shared_id
);
5738 case kSCNetworkInterfacePasswordTypeEAPOL
: {
5739 CFStringRef account
= NULL
;
5740 CFStringRef unique_id
= NULL
;
5742 // get configuration
5743 config
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetEAPOL
);
5745 // get 802.1X identifier
5746 if (config
!= NULL
) {
5747 unique_id
= CFDictionaryGetValue(config
, kEAPClientPropUserPasswordKeychainItemID
);
5748 unique_id
= isA_CFString(unique_id
);
5750 if (unique_id
!= NULL
) {
5751 CFRetain(unique_id
);
5755 uuid
= CFUUIDCreate(NULL
);
5756 unique_id
= CFUUIDCreateString(NULL
, uuid
);
5760 // 802.1x UserName --> keychain "Account"
5761 if (config
!= NULL
) {
5762 account
= CFDictionaryGetValue(config
, kEAPClientPropUserName
);
5765 // get "Name", "Kind"
5766 if (bundle
!= NULL
) {
5767 CFStringRef interface_name
;
5769 // "Network Connection (%@)" --> keychain "Name"
5770 interface_name
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
5771 if (interface_name
!= NULL
) {
5772 CFStringRef label_fmt
;
5774 label_fmt
= CFBundleCopyLocalizedString(bundle
,
5775 CFSTR("KEYCHAIN_DESCRIPTION_EAPOL_INTERFACE"),
5776 CFSTR("Network Connection (%@)"),
5778 label
= CFStringCreateWithFormat(NULL
, NULL
, label_fmt
, interface_name
);
5779 CFRelease(label_fmt
);
5781 label
= CFBundleCopyLocalizedString(bundle
,
5782 CFSTR("KEYCHAIN_DESCRIPTION_EAPOL"),
5783 CFSTR("Network Connection"),
5787 // "802.1X Password" --> keychain "Kind"
5788 description
= CFBundleCopyLocalizedString(bundle
,
5789 CFSTR("KEYCHAIN_KIND_EAPOL"),
5790 CFSTR("802.1X Password"),
5795 ok
= _SCPreferencesSystemKeychainPasswordItemSet(prefs
,
5797 (label
!= NULL
) ? label
: CFSTR("Network Connection"),
5798 (description
!= NULL
) ? description
: CFSTR("802.1X Password"),
5803 CFMutableDictionaryRef newConfig
= NULL
;
5805 if (config
!= NULL
) {
5806 newConfig
= CFDictionaryCreateMutableCopy(NULL
, 0, config
);
5808 newConfig
= CFDictionaryCreateMutable(NULL
,
5810 &kCFTypeDictionaryKeyCallBacks
,
5811 &kCFTypeDictionaryValueCallBacks
);
5813 CFDictionarySetValue(newConfig
,
5814 kEAPClientPropUserPasswordKeychainItemID
,
5816 ok
= SCNetworkInterfaceSetExtendedConfiguration(interface
,
5819 CFRelease(newConfig
);
5822 CFRelease(unique_id
);
5823 if (label
!= NULL
) CFRelease(label
);
5824 if (description
!= NULL
) CFRelease(description
);
5828 case kSCNetworkInterfacePasswordTypeIPSecXAuth
: {
5829 SCNetworkServiceRef service
= NULL
;
5830 CFStringRef xauth_id
;
5832 // get configuration
5833 config
= SCNetworkInterfaceGetConfiguration(interface
);
5836 xauth_id
= copyXAuthID(config
, serviceID
);
5838 // get "Account", "Name", "Kind"
5839 if (config
!= NULL
) {
5840 // auth name --> keychain "Account"
5841 account
= CFDictionaryGetValue(config
, kSCPropNetIPSecXAuthName
);
5843 // IPSec [user defined] "name" --> keychain "Name"
5844 label
= CFDictionaryGetValue(config
, kSCPropUserDefinedName
);
5847 if (label
== NULL
) {
5848 // service name --> keychain "Name"
5849 service
= (SCNetworkServiceRef
)__SCNetworkServiceCreatePrivate(NULL
,
5854 label
= SCNetworkServiceGetName(service
);
5855 if (label
== NULL
) {
5856 // interface name --> keychain "Name"
5857 label
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
5861 if (bundle
!= NULL
) {
5862 // "IPSec XAuth Password" --> keychain "Kind"
5863 description
= CFBundleCopyLocalizedString(bundle
,
5864 CFSTR("KEYCHAIN_KIND_IPSEC_XAUTH_PASSWORD"),
5865 CFSTR("IPSec XAuth Password"),
5870 ok
= _SCPreferencesSystemKeychainPasswordItemSet(prefs
,
5872 (label
!= NULL
) ? label
: CFSTR("Network Connection"),
5873 (description
!= NULL
) ? description
: CFSTR("IPSec XAuth Password"),
5878 CFMutableDictionaryRef newConfig
;
5880 if (config
!= NULL
) {
5881 newConfig
= CFDictionaryCreateMutableCopy(NULL
, 0, config
);
5883 newConfig
= CFDictionaryCreateMutable(NULL
,
5885 &kCFTypeDictionaryKeyCallBacks
,
5886 &kCFTypeDictionaryValueCallBacks
);
5888 CFDictionarySetValue(newConfig
,
5889 kSCPropNetIPSecXAuthPassword
,
5891 CFDictionarySetValue(newConfig
,
5892 kSCPropNetIPSecXAuthPasswordEncryption
,
5893 kSCValNetIPSecXAuthPasswordEncryptionKeychain
);
5894 ok
= SCNetworkInterfaceSetConfiguration(interface
, newConfig
);
5895 CFRelease(newConfig
);
5898 CFRelease(xauth_id
);
5899 if (description
!= NULL
) CFRelease(description
);
5900 if (service
!= NULL
) CFRelease(service
);
5904 case kSCNetworkInterfacePasswordTypeVPN
: {
5905 SCNetworkServiceRef service
= NULL
;
5908 // get configuration
5909 config
= SCNetworkInterfaceGetConfiguration(interface
);
5912 vpn_id
= getPasswordID(config
, serviceID
);
5914 // get "Account", "Name", "Kind"
5915 if (config
!= NULL
) {
5916 // auth name --> keychain "Account"
5917 account
= CFDictionaryGetValue(config
, kSCPropNetVPNAuthName
);
5919 // VPN [user defined] "name" --> keychain "Name"
5920 label
= CFDictionaryGetValue(config
, kSCPropUserDefinedName
);
5923 if (label
== NULL
) {
5924 // service name --> keychain "Name"
5925 service
= (SCNetworkServiceRef
)__SCNetworkServiceCreatePrivate(NULL
,
5930 label
= SCNetworkServiceGetName(service
);
5931 if (label
== NULL
) {
5932 // interface name --> keychain "Name"
5933 label
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
5937 if (bundle
!= NULL
) {
5938 // "VPN Password" --> keychain "Kind"
5939 description
= CFBundleCopyLocalizedString(bundle
,
5940 CFSTR("KEYCHAIN_KIND_VPN_PASSWORD"),
5941 CFSTR("VPN Password"),
5946 ok
= _SCPreferencesSystemKeychainPasswordItemSet(prefs
,
5948 (label
!= NULL
) ? label
: CFSTR("Network Connection"),
5949 (description
!= NULL
) ? description
: CFSTR("VPN Password"),
5954 CFMutableDictionaryRef newConfig
;
5956 if (config
!= NULL
) {
5957 newConfig
= CFDictionaryCreateMutableCopy(NULL
, 0, config
);
5959 newConfig
= CFDictionaryCreateMutable(NULL
,
5961 &kCFTypeDictionaryKeyCallBacks
,
5962 &kCFTypeDictionaryValueCallBacks
);
5964 CFDictionarySetValue(newConfig
,
5965 kSCPropNetVPNAuthPassword
,
5967 CFDictionarySetValue(newConfig
,
5968 kSCPropNetVPNAuthPasswordEncryption
,
5969 kSCValNetVPNAuthPasswordEncryptionKeychain
);
5970 ok
= SCNetworkInterfaceSetConfiguration(interface
, newConfig
);
5971 CFRelease(newConfig
);
5974 if (description
!= NULL
) CFRelease(description
);
5975 if (service
!= NULL
) CFRelease(service
);
5980 _SCErrorSet(kSCStatusInvalidArgument
);
5989 #pragma mark SCNetworkInterface [InterfaceNamer] SPIs
5993 _SCNetworkInterfaceCopyInterfaceInfo(SCNetworkInterfaceRef interface
)
5995 CFMutableDictionaryRef info
;
5996 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
5999 info
= CFDictionaryCreateMutable(NULL
,
6001 &kCFTypeDictionaryKeyCallBacks
,
6002 &kCFTypeDictionaryValueCallBacks
);
6004 // add non-localized interface name
6005 name
= __SCNetworkInterfaceGetNonLocalizedDisplayName(interface
);
6007 CFDictionaryAddValue(info
, kSCPropUserDefinedName
, name
);
6011 if ((interfacePrivate
->usb
.vid
!= NULL
) || (interfacePrivate
->usb
.pid
!= NULL
)) {
6012 if (interfacePrivate
->usb
.name
!= NULL
) {
6013 CFDictionaryAddValue(info
, CFSTR(kUSBProductString
), interfacePrivate
->usb
.name
);
6015 if (interfacePrivate
->usb
.vid
!= NULL
) {
6016 CFDictionaryAddValue(info
, CFSTR(kUSBVendorID
), interfacePrivate
->usb
.vid
);
6018 if (interfacePrivate
->usb
.pid
!= NULL
) {
6019 CFDictionaryAddValue(info
, CFSTR(kUSBProductID
), interfacePrivate
->usb
.pid
);
6023 if (CFDictionaryGetCount(info
) == 0) {
6024 // do not return an empty dictionary
6033 SCNetworkInterfaceRef
6034 _SCNetworkInterfaceCreateWithIONetworkInterfaceObject(io_object_t if_obj
)
6036 SCNetworkInterfaceRef interface
= NULL
;
6038 /* initialize runtime */
6039 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
6041 if (IOObjectConformsTo(if_obj
, kIONetworkInterfaceClass
)) {
6042 interface
= createInterface(if_obj
, processNetworkInterface
);
6043 } else if (IOObjectConformsTo(if_obj
, kIOSerialBSDServiceValue
)) {
6044 interface
= createInterface(if_obj
, processSerialInterface
);
6052 _SCNetworkInterfaceGetConfigurationAction(SCNetworkInterfaceRef interface
)
6054 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6056 return interfacePrivate
->configurationAction
;
6061 _SCNetworkInterfaceGetHardwareAddress(SCNetworkInterfaceRef interface
)
6063 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6065 return interfacePrivate
->address
;
6070 _SCNetworkInterfaceGetIOInterfaceType(SCNetworkInterfaceRef interface
)
6072 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6074 return interfacePrivate
->type
;
6079 _SCNetworkInterfaceGetIOInterfaceUnit(SCNetworkInterfaceRef interface
)
6081 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6083 return interfacePrivate
->unit
;
6088 _SCNetworkInterfaceGetIOPath(SCNetworkInterfaceRef interface
)
6090 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6092 return interfacePrivate
->path
;
6097 _SCNetworkInterfaceGetIORegistryEntryID(SCNetworkInterfaceRef interface
)
6099 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6101 return interfacePrivate
->entryID
;
6106 _SCNetworkInterfaceIsBuiltin(SCNetworkInterfaceRef interface
)
6108 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6110 return interfacePrivate
->builtin
;
6115 #pragma mark SCNetworkInterface SPIs
6119 _SCNetworkInterfaceCopySlashDevPath(SCNetworkInterfaceRef interface
)
6121 io_registry_entry_t device
;
6122 io_iterator_t device_iterator
= MACH_PORT_NULL
;
6123 CFStringRef device_path
= NULL
;
6124 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6126 CFStringRef match_keys
[2];
6127 CFTypeRef match_vals
[2];
6128 CFDictionaryRef match_dict
;
6129 CFDictionaryRef matching
;
6131 if (interfacePrivate
->entity_device
== NULL
) {
6135 if (interfacePrivate
->entity_device_unique
== NULL
) {
6139 match_keys
[0] = CFSTR(kIOTTYBaseNameKey
);
6140 match_vals
[0] = interfacePrivate
->entity_device
;
6141 match_dict
= CFDictionaryCreate(NULL
,
6142 (const void **)match_keys
,
6143 (const void **)match_vals
,
6145 &kCFTypeDictionaryKeyCallBacks
,
6146 &kCFTypeDictionaryValueCallBacks
);
6148 match_keys
[0] = CFSTR(kIOProviderClassKey
);
6149 match_vals
[0] = CFSTR(kIOSerialBSDServiceValue
);
6150 match_keys
[1] = CFSTR(kIOPropertyMatchKey
);
6151 match_vals
[1] = match_dict
;
6152 matching
= CFDictionaryCreate(NULL
,
6153 (const void **)match_keys
,
6154 (const void **)match_vals
,
6155 sizeof(match_keys
)/sizeof(match_keys
[0]),
6156 &kCFTypeDictionaryKeyCallBacks
,
6157 &kCFTypeDictionaryValueCallBacks
);
6158 CFRelease(match_dict
);
6160 // note: this "matching" dictionary will be consumed by the call to IOServiceGetMatchingServices
6161 kr
= IOServiceGetMatchingServices(masterPort
, matching
, &device_iterator
);
6162 if (kr
!= kIOReturnSuccess
) {
6163 SCLog(TRUE
, LOG_DEBUG
, CFSTR("IOServiceGetMatchingServices() failed, kr = 0x%x"), kr
);
6167 while ((device_path
== NULL
) &&
6168 ((device
= IOIteratorNext(device_iterator
)) != MACH_PORT_NULL
)) {
6169 CFDictionaryRef overrides
;
6171 overrides
= IORegistryEntrySearchCFProperty(device
,
6173 kSCNetworkInterfaceNetworkConfigurationOverridesKey
,
6175 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
6176 if (overrides
!= NULL
) {
6177 CFDictionaryRef modemOverrides
;
6179 modemOverrides
= CFDictionaryGetValue(overrides
, kSCEntNetModem
);
6180 if (modemOverrides
!= NULL
) {
6181 CFRetain(modemOverrides
);
6183 CFRelease(overrides
);
6184 overrides
= modemOverrides
;
6186 if (overrides
== NULL
) {
6187 overrides
= IORegistryEntrySearchCFProperty(device
,
6189 CFSTR("DeviceModemOverrides"),
6191 kIORegistryIterateRecursively
| kIORegistryIterateParents
);
6193 if (overrides
!= NULL
) {
6194 if (isA_CFDictionary(overrides
)) {
6195 CFStringRef matchIdentifier
;
6197 matchIdentifier
= CFDictionaryGetValue(overrides
, CFSTR("UniqueIdentifier"));
6198 if (isA_CFString(matchIdentifier
) &&
6199 CFEqual(interfacePrivate
->entity_device_unique
, matchIdentifier
)) {
6200 device_path
= IORegistryEntryCreateCFProperty(device
,
6201 CFSTR(kIOTTYDeviceKey
),
6206 CFRelease(overrides
);
6208 IOObjectRelease(device
);
6211 IOObjectRelease(device_iterator
);
6215 if (device_path
== NULL
) {
6216 // if we haven't found an exact match to our UniqueIdentifier
6217 // so we simply return the base name.
6218 device_path
= SCNetworkInterfaceGetBSDName(interface
);
6219 if (device_path
!= NULL
) {
6220 CFRetain(device_path
);
6229 _SCNetworkInterfaceIsBluetoothPAN(SCNetworkInterfaceRef interface
)
6231 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6233 return (interfacePrivate
->sort_order
== kSortBluetoothPAN_GN
);
6238 _SCNetworkInterfaceIsBluetoothPAN_NAP(SCNetworkInterfaceRef interface
)
6240 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6242 return (interfacePrivate
->sort_order
== kSortBluetoothPAN_NAP
);
6247 _SCNetworkInterfaceIsBluetoothP2P(SCNetworkInterfaceRef interface
)
6249 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6251 return (interfacePrivate
->sort_order
== kSortBluetoothPAN_U
);
6256 _SCNetworkInterfaceIsHiddenConfiguration(SCNetworkInterfaceRef interface
)
6258 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6260 return interfacePrivate
->hidden
;
6265 _SCNetworkInterfaceIsModemV92(SCNetworkInterfaceRef interface
)
6267 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6269 return interfacePrivate
->modemIsV92
;
6274 _SCNetworkInterfaceIsTethered(SCNetworkInterfaceRef interface
)
6276 SCNetworkInterfacePrivateRef interfacePrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6278 return (interfacePrivate
->sort_order
== kSortTethered
);
6283 #pragma mark SCNetworkInterface [internal] SPIs
6287 SCNetworkInterfacePrivateRef
6288 __SCNetworkInterfaceCreateCopy(CFAllocatorRef allocator
,
6289 SCNetworkInterfaceRef interface
,
6290 SCPreferencesRef prefs
,
6291 CFStringRef serviceID
)
6293 SCNetworkInterfacePrivateRef oldPrivate
= (SCNetworkInterfacePrivateRef
)interface
;
6294 SCNetworkInterfacePrivateRef newPrivate
;
6296 /* initialize runtime (and kSCNetworkInterfaceIPv4) */
6297 pthread_once(&initialized
, __SCNetworkInterfaceInitialize
);
6299 if (interface
== kSCNetworkInterfaceIPv4
) {
6300 return (SCNetworkInterfacePrivateRef
)CFRetain(interface
);
6303 newPrivate
= __SCNetworkInterfaceCreatePrivate(NULL
, NULL
, prefs
, serviceID
);
6304 newPrivate
->interface_type
= oldPrivate
->interface_type
;
6305 if (oldPrivate
->interface
!= NULL
) {
6306 newPrivate
->interface
= (SCNetworkInterfaceRef
)__SCNetworkInterfaceCreateCopy(NULL
, // allocator
6307 oldPrivate
->interface
, // interface
6308 prefs
, // [new] prefs
6309 serviceID
); // [new] serviceID
6311 if (oldPrivate
->name
!= NULL
) {
6312 newPrivate
->name
= CFRetain(oldPrivate
->name
);
6314 if (oldPrivate
->localized_name
!= NULL
) {
6315 newPrivate
->localized_name
= CFRetain(oldPrivate
->localized_name
);
6317 newPrivate
->localized_key
= oldPrivate
->localized_key
;
6318 if (oldPrivate
->localized_arg1
!= NULL
) {
6319 newPrivate
->localized_arg1
= CFRetain(oldPrivate
->localized_arg1
);
6321 if (oldPrivate
->localized_arg2
!= NULL
) {
6322 newPrivate
->localized_arg2
= CFRetain(oldPrivate
->localized_arg2
);
6324 if (oldPrivate
->unsaved
!= NULL
) {
6325 newPrivate
->unsaved
= CFDictionaryCreateMutableCopy(NULL
, 0, oldPrivate
->unsaved
);
6327 if (oldPrivate
->entity_device
!= NULL
) {
6328 newPrivate
->entity_device
= CFRetain(oldPrivate
->entity_device
);
6330 if (oldPrivate
->entity_device_unique
!= NULL
) {
6331 newPrivate
->entity_device_unique
= CFRetain(oldPrivate
->entity_device_unique
);
6333 newPrivate
->entity_type
= oldPrivate
->entity_type
;
6334 newPrivate
->entity_subtype
= oldPrivate
->entity_subtype
;
6335 if (oldPrivate
->supported_interface_types
!= NULL
) {
6336 newPrivate
->supported_interface_types
= CFArrayCreateMutableCopy(NULL
, 0, oldPrivate
->supported_interface_types
);
6338 if (oldPrivate
->supported_protocol_types
!= NULL
) {
6339 newPrivate
->supported_protocol_types
= CFArrayCreateMutableCopy(NULL
, 0, oldPrivate
->supported_protocol_types
);
6341 if (oldPrivate
->address
!= NULL
) {
6342 newPrivate
->address
= CFRetain(oldPrivate
->address
);
6344 newPrivate
->builtin
= oldPrivate
->builtin
;
6345 if (oldPrivate
->configurationAction
!= NULL
) {
6346 newPrivate
->configurationAction
= CFRetain(oldPrivate
->configurationAction
);
6348 newPrivate
->hidden
= oldPrivate
->hidden
;
6349 if (oldPrivate
->location
!= NULL
) {
6350 newPrivate
->location
= CFRetain(oldPrivate
->location
);
6352 if (oldPrivate
->path
!= NULL
) {
6353 newPrivate
->path
= CFRetain(oldPrivate
->path
);
6355 newPrivate
->entryID
= oldPrivate
->entryID
;
6356 if (oldPrivate
->overrides
!= NULL
) {
6357 newPrivate
->overrides
= CFDictionaryCreateMutableCopy(NULL
, 0, oldPrivate
->overrides
);
6359 newPrivate
->modemIsV92
= oldPrivate
->modemIsV92
;
6360 if (oldPrivate
->type
!= NULL
) {
6361 newPrivate
->type
= CFRetain(oldPrivate
->type
);
6363 if (oldPrivate
->unit
!= NULL
) {
6364 newPrivate
->unit
= CFRetain(oldPrivate
->unit
);
6366 if (oldPrivate
->usb
.name
!= NULL
) {
6367 newPrivate
->usb
.name
= CFRetain(oldPrivate
->usb
.name
);
6369 if (oldPrivate
->usb
.vid
!= NULL
) {
6370 newPrivate
->usb
.vid
= CFRetain(oldPrivate
->usb
.vid
);
6372 if (oldPrivate
->usb
.pid
!= NULL
) {
6373 newPrivate
->usb
.pid
= CFRetain(oldPrivate
->usb
.pid
);
6375 newPrivate
->sort_order
= oldPrivate
->sort_order
;
6377 newPrivate
->supportsBond
= oldPrivate
->supportsBond
;
6378 if (oldPrivate
->bond
.interfaces
!= NULL
) {
6379 newPrivate
->bond
.interfaces
= CFRetain(oldPrivate
->bond
.interfaces
);
6381 if (oldPrivate
->bond
.mode
!= NULL
) {
6382 newPrivate
->bond
.mode
= CFRetain(oldPrivate
->bond
.mode
);
6384 if (oldPrivate
->bond
.options
!= NULL
) {
6385 newPrivate
->bond
.options
= CFRetain(oldPrivate
->bond
.options
);
6388 newPrivate
->supportsBridge
= oldPrivate
->supportsBridge
;
6389 if (oldPrivate
->bridge
.interfaces
!= NULL
) {
6390 newPrivate
->bridge
.interfaces
= CFRetain(oldPrivate
->bridge
.interfaces
);
6392 if (oldPrivate
->bridge
.options
!= NULL
) {
6393 newPrivate
->bridge
.options
= CFRetain(oldPrivate
->bridge
.options
);
6396 newPrivate
->supportsVLAN
= oldPrivate
->supportsVLAN
;
6397 if (oldPrivate
->vlan
.interface
!= NULL
) {
6398 newPrivate
->vlan
.interface
= CFRetain(oldPrivate
->vlan
.interface
);
6400 if (oldPrivate
->vlan
.tag
!= NULL
) {
6401 newPrivate
->vlan
.tag
= CFRetain(oldPrivate
->vlan
.tag
);
6403 if (oldPrivate
->vlan
.options
!= NULL
) {
6404 newPrivate
->vlan
.options
= CFRetain(oldPrivate
->vlan
.options
);
6413 __SCNetworkInterfaceCopyDeepConfiguration(SCNetworkSetRef set
, SCNetworkInterfaceRef interface
)
6415 CFMutableArrayRef configs
;
6417 configs
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
6419 while (interface
!= NULL
) {
6420 CFStringRef defaultType
;
6421 CFMutableDictionaryRef interfaceConfiguration
;
6423 interfaceConfiguration
= CFDictionaryCreateMutable(NULL
,
6425 &kCFTypeDictionaryKeyCallBacks
,
6426 &kCFTypeDictionaryValueCallBacks
);
6428 defaultType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
6429 if (defaultType
!= NULL
) {
6430 CFDictionaryRef config
;
6431 CFArrayRef extendedTypes
;
6434 config
= __SCNetworkInterfaceGetConfiguration(interface
, defaultType
);
6436 config
= __SCNetworkInterfaceGetDefaultConfiguration(set
, interface
);
6438 if (config
== NULL
) {
6439 config
= (CFDictionaryRef
)kCFNull
;
6441 CFDictionarySetValue(interfaceConfiguration
, defaultType
, config
);
6443 extendedTypes
= extendedConfigurationTypes(interface
);
6444 if (extendedTypes
!= NULL
) {
6448 n
= CFArrayGetCount(extendedTypes
);
6449 for (i
= 0; i
< n
; i
++) {
6450 CFStringRef extendedType
;
6452 extendedType
= CFArrayGetValueAtIndex(extendedTypes
, i
);
6453 config
= __SCNetworkInterfaceGetConfiguration(interface
, extendedType
);
6454 if (config
== NULL
) {
6455 config
= (CFDictionaryRef
)kCFNull
;
6457 CFDictionarySetValue(interfaceConfiguration
, extendedType
, config
);
6460 CFRelease(extendedTypes
);
6464 CFArrayAppendValue(configs
, interfaceConfiguration
);
6465 CFRelease(interfaceConfiguration
);
6467 interface
= SCNetworkInterfaceGetInterface(interface
);
6474 __private_extern__ Boolean
6475 __SCNetworkInterfaceIsMember(SCPreferencesRef prefs
, SCNetworkInterfaceRef interface
)
6477 CFArrayRef interfaces
;
6478 Boolean match
= FALSE
;
6479 CFMutableSetRef members
;
6481 members
= CFSetCreateMutable(NULL
, 0, &kCFTypeSetCallBacks
);
6483 #if !TARGET_OS_IPHONE
6484 // add Bond [member] interfaces
6485 interfaces
= SCBondInterfaceCopyAll(prefs
);
6486 if (interfaces
!= NULL
) {
6487 __SCBondInterfaceListCollectMembers(interfaces
, members
);
6488 CFRelease(interfaces
);
6490 #endif // !TARGET_OS_IPHONE
6492 // add Bridge [member] interfaces
6493 interfaces
= SCBridgeInterfaceCopyAll(prefs
);
6494 if (interfaces
!= NULL
) {
6495 __SCBridgeInterfaceListCollectMembers(interfaces
, members
);
6496 CFRelease(interfaces
);
6499 if (CFSetGetCount(members
) == 0) {
6503 while (interface
!= NULL
) {
6504 match
= CFSetContainsValue(members
, interface
);
6506 // if the interface is a member of an
6507 // Ethernet Bond or Bridge
6511 interface
= SCNetworkInterfaceGetInterface(interface
);
6523 __SCNetworkInterfaceSetDeepConfiguration(SCNetworkSetRef set
, SCNetworkInterfaceRef interface
, CFArrayRef configs
)
6527 for (i
= 0; interface
!= NULL
; i
++) {
6528 CFStringRef defaultType
;
6529 CFDictionaryRef interfaceConfiguration
;
6531 interfaceConfiguration
= (configs
!= NULL
) ? CFArrayGetValueAtIndex(configs
, i
) : NULL
;
6533 defaultType
= __SCNetworkInterfaceGetDefaultConfigurationType(interface
);
6534 if (defaultType
!= NULL
) {
6535 CFDictionaryRef config
;
6536 CFArrayRef extendedTypes
;
6538 config
= (interfaceConfiguration
!= NULL
) ? CFDictionaryGetValue(interfaceConfiguration
, defaultType
)
6540 if (config
== (CFDictionaryRef
)kCFNull
) {
6544 // if service is not associated with the set
6545 if (!__SCNetworkInterfaceSetConfiguration(interface
, defaultType
, config
, TRUE
)) {
6546 SCLog(TRUE
, LOG_DEBUG
,
6547 CFSTR("__SCNetworkInterfaceSetDeepConfiguration __SCNetworkInterfaceSetConfiguration() failed, interface=%@, type=%@"),
6552 // apply default configuration to this set
6553 if (!__SCNetworkInterfaceSetDefaultConfiguration(set
, interface
, defaultType
, config
, TRUE
)) {
6554 SCLog(TRUE
, LOG_DEBUG
,
6555 CFSTR("__SCNetworkInterfaceSetDeepConfiguration __SCNetworkInterfaceSetDefaultConfiguration() failed, interface=%@, type=%@"),
6561 extendedTypes
= extendedConfigurationTypes(interface
);
6562 if (extendedTypes
!= NULL
) {
6566 n
= CFArrayGetCount(extendedTypes
);
6567 for (j
= 0; j
< n
; j
++) {
6568 CFStringRef extendedType
;
6570 extendedType
= CFArrayGetValueAtIndex(extendedTypes
, j
);
6571 config
= (interfaceConfiguration
!= NULL
) ? CFDictionaryGetValue(interfaceConfiguration
, extendedType
)
6573 if (config
== (CFDictionaryRef
)kCFNull
) {
6576 if (!__SCNetworkInterfaceSetConfiguration(interface
, extendedType
, config
, TRUE
)) {
6577 SCLog(TRUE
, LOG_DEBUG
,
6578 CFSTR("__SCNetworkInterfaceSetDeepConfiguration __SCNetworkInterfaceSetConfiguration() failed, interface=%@, type=%@"),
6584 CFRelease(extendedTypes
);
6588 interface
= SCNetworkInterfaceGetInterface(interface
);
6595 SCNetworkInterfaceRef
6596 _SCNetworkInterfaceCopyActive(SCDynamicStoreRef store
, CFStringRef bsdName
)
6598 SCNetworkInterfaceRef interface
;
6600 interface
= _SCNetworkInterfaceCreateWithBSDName(NULL
, bsdName
, kIncludeAllVirtualInterfaces
);
6601 if (interface
== NULL
) {
6605 if (store
!= NULL
) {
6606 SCNetworkInterfacePrivateRef interfacePrivate
=
6607 (SCNetworkInterfacePrivateRef
)interface
;
6610 interfacePrivate
->store
= store
;
6617 SCNetworkServicePrimaryRank
6618 SCNetworkInterfaceGetPrimaryRank(SCNetworkInterfaceRef interface
)
6620 CFDictionaryRef entity
;
6621 SCNetworkInterfacePrivateRef interfacePrivate
=
6622 (SCNetworkInterfacePrivateRef
)interface
;
6626 SCNetworkServicePrimaryRank rank
= kSCNetworkServicePrimaryRankDefault
;
6627 SCDynamicStoreRef session
;
6629 ifName
= SCNetworkInterfaceGetBSDName(interface
);
6630 if ((ifName
== NULL
) || (interfacePrivate
->store
== NULL
)) {
6631 _SCErrorSet(kSCStatusInvalidArgument
);
6635 session
= interfacePrivate
->store
;
6637 path
= SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL
,
6638 kSCDynamicStoreDomainState
,
6641 entity
= SCDynamicStoreCopyValue(session
, path
);
6644 if (entity
!= NULL
) {
6645 if (isA_CFDictionary(entity
)) {
6646 CFStringRef rankStr
=
6647 CFDictionaryGetValue(entity
, kSCPropNetServicePrimaryRank
);
6648 ok
= __str_to_rank(rankStr
, &rank
);
6654 rank
= kSCNetworkServicePrimaryRankDefault
;
6655 _SCErrorSet(kSCStatusInvalidArgument
);
6656 } else if (rank
== kSCNetworkServicePrimaryRankDefault
) {
6657 _SCErrorSet(kSCStatusOK
);
6664 SCNetworkInterfaceSetPrimaryRank(SCNetworkInterfaceRef interface
,
6665 SCNetworkServicePrimaryRank newRank
)
6667 CFDictionaryRef entity
;
6668 SCNetworkInterfacePrivateRef interfacePrivate
=
6669 (SCNetworkInterfacePrivateRef
)interface
;
6671 CFMutableDictionaryRef newEntity
;
6673 CFStringRef path
= NULL
;
6674 CFStringRef rankStr
;
6675 SCDynamicStoreRef session
;
6677 ifName
= SCNetworkInterfaceGetBSDName(interface
);
6678 if ((ifName
== NULL
) || (interfacePrivate
->store
== NULL
)) {
6679 _SCErrorSet(kSCStatusInvalidArgument
);
6683 session
= interfacePrivate
->store
;
6685 ok
= __rank_to_str(newRank
, &rankStr
);
6687 _SCErrorSet(kSCStatusInvalidArgument
);
6691 path
= SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL
,
6692 kSCDynamicStoreDomainState
,
6696 entity
= SCDynamicStoreCopyValue(session
, path
);
6697 if (entity
!= NULL
) {
6698 if (!isA_CFDictionary(entity
)) {
6700 _SCErrorSet(kSCStatusFailed
);
6703 newEntity
= CFDictionaryCreateMutableCopy(NULL
, 0, entity
);
6706 newEntity
= CFDictionaryCreateMutable(NULL
,
6708 &kCFTypeDictionaryKeyCallBacks
,
6709 &kCFTypeDictionaryValueCallBacks
);
6712 if (rankStr
!= NULL
) {
6713 CFDictionarySetValue(newEntity
, kSCPropNetServicePrimaryRank
, rankStr
);
6715 CFDictionaryRemoveValue(newEntity
, kSCPropNetServicePrimaryRank
);
6718 if (CFDictionaryGetCount(newEntity
) > 0) {
6719 ok
= SCDynamicStoreSetValue(session
, path
, newEntity
);
6721 ok
= SCDynamicStoreRemoveValue(session
, path
);
6724 CFRelease(newEntity
);
6728 if (path
!= NULL
) CFRelease(path
);