1/* 2 * Copyright (c) 2004-2014 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#ifndef _SCNETWORKCONFIGURATIONINTERNAL_H 25#define _SCNETWORKCONFIGURATIONINTERNAL_H 26 27 28#include <TargetConditionals.h> 29#include <CoreFoundation/CoreFoundation.h> 30#include <CoreFoundation/CFRuntime.h> 31#include <SystemConfiguration/SystemConfiguration.h> 32#include <SystemConfiguration/SCPreferencesPathKey.h> 33#include <SystemConfiguration/SCNetworkConfigurationPrivate.h> 34#include <IOKit/IOKitLib.h> 35 36#if !TARGET_IPHONE_SIMULATOR 37#include "IPMonitorControl.h" 38#endif // !TARGET_IPHONE_SIMULATOR 39 40 41typedef struct { 42 43 // base CFType information 44 CFRuntimeBase cfBase; 45 46 // set id 47 CFStringRef setID; 48 49 // prefs 50 SCPreferencesRef prefs; 51 52 // name 53 CFStringRef name; 54 55 // misc 56 Boolean established; 57 58} SCNetworkSetPrivate, *SCNetworkSetPrivateRef; 59 60 61typedef struct { 62 63 // base CFType information 64 CFRuntimeBase cfBase; 65 66 // service id 67 CFStringRef serviceID; 68 69 // interface 70 SCNetworkInterfaceRef interface; 71 72 // prefs 73 SCPreferencesRef prefs; 74 75 // store (for live SCNetworkService) 76 SCDynamicStoreRef store; 77 78 // name 79 CFStringRef name; 80 81 // external identifiers 82 CFMutableDictionaryRef externalIDs; 83 84} SCNetworkServicePrivate, *SCNetworkServicePrivateRef; 85 86 87typedef struct { 88 89 // base CFType information 90 CFRuntimeBase cfBase; 91 92 // entity id 93 CFStringRef entityID; 94 95 // service 96 SCNetworkServiceRef service; 97 98} SCNetworkProtocolPrivate, *SCNetworkProtocolPrivateRef; 99 100 101typedef struct { 102 103 // base CFType information 104 CFRuntimeBase cfBase; 105 106 // interface information 107 CFStringRef interface_type; // interface type 108 109 Boolean active; 110 111 // [non-localized] name 112 CFStringRef name; // non-localized [display] name 113 114 // localized name 115 CFStringRef localized_name; // localized [display] name 116 CFStringRef localized_key; 117 CFStringRef localized_arg1; 118 CFStringRef localized_arg2; 119 120 // [layered] interface 121 SCNetworkInterfaceRef interface; 122 123 // prefs (for associated service, BOND interfaces, and VLAN interfaces) 124 SCPreferencesRef prefs; 125 126 // SCDynamicStore 127 SCDynamicStoreRef store; 128 129 // serviceID (NULL if not associated with a service) 130 CFStringRef serviceID; 131 132 // unsaved configuration (when prefs not [yet] available) 133 CFMutableDictionaryRef unsaved; 134 135 // [SCPreferences] interface entity information 136 CFStringRef entity_device; // interface device 137 CFStringRef entity_device_unique; // ... UniqueIdentifier 138 CFStringRef entity_type; // interface type 139 CFStringRef entity_subtype; // interface subtype 140 141 // configuration information 142 CFMutableArrayRef supported_interface_types; 143 CFMutableArrayRef supported_protocol_types; 144 145 // IORegistry (service plane) information 146 CFDataRef address; 147 CFStringRef addressString; 148 Boolean builtin; 149 CFStringRef configurationAction; 150 Boolean hidden; 151 CFStringRef location; 152 CFStringRef path; 153 uint64_t entryID; 154 CFMutableDictionaryRef overrides; 155 Boolean modemIsV92; 156 CFStringRef prefix; 157 CFNumberRef type; 158 CFNumberRef unit; 159 struct { 160 CFStringRef name; 161 CFNumberRef vid; 162 CFNumberRef pid; 163 } usb; 164 165 // misc 166 int sort_order; // sort order for this interface 167 168 // for BOND interfaces 169 Boolean supportsBond; 170 struct { 171 CFArrayRef interfaces; 172 CFNumberRef mode; 173 CFDictionaryRef options; 174 } bond; 175 176 // for Bridge interfaces 177 Boolean supportsBridge; 178 struct { 179 CFArrayRef interfaces; 180 CFDictionaryRef options; 181 } bridge; 182 183 // for VLAN interfaces 184 Boolean supportsVLAN; 185 struct { 186 SCNetworkInterfaceRef interface; 187 CFNumberRef tag; // e.g. 1 <= tag <= 4094 188 CFDictionaryRef options; 189 } vlan; 190 191#if !TARGET_IPHONE_SIMULATOR 192 // for interface rank assertions 193 IPMonitorControlRef IPMonitorControl; 194#endif // !TARGET_IPHONE_SIMULATOR 195} SCNetworkInterfacePrivate, *SCNetworkInterfacePrivateRef; 196 197 198__BEGIN_DECLS 199 200 201#pragma mark - 202#pragma mark SCNetworkInterface configuration (internal) 203 204Boolean 205__SCNetworkInterfaceMatchesName (CFStringRef name, CFStringRef key); 206 207CFArrayRef 208__SCNetworkInterfaceCopyAll_IONetworkInterface (void); 209 210/*! 211 @function __SCNetworkInterfaceCopyStorageEntity 212 @discussion Create interface entity of network interface as seen in 213 NetworkInterfaces.plist 214 @param interface The network interface from which interface entity is create 215 @result Dictionary which contains information about interface entity 216 You must release the returned value. 217 */ 218CFDictionaryRef 219__SCNetworkInterfaceCopyStorageEntity (SCNetworkInterfaceRef interface); 220 221/*! 222 @function __SCNetworkInterfaceCopyStoredWithPreferences 223 @discussion Create an array of network interfaces, which is present in the preferences 224 in NetworkInteraces.plist 225 @param ni_prefs Preference for network interfaces 226 @result Array which contains SCNetworkInterfaceRef. 227 You must release the returned value. 228 */ 229 230CFArrayRef // SCNetworkInterfaceRef 231__SCNetworkInterfaceCopyStoredWithPreferences (SCPreferencesRef ni_prefs); 232 233SCNetworkInterfacePrivateRef 234__SCNetworkInterfaceCreateCopy (CFAllocatorRef allocator, 235 SCNetworkInterfaceRef interface, 236 SCPreferencesRef prefs, 237 CFStringRef serviceID); 238 239/*! 240 @function __SCNetworkInterfaceCreateMappingUsingBSDName 241 @discussion This function creates mapping of BSD name and network interface using 242 preferences which point to the NetworkInterfaces.plist file. 243 @param ni_prefs Preferences pointing to NetworkInterfaces.plist 244 @result BSD Mapping in a dictionary. 245 You must release the returned value. 246 */ 247CFDictionaryRef 248__SCNetworkInterfaceCreateMappingUsingBSDName(CFArrayRef interfaces); 249 250SCNetworkInterfaceRef 251__SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(CFAllocatorRef allocator, 252 SCPreferencesRef ni_prefs, 253 CFStringRef bsdName); 254 255SCNetworkInterfacePrivateRef 256__SCNetworkInterfaceCreatePrivate (CFAllocatorRef allocator, 257 SCNetworkInterfaceRef interface, 258 SCPreferencesRef prefs, 259 CFStringRef serviceID); 260 261SCNetworkInterfacePrivateRef 262_SCBondInterfaceCreatePrivate (CFAllocatorRef allocator, 263 CFStringRef bond_if); 264 265SCNetworkInterfacePrivateRef 266_SCBridgeInterfaceCreatePrivate (CFAllocatorRef allocator, 267 CFStringRef bridge_if); 268 269SCNetworkInterfacePrivateRef 270_SCVLANInterfaceCreatePrivate (CFAllocatorRef allocator, 271 CFStringRef vlan_if); 272 273CFDictionaryRef 274__SCNetworkInterfaceCopyInterfaceEntity (SCNetworkInterfaceRef interface); 275 276CFArrayRef 277__SCNetworkInterfaceCopyDeepConfiguration (SCNetworkSetRef set, 278 SCNetworkInterfaceRef interface); 279 280#if !TARGET_OS_IPHONE 281CFStringRef 282__SCNetworkInterfaceCopyXLocalizedDisplayName (SCNetworkInterfaceRef interface); 283 284CFStringRef 285__SCNetworkInterfaceCopyXNonLocalizedDisplayName(SCNetworkInterfaceRef interface); 286#endif // !TARGET_OS_IPHONE 287 288int 289__SCNetworkInterfaceCreateCapabilities (SCNetworkInterfaceRef interface, 290 int capability_base, 291 CFDictionaryRef capability_options); 292 293int 294__SCNetworkInterfaceCreateMediaOptions (SCNetworkInterfaceRef interface, 295 CFDictionaryRef media_options); 296 297CFStringRef 298__SCNetworkInterfaceGetDefaultConfigurationType (SCNetworkInterfaceRef interface); 299 300CFStringRef 301__SCNetworkInterfaceGetEntitySubType (SCNetworkInterfaceRef interface); 302 303CFStringRef 304__SCNetworkInterfaceGetEntityType (SCNetworkInterfaceRef interface); 305 306CFStringRef 307__SCNetworkInterfaceGetNonLocalizedDisplayName (SCNetworkInterfaceRef interface); 308 309void 310__SCNetworkInterfaceSetUserDefinedName(SCNetworkInterfaceRef interface, CFStringRef name); 311 312/*! 313 @function __SCNetworkInterfaceGetUserDefinedName 314 @discussion This function returns the user defined name of the interface if available 315 @param interface The network interface. 316 @result String containing the user defined name. 317 */ 318CFStringRef 319__SCNetworkInterfaceGetUserDefinedName(SCNetworkInterfaceRef interface); 320 321/*! 322 @function __SCNetworkInterfaceIsActive 323 @discussion Identifies if the configuration of network interface is active or not 324 @param interface The network interface 325 @result TRUE if the interface configuration is active. 326 */ 327Boolean 328__SCNetworkInterfaceIsActive (SCNetworkInterfaceRef interface); 329 330Boolean 331__SCNetworkInterfaceIsMember (SCPreferencesRef prefs, 332 SCNetworkInterfaceRef interface); 333 334Boolean 335__SCNetworkInterfaceIsValidExtendedConfigurationType 336 (SCNetworkInterfaceRef interface, 337 CFStringRef extendedType, 338 Boolean requirePerInterface); 339 340CFDictionaryRef 341__SCNetworkInterfaceGetTemplateOverrides (SCNetworkInterfaceRef interface, 342 CFStringRef overrideType); 343 344int 345__SCNetworkInterfaceOrder (SCNetworkInterfaceRef interface); 346 347/*! 348 @function __SCNetworkInterfaceSaveStoredWithPreferences 349 @discussion Saves the array of interfaces in the preferences passed in the function. The interfaces 350 which are already present in the prefs file are replaced. 351 @param prefs Preferences which contain the interfaces to be replaced. If NULL, then preferences on 352 the system are used. 353 @param interfacesToSave The new interfaces array which is to be stored in preferences. 354 @result TRUE if saving of the new interfaces was successful. 355 */ 356 357Boolean 358__SCNetworkInterfaceSaveStoredWithPreferences (SCPreferencesRef prefs, 359 CFArrayRef interfacesToSave); 360 361Boolean 362__SCNetworkInterfaceSetConfiguration (SCNetworkInterfaceRef interface, 363 CFStringRef extendedType, 364 CFDictionaryRef config, 365 Boolean okToHold); 366 367void 368__SCNetworkInterfaceSetDeepConfiguration (SCNetworkSetRef set, 369 SCNetworkInterfaceRef interface, 370 CFArrayRef configs); 371 372/*! 373 @function __SCNetworkInterfaceSetIOInterfaceUnity 374 @discussion Will allow the caller to set IO Interface Unit 375 @param interface The network interface 376 @param unit The new interface unit to set 377 378 */ 379void 380__SCNetworkInterfaceSetIOInterfaceUnit (SCNetworkInterfaceRef interface, 381 CFNumberRef unit); 382 383Boolean 384__SCNetworkInterfaceSupportsVLAN (CFStringRef bsd_if); 385 386void 387__SCBondInterfaceListCollectMembers (CFArrayRef interfaces, 388 CFMutableSetRef set); 389 390Boolean 391__SCBondInterfaceSetMemberInterfaces (SCBondInterfaceRef bond, 392 CFArrayRef members); 393 394void 395__SCBridgeInterfaceListCollectMembers (CFArrayRef interfaces, 396 CFMutableSetRef set); 397 398Boolean 399__SCBridgeInterfaceSetMemberInterfaces (SCBridgeInterfaceRef bridge, 400 CFArrayRef members); 401 402#pragma mark - 403#pragma mark SCNetworkProtocol configuration (internal) 404 405 406SCNetworkProtocolPrivateRef 407__SCNetworkProtocolCreatePrivate (CFAllocatorRef allocator, 408 CFStringRef entityID, 409 SCNetworkServiceRef service); 410 411Boolean 412__SCNetworkProtocolIsValidType (CFStringRef protocolType); 413 414 415#pragma mark - 416#pragma mark SCNetworkService configuration (internal) 417 418 419CFArrayRef /* of SCNetworkServiceRef's */ 420__SCNetworkServiceCopyAllEnabled (SCPreferencesRef prefs); 421 422CFArrayRef /* of SCNetworkInterfaceRef's */ 423__SCNetworkServiceCopyAllInterfaces (SCPreferencesRef prefs); 424 425SCNetworkServicePrivateRef 426__SCNetworkServiceCreatePrivate (CFAllocatorRef allocator, 427 SCPreferencesRef prefs, 428 CFStringRef serviceID, 429 SCNetworkInterfaceRef interface); 430 431Boolean 432__SCNetworkServiceExistsForInterface (CFArrayRef services, 433 SCNetworkInterfaceRef interface); 434 435Boolean 436__SCNetworkServiceCreate (SCPreferencesRef prefs, 437 SCNetworkInterfaceRef interface, 438 CFStringRef userDefinedName); 439 440SCPreferencesRef 441__SCNetworkCreateDefaultNIPrefs (CFStringRef prefsID); 442 443/*! 444 @function __SCNetworkServiceMigrateNew 445 @discussion Adds network service to SCPreferencesRef if it doesn't exists 446 @param prefs SCPreferencesRef 447 @param service The network service 448 @param bsdMapping Mapping of interface names between configurations 449 @result TRUE if add service to prefs is successful 450 */ 451Boolean 452__SCNetworkServiceMigrateNew (SCPreferencesRef prefs, 453 SCNetworkServiceRef service, 454 CFDictionaryRef bsdMapping, 455 CFDictionaryRef setMapping, 456 CFDictionaryRef serviceSetMapping); 457 458#pragma mark - 459#pragma mark SCNetworkSet configuration (internal) 460 461 462#pragma mark - 463#pragma mark Miscellaneous (internal) 464 465 466CFDictionaryRef 467__copyInterfaceTemplate (CFStringRef interfaceType, 468 CFStringRef childInterfaceType); 469 470CFDictionaryRef 471__copyProtocolTemplate (CFStringRef interfaceType, 472 CFStringRef childInterfaceType, 473 CFStringRef protocolType); 474 475CFDictionaryRef 476__getPrefsConfiguration (SCPreferencesRef prefs, 477 CFStringRef path); 478 479Boolean 480__setPrefsConfiguration (SCPreferencesRef prefs, 481 CFStringRef path, 482 CFDictionaryRef config, 483 Boolean keepInactive); 484 485Boolean 486__getPrefsEnabled (SCPreferencesRef prefs, 487 CFStringRef path); 488 489Boolean 490__setPrefsEnabled (SCPreferencesRef prefs, 491 CFStringRef path, 492 Boolean enabled); 493 494Boolean 495__createInterface (int s, 496 CFStringRef interface); 497 498Boolean 499__destroyInterface (int s, 500 CFStringRef interface); 501 502CFStringRef 503__SCPreferencesPathCreateUniqueChild_WithMoreSCFCompatibility 504 (SCPreferencesRef prefs, 505 CFStringRef prefix); 506 507Boolean 508__extract_password (SCPreferencesRef prefs, 509 CFDictionaryRef config, 510 CFStringRef passwordKey, 511 CFStringRef encryptionKey, 512 CFStringRef encryptionKeyChainValue, 513 CFStringRef unique_id, 514 CFDataRef *password); 515 516Boolean 517__remove_password (SCPreferencesRef prefs, 518 CFDictionaryRef config, 519 CFStringRef passwordKey, 520 CFStringRef encryptionKey, 521 CFStringRef encryptionKeyChainValue, 522 CFStringRef unique_id, 523 CFDictionaryRef *newConfig); 524 525Boolean 526__rank_to_str (SCNetworkServicePrimaryRank rank, 527 CFStringRef *rankStr); 528 529Boolean 530__str_to_rank (CFStringRef rankStr, 531 SCNetworkServicePrimaryRank *rank); 532 533__END_DECLS 534 535#endif /* _SCNETWORKCONFIGURATIONINTERNAL_H */ 536