#include "SCNetworkConfiguration.h"
#include "SCNetworkConfigurationInternal.h"
+#include <string.h>
#include <mach/mach.h>
#include <net/if.h>
#include <net/if_types.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <pthread.h>
+#include <NSSystemDirectories.h>
static CFStringRef __SCNetworkInterfaceCopyDescription (CFTypeRef cf);
NULL, // service
NULL, // unsaved
NULL, // entity_device
- NULL, // entity_hardware
NULL, // entity_type
NULL, // entity_subtype
NULL, // supported_interface_types
FALSE, // builtin
NULL, // location
NULL, // path
- FALSE, // supportsDeviceOnHold
+ NULL, // modemCCL
+ FALSE, // modemIsV92
FALSE, // supportsBond
FALSE, // supportsVLAN
kSortUnknown // sort_order
static const struct {
const CFStringRef *interface_type;
+ const CFStringRef *entity_hardware;
Boolean per_interface_config;
uint32_t supported_interfaces;
const CFStringRef *ppp_subtype;
uint32_t supported_protocols;
} configurations[] = {
- // interface type if config? interface types PPP sub-type interface protocols
- // ===================================== ========== ======================= ======================================= =========================================
- { &kSCNetworkInterfaceType6to4 , FALSE, doNone, NULL, doIPv6 },
- { &kSCNetworkInterfaceTypeBluetooth , FALSE, doPPP, &kSCValNetInterfaceSubTypePPPSerial, doNone },
- { &kSCNetworkInterfaceTypeBond , TRUE, doNone, NULL, doAppleTalk|doDNS|doIPv4|doIPv6|doProxies },
- { &kSCNetworkInterfaceTypeEthernet , TRUE, doPPP, &kSCValNetInterfaceSubTypePPPoE, doAppleTalk|doDNS|doIPv4|doIPv6|doProxies },
- { &kSCNetworkInterfaceTypeFireWire , TRUE, doNone, NULL, doDNS|doIPv4|doIPv6|doProxies },
- { &kSCNetworkInterfaceTypeIEEE80211 , TRUE, doPPP, &kSCValNetInterfaceSubTypePPPoE, doAppleTalk|doDNS|doIPv4|doIPv6|doProxies },
- { &kSCNetworkInterfaceTypeIrDA , FALSE, doPPP, &kSCValNetInterfaceSubTypePPPSerial, doNone },
- { &kSCNetworkInterfaceTypeL2TP , FALSE, doPPP, &kSCValNetInterfaceSubTypeL2TP, doNone },
- { &kSCNetworkInterfaceTypeModem , FALSE, doPPP, &kSCValNetInterfaceSubTypePPPSerial, doNone },
- { &kSCNetworkInterfaceTypePPP , FALSE, doNone, NULL, doDNS|doIPv4|doIPv6|doProxies },
- { &kSCNetworkInterfaceTypePPTP , FALSE, doPPP, &kSCValNetInterfaceSubTypePPTP, doNone },
- { &kSCNetworkInterfaceTypeSerial , FALSE, doPPP, &kSCValNetInterfaceSubTypePPPSerial, doNone },
- { &kSCNetworkInterfaceTypeVLAN , TRUE, doNone, NULL, doAppleTalk|doDNS|doIPv4|doIPv6|doProxies },
- // ===================================== ========== ======================= ======================================= =========================================
- { &kSCNetworkInterfaceTypeIPv4 , FALSE, do6to4|doPPTP|doL2TP, NULL, doNone }
+ // interface type entity_hardware if config? interface types PPP sub-type interface protocols
+ // ===================================== ================= ========== ======================= ======================================= =========================================
+ { &kSCNetworkInterfaceType6to4 , &kSCEntNet6to4 , FALSE, doNone, NULL, doIPv6 },
+ { &kSCNetworkInterfaceTypeBluetooth , &kSCEntNetModem , FALSE, doPPP, &kSCValNetInterfaceSubTypePPPSerial, doNone },
+ { &kSCNetworkInterfaceTypeBond , &kSCEntNetEthernet, TRUE , doNone, NULL, doAppleTalk|doDNS|doIPv4|doIPv6|doProxies },
+ { &kSCNetworkInterfaceTypeEthernet , &kSCEntNetEthernet, TRUE , doPPP, &kSCValNetInterfaceSubTypePPPoE, doAppleTalk|doDNS|doIPv4|doIPv6|doProxies },
+ { &kSCNetworkInterfaceTypeFireWire , &kSCEntNetFireWire, TRUE , doNone, NULL, doDNS|doIPv4|doIPv6|doProxies },
+ { &kSCNetworkInterfaceTypeIEEE80211 , &kSCEntNetAirPort , TRUE , doPPP, &kSCValNetInterfaceSubTypePPPoE, doAppleTalk|doDNS|doIPv4|doIPv6|doProxies },
+ { &kSCNetworkInterfaceTypeIrDA , &kSCEntNetModem , FALSE, doPPP, &kSCValNetInterfaceSubTypePPPSerial, doNone },
+ { &kSCNetworkInterfaceTypeL2TP , NULL , FALSE, doPPP, &kSCValNetInterfaceSubTypeL2TP, doNone },
+ { &kSCNetworkInterfaceTypeModem , &kSCEntNetModem , FALSE, doPPP, &kSCValNetInterfaceSubTypePPPSerial, doNone },
+ { &kSCNetworkInterfaceTypePPP , &kSCEntNetPPP , FALSE, doNone, NULL, doDNS|doIPv4|doIPv6|doProxies },
+ { &kSCNetworkInterfaceTypePPTP , NULL , FALSE, doPPP, &kSCValNetInterfaceSubTypePPTP, doNone },
+ { &kSCNetworkInterfaceTypeSerial , &kSCEntNetModem , FALSE, doPPP, &kSCValNetInterfaceSubTypePPPSerial, doNone },
+ { &kSCNetworkInterfaceTypeVLAN , &kSCEntNetEthernet, TRUE , doNone, NULL, doAppleTalk|doDNS|doIPv4|doIPv6|doProxies },
+ // ===================================== ================= ========== ======================= ======================================= =========================================
+ { &kSCNetworkInterfaceTypeIPv4 , NULL , FALSE, do6to4|doL2TP|doPPTP, NULL, doNone }
};
SCNetworkInterfacePrivateRef interfacePrivate = (SCNetworkInterfacePrivateRef)cf;
result = CFStringCreateMutable(allocator, 0);
- CFStringAppendFormat(result, NULL, CFSTR("<SCNetworkInterface %p [%p]> { "), cf, allocator);
+ CFStringAppendFormat(result, NULL, CFSTR("<SCNetworkInterface %p [%p]> {"), cf, allocator);
CFStringAppendFormat(result, NULL, CFSTR("type = %@"), interfacePrivate->interface_type);
- CFStringAppendFormat(result, NULL, CFSTR(", entity = %@ / %@ / %@"),
- interfacePrivate->entity_device,
- interfacePrivate->entity_hardware,
- interfacePrivate->entity_type);
+ CFStringAppendFormat(result, NULL, CFSTR(", entity_device = %@"), interfacePrivate->entity_device);
+ CFStringAppendFormat(result, NULL, CFSTR(", entity_type = %@"), interfacePrivate->entity_type);
if (interfacePrivate->entity_subtype != NULL) {
CFStringAppendFormat(result, NULL, CFSTR(" / %@"), interfacePrivate->entity_subtype);
}
if (interfacePrivate->location != NULL) {
CFStringAppendFormat(result, NULL, CFSTR(", location = %@"), interfacePrivate->location);
}
- CFStringAppendFormat(result, NULL, CFSTR(", path = %@"), interfacePrivate->path);
+ if (interfacePrivate->path != NULL) {
+ CFStringAppendFormat(result, NULL, CFSTR(", path = %@"), interfacePrivate->path);
+ }
+ if (interfacePrivate->modemCCL != NULL) {
+ CFStringAppendFormat(result, NULL, CFSTR(", modemCCL = %@"), interfacePrivate->modemCCL);
+ }
CFStringAppendFormat(result, NULL, CFSTR(", order = %d"), interfacePrivate->sort_order);
-
if (interfacePrivate->service != NULL) {
CFStringAppendFormat(result, NULL, CFSTR(", service=%@"), interfacePrivate->service);
}
-
if (interfacePrivate->interface != NULL) {
CFStringAppendFormat(result, NULL, CFSTR(", interface=%@"), interfacePrivate->interface);
}
-
if (interfacePrivate->unsaved != NULL) {
CFStringAppendFormat(result, NULL, CFSTR(", unsaved=%@"), interfacePrivate->unsaved);
}
- CFStringAppendFormat(result, NULL, CFSTR(" }"));
+ CFStringAppendFormat(result, NULL, CFSTR("}"));
return result;
}
if (interfacePrivate->path != NULL)
CFRelease(interfacePrivate->path);
+ if (interfacePrivate->modemCCL != NULL)
+ CFRelease(interfacePrivate->modemCCL);
+
return;
}
interfacePrivate->service = service;
interfacePrivate->unsaved = NULL;
interfacePrivate->entity_device = NULL;
- interfacePrivate->entity_hardware = NULL;
interfacePrivate->entity_type = NULL;
interfacePrivate->entity_subtype = NULL;
interfacePrivate->supported_interface_types = NULL;
interfacePrivate->path = (path != NULL) ? CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8)
: NULL;
interfacePrivate->location = NULL;
- interfacePrivate->supportsDeviceOnHold = FALSE;
+ interfacePrivate->modemCCL = NULL;
+ interfacePrivate->modemIsV92 = FALSE;
interfacePrivate->supportsBond = FALSE;
interfacePrivate->supportsVLAN = FALSE;
interfacePrivate->sort_order = kSortUnknown;
pci_slot(io_registry_entry_t interface, CFTypeRef *pci_slot_name)
{
kern_return_t kr;
- io_registry_entry_t slot = interface;
+ io_registry_entry_t parent;
+ CFMutableStringRef slot;
+ CFTypeRef slot_name;
+ slot = NULL;
if (pci_slot_name != NULL) *pci_slot_name = NULL;
- while (slot != MACH_PORT_NULL) {
- io_registry_entry_t parent;
- CFTypeRef slot_name;
-
- slot_name = IORegistryEntryCreateCFProperty(slot, CFSTR("AAPL,slot-name"), NULL, 0);
- if (slot_name != NULL) {
- Boolean found;
-
- found = IOStringValueHasPrefix(slot_name, CFSTR("slot"));
- if (found) {
- CFIndex i;
- CFMutableStringRef name;
-
- // if we found a slot #
- name = CFStringCreateMutable(NULL, 0);
- if (isA_CFString(slot_name)) {
- if (pci_slot_name != NULL) *pci_slot_name = CFStringCreateCopy(NULL, slot_name);
- CFStringAppend(name, slot_name);
- } else if (isA_CFData(slot_name)) {
- if (pci_slot_name != NULL) *pci_slot_name = CFDataCreateCopy(NULL, slot_name);
- CFStringAppendCString(name,
- (const char *)CFDataGetBytePtr(slot_name),
- kCFStringEncodingUTF8);
- }
-
- (void) CFStringFindAndReplace(name,
- CFSTR("slot-"),
- CFSTR(""),
- CFRangeMake(0, 5),
- kCFCompareCaseInsensitive|kCFCompareAnchored);
- for (i = 0; i < sizeof(slot_mappings)/sizeof(slot_mappings[0]); i++) {
- if (CFStringCompareWithOptions(name,
- slot_mappings[i].name,
- CFRangeMake(0, CFStringGetLength(slot_mappings[i].name)),
- kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
- CFRelease(name);
- name = (CFMutableStringRef)CFRetain(slot_mappings[i].slot);
- break;
- }
- }
-
- CFRelease(slot_name);
- if (slot != interface) IOObjectRelease(slot);
- return name;
- }
+ slot_name = IORegistryEntryCreateCFProperty(interface, CFSTR("AAPL,slot-name"), NULL, 0);
+ if (slot_name != NULL) {
+ CFIndex i;
+
+ slot = CFStringCreateMutable(NULL, 0);
+ if (isA_CFString(slot_name)) {
+ if (pci_slot_name != NULL) *pci_slot_name = CFStringCreateCopy(NULL, slot_name);
+ CFStringAppend(slot, slot_name);
+ } else if (isA_CFData(slot_name)) {
+ if (pci_slot_name != NULL) *pci_slot_name = CFDataCreateCopy(NULL, slot_name);
+ CFStringAppendCString(slot,
+ (const char *)CFDataGetBytePtr(slot_name),
+ kCFStringEncodingUTF8);
+ }
- CFRelease(slot_name);
+ if (CFStringGetLength(slot) > 5) {
+ (void) CFStringFindAndReplace(slot,
+ CFSTR("slot-"),
+ CFSTR(""),
+ CFRangeMake(0, 5),
+ kCFCompareCaseInsensitive|kCFCompareAnchored);
}
- kr = IORegistryEntryGetParentEntry(slot, kIOServicePlane, &parent);
- if (slot != interface) IOObjectRelease(slot);
- switch (kr) {
- case kIOReturnSuccess :
- slot = parent;
+ for (i = 0; i < sizeof(slot_mappings)/sizeof(slot_mappings[0]); i++) {
+ if (CFStringCompare(slot,
+ slot_mappings[i].name,
+ kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
+ CFRelease(slot);
+ slot = (CFMutableStringRef)CFRetain(slot_mappings[i].slot);
break;
- case kIOReturnNoDevice :
- // if we have hit the root node without finding a slot #
- goto done;
- default :
- SCLog(TRUE, LOG_INFO, CFSTR("pci_slot IORegistryEntryGetParentEntry() failed, kr = 0x%x"), kr);
- goto done;
+ }
}
+
+ CFRelease(slot_name);
}
- done :
+ kr = IORegistryEntryGetParentEntry(interface, kIOServicePlane, &parent);
+ switch (kr) {
+ case kIOReturnSuccess : {
+ CFTypeRef parent_pci_slot_name = NULL;
+ CFStringRef parent_slot;
- return NULL;
+ parent_slot = pci_slot(parent, &parent_pci_slot_name);
+ if (parent_slot != NULL) {
+ if (slot != NULL) CFRelease(slot);
+ slot = (CFMutableStringRef)parent_slot;
+
+ if (pci_slot_name != NULL) {
+ if (*pci_slot_name != NULL) CFRelease(*pci_slot_name);
+ *pci_slot_name = parent_pci_slot_name;
+ } else {
+ CFRelease(parent_pci_slot_name);
+ }
+ }
+
+ IOObjectRelease(parent);
+ break;
+ }
+ case kIOReturnNoDevice :
+ // if we have hit the root node
+ break;
+ default :
+ SCLog(TRUE, LOG_DEBUG, CFSTR("pci_slot IORegistryEntryGetParentEntry() failed, kr = 0x%x"), kr);
+ break;
+ }
+
+ return slot;
}
kr = IOServiceGetMatchingServices(masterPort, matching, &slot_iterator);
if (kr != kIOReturnSuccess) {
- SCPrint(TRUE, stderr, CFSTR("IOServiceGetMatchingServices() failed, kr = 0x%x\n"), kr);
+ SCLog(TRUE, LOG_DEBUG, CFSTR("pci_port IOServiceGetMatchingServices() failed, kr = 0x%x"), kr);
return MACH_PORT_NULL;
}
kIORegistryIterateRecursively,
&child_iterator);
if (kr != kIOReturnSuccess) {
- SCPrint(TRUE, stderr, CFSTR("IORegistryEntryCreateIterator() failed, kr = 0x%x\n"), kr);
+ SCLog(TRUE, LOG_DEBUG, CFSTR("pci_port IORegistryEntryCreateIterator() failed, kr = 0x%x"), kr);
return MACH_PORT_NULL;
}
static Boolean
isBuiltIn(io_registry_entry_t interface)
{
- kern_return_t kr;
- io_registry_entry_t slot = interface;
-
- while (slot != MACH_PORT_NULL) {
- io_registry_entry_t parent;
- CFTypeRef slot_name;
-
- slot_name = IORegistryEntryCreateCFProperty(slot, CFSTR("AAPL,slot-name"), NULL, 0);
- if (slot_name != NULL) {
- Boolean found;
-
- found = IOStringValueHasPrefix(slot_name, CFSTR("slot"));
- CFRelease(slot_name);
+ CFStringRef slot;
- if (found) {
- // if we found a slot # then this is not a built-in interface
- if (slot != interface) IOObjectRelease(slot);
- return FALSE;
- }
- }
-
- kr = IORegistryEntryGetParentEntry(slot, kIOServicePlane, &parent);
- if (slot != interface) IOObjectRelease(slot);
- switch (kr) {
- case kIOReturnSuccess :
- slot = parent;
- break;
- case kIOReturnNoDevice :
- // if we have hit the root node without finding a slot #
- return TRUE;
- default :
- SCLog(TRUE, LOG_INFO, CFSTR("isBuiltIn IORegistryEntryGetParentEntry() failed, kr = 0x%x"), kr);
- return FALSE;
- }
+ slot = pci_slot(interface, NULL);
+ if (slot != NULL) {
+ // interfaces which have a "slot" are not built-in
+ CFRelease(slot);
+ return FALSE;
}
- return FALSE;
+ return TRUE;
}
CFDictionaryRef bus_dict)
{
CFBooleanRef bVal;
- io_name_t c_IOClass;
- io_name_t c_IOName;
- io_name_t i_IOClass;
int ift = -1;
int iVal;
CFNumberRef num;
CFStringRef str;
- // get the interface type
-
+ // interface type
num = CFDictionaryGetValue(interface_dict, CFSTR(kIOInterfaceType));
if (!isA_CFNumber(num) ||
!CFNumberGetValue(num, kCFNumberIntType, &ift)) {
case IFT_ETHER :
// Type, Hardware
- if (IOObjectGetClass(interface, i_IOClass) != KERN_SUCCESS) {
- i_IOClass[0] = '\0';
- }
- if (IOObjectGetClass(controller, c_IOClass) != KERN_SUCCESS) {
- c_IOClass[0] = '\0';
- }
- if (IORegistryEntryGetName(controller, c_IOName) != KERN_SUCCESS) {
- c_IOName[0] = '\0';
- }
-
- if ((strcmp(i_IOClass, "IO80211Interface" ) == 0) ||
- (strcmp(c_IOClass, "AirPortPCI" ) == 0) ||
- (strcmp(c_IOClass, "AirPortDriver" ) == 0) ||
- (strcmp(c_IOName , "AppleWireless80211") == 0)) {
+ if ((IOObjectConformsTo(controller, "IO80211Controller")) ||
+ (IOObjectConformsTo(controller, "AirPortPCI" )) ||
+ (IOObjectConformsTo(controller, "AirPortDriver" ))) {
interfacePrivate->interface_type = kSCNetworkInterfaceTypeIEEE80211;
interfacePrivate->entity_type = kSCEntNetEthernet;
- interfacePrivate->entity_hardware = kSCEntNetAirPort;
interfacePrivate->sort_order = kSortAirPort;
} else {
str = IODictionaryCopyCFStringValue(bus_dict, CFSTR("name"));
if ((str != NULL) && CFEqual(str, CFSTR("radio"))) {
interfacePrivate->interface_type = kSCNetworkInterfaceTypeEthernet; // ??
interfacePrivate->entity_type = kSCEntNetEthernet;
- interfacePrivate->entity_hardware = kSCEntNetEthernet; // ??
interfacePrivate->sort_order = kSortOtherWireless;
} else {
interfacePrivate->interface_type = kSCNetworkInterfaceTypeEthernet;
interfacePrivate->entity_type = kSCEntNetEthernet;
- interfacePrivate->entity_hardware = kSCEntNetEthernet;
interfacePrivate->sort_order = kSortEthernet;
// BOND support only enabled for ethernet devices
// Entity
interfacePrivate->entity_type = kSCEntNetFireWire;
- interfacePrivate->entity_hardware = kSCEntNetFireWire;
// built-in
interfacePrivate->builtin = isBuiltIn(interface);
break;
default :
- SCPrint(TRUE, stderr, CFSTR("Unknown interface type = %d\n"), ift);
+ SCLog(TRUE, LOG_DEBUG, CFSTR("processNetworkInterface() failed, unknown interface type = %d"), ift);
return FALSE;
}
// Modem
interfacePrivate->interface_type = kSCNetworkInterfaceTypeModem;
- // DeviceOnHold support
+ // V.92 support
val = IORegistryEntrySearchCFProperty(interface,
kIOServicePlane,
CFSTR(kIODeviceSupportsHoldKey),
NULL,
kIORegistryIterateRecursively | kIORegistryIterateParents);
if (val != NULL) {
- uint32_t supportsHold;
+ uint32_t v92;
if (isA_CFNumber(val) &&
- CFNumberGetValue(val, kCFNumberSInt32Type, &supportsHold)) {
- interfacePrivate->supportsDeviceOnHold = (supportsHold == 1);
+ CFNumberGetValue(val, kCFNumberSInt32Type, &v92)) {
+ interfacePrivate->modemIsV92 = (v92 == 1);
}
CFRelease(val);
}
if (CFEqual(ift, CFSTR(kIOSerialBSDModemType))) {
// if modem
isModem = TRUE;
- interfacePrivate->entity_hardware = kSCEntNetModem;
if (CFEqual(str, CFSTR("modem"))) {
interfacePrivate->builtin = TRUE;
}
} else if (CFEqual(ift, CFSTR(kIOSerialBSDRS232Type))) {
// if serial port
- interfacePrivate->entity_hardware = kSCEntNetModem;
interfacePrivate->sort_order = kSortSerialPort;
} else {
return FALSE;
// Entity (Device)
interfacePrivate->entity_device = IODictionaryCopyCFStringValue(interface_dict, CFSTR(kIOTTYDeviceKey));
+ // modem CCL
+ val = IORegistryEntrySearchCFProperty(interface,
+ kIOServicePlane,
+ CFSTR("ModemCCL"),
+ NULL,
+ kIORegistryIterateRecursively | kIORegistryIterateParents);
+ if (val != NULL) {
+ interfacePrivate->modemCCL = IOCopyCFStringValue(val);
+ CFRelease(val);
+ }
+
// localized name
if (CFEqual(interfacePrivate->interface_type, kSCNetworkInterfaceTypeIrDA)) {
interfacePrivate->localized_key = CFSTR("irda");
} else if (CFEqual(interfacePrivate->interface_type, kSCNetworkInterfaceTypeBluetooth)) {
interfacePrivate->localized_key = CFSTR("bluetooth");
} else {
- CFStringRef localized;
+ CFStringRef localized = NULL;
CFMutableStringRef port;
port = CFStringCreateMutableCopy(NULL, 0, str);
CFStringAppend(port, CFSTR("-port"));
}
- localized = CFBundleCopyLocalizedString(bundle,
- port,
- port,
- NETWORKINTERFACE_LOCALIZATIONS);
+ if (bundle != NULL) {
+ localized = CFBundleCopyLocalizedString(bundle,
+ port,
+ port,
+ NETWORKINTERFACE_LOCALIZATIONS);
+ }
if (localized != NULL) {
if (!CFEqual(port, localized)) {
// if localization available
// if we have a [somewhat reasonable?] product name
CFRelease(interfacePrivate->localized_name);
interfacePrivate->localized_name = CFRetain(productName);
+
+ // if not provided, also check if the product name
+ // matches a CCL script
+ if (interfacePrivate->modemCCL == NULL) {
+ interfacePrivate->modemCCL = CFRetain(productName);
+ }
}
+
CFRelease(productName);
}
}
CFRelease(port);
}
+ // validate the CCL script
+ if (interfacePrivate->modemCCL != NULL) {
+ char ccl[MAXPATHLEN];
+ char path[MAXPATHLEN];
+ NSSearchPathEnumerationState state;
+ Boolean valid = FALSE;
+
+ (void) _SC_cfstring_to_cstring(interfacePrivate->modemCCL,
+ ccl,
+ sizeof(ccl),
+ kCFStringEncodingUTF8);
+
+ state = NSStartSearchPathEnumeration(NSLibraryDirectory,
+ NSLocalDomainMask|NSSystemDomainMask);
+ while ((state = NSGetNextSearchPathEnumeration(state, path))) {
+ struct stat statBuf;
+
+ if (ccl[0] == '/') {
+ path[0] = '\0'; // if modemCCL is a full path
+ } else {
+ strlcat(path, "/Modem Scripts/", sizeof(path));
+ strlcat(path, ccl, sizeof(path));
+ }
+
+ if (stat(path, &statBuf) == 0) {
+ if (S_ISREG(statBuf.st_mode)) {
+ // if we have a valid CCL script
+ valid = TRUE;
+ break;
+ }
+ } else {
+ if (errno == ENOENT) {
+ continue;
+ }
+
+ SCLog(TRUE, LOG_DEBUG,
+ CFSTR("processSerialInterface stat() failed: %s"),
+ strerror(errno));
+ break;
+ }
+ }
+
+ if (!valid) {
+ // if the CCL script is not valid
+ CFRelease(interfacePrivate->modemCCL);
+ interfacePrivate->modemCCL = NULL;
+ }
+ }
+
return TRUE;
}
kr = IOServiceGetMatchingServices(masterPort, matching, &iterator);
if (kr != kIOReturnSuccess) {
- SCPrint(TRUE, stderr, CFSTR("IOServiceGetMatchingServices() failed, kr = 0x%x\n"), kr);
+ SCLog(TRUE, LOG_DEBUG, CFSTR("findMatchingInterfaces IOServiceGetMatchingServices() failed, kr = 0x%x"), kr);
return NULL;
}
interfacePrivate->interface_type = kSCNetworkInterfaceTypeBond;
interfacePrivate->entity_type = kSCEntNetEthernet;
- interfacePrivate->entity_hardware = kSCEntNetEthernet;
interfacePrivate->entity_device = CFStringCreateCopy(NULL, bond_if);
interfacePrivate->builtin = TRUE;
interfacePrivate->sort_order = kSortBond;
interfacePrivate->interface_type = kSCNetworkInterfaceTypeVLAN;
interfacePrivate->entity_type = kSCEntNetEthernet;
- interfacePrivate->entity_hardware = kSCEntNetEthernet;
interfacePrivate->entity_device = CFStringCreateCopy(NULL, vlan_if);
interfacePrivate->builtin = TRUE;
interfacePrivate->sort_order = kSortVLAN;
}
-/* ---------- interface from preferences ---------- */
+/* ---------- helper functions ---------- */
+
+
+static CFIndex
+findConfiguration(CFStringRef interface_type)
+{
+ CFIndex i;
+
+ for (i = 0; i < sizeof(configurations)/sizeof(configurations[0]); i++) {
+ if (CFEqual(interface_type, *configurations[i].interface_type)) {
+ return i;
+ }
+ }
+
+ return kCFNotFound;
+}
+
+
+static CFArrayRef
+copyConfigurationPaths(SCNetworkInterfacePrivateRef interfacePrivate)
+{
+ CFMutableArrayRef array = NULL;
+ CFIndex interfaceIndex;
+ CFStringRef path;
+ SCNetworkServicePrivateRef servicePrivate;
+
+ servicePrivate = (SCNetworkServicePrivateRef)interfacePrivate->service;
+ if (servicePrivate == NULL) {
+ // if not associated with a service (yet)
+ return NULL;
+ }
+
+ array = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
+
+ interfaceIndex = findConfiguration(interfacePrivate->interface_type);
+ if (interfaceIndex == kCFNotFound) {
+ // unknown interface type, use per-service configuration preferences
+ path = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL, // allocator
+ servicePrivate->serviceID, // service
+ interfacePrivate->interface_type); // entity
+ CFArrayAppendValue(array, path);
+ CFRelease(path);
+ goto done;
+ }
+
+ if (configurations[interfaceIndex].entity_hardware == NULL) {
+ // if no configuration information can be associated with this interface type
+ CFRelease(array);
+ array = NULL;
+ goto done;
+ }
+
+ if (configurations[interfaceIndex].per_interface_config) {
+ CFIndex i;
+ CFIndex n;
+ CFArrayRef sets;
+
+ // known interface type, per-interface configuration preferences
+ //
+ // 1. look for all sets which contain the associated service
+ // 2. add a per-set path for the interface configuration for
+ // each set.
+
+ sets = SCNetworkSetCopyAll(servicePrivate->prefs);
+ n = (sets != NULL) ? CFArrayGetCount(sets) : 0;
+
+ for (i = 0; i < n; i++) {
+ CFArrayRef services;
+ SCNetworkSetRef set;
+
+ set = CFArrayGetValueAtIndex(sets, i);
+ services = SCNetworkSetCopyServices(set);
+ if (CFArrayContainsValue(services,
+ CFRangeMake(0, CFArrayGetCount(services)),
+ interfacePrivate->service)) {
+ path = SCPreferencesPathKeyCreateSetNetworkInterfaceEntity(NULL, // allocator
+ SCNetworkSetGetSetID(set), // set
+ interfacePrivate->entity_device, // service
+ *configurations[interfaceIndex].entity_hardware); // entity
+ CFArrayAppendValue(array, path);
+ CFRelease(path);
+ }
+ CFRelease(services);
+ }
+
+ if (CFArrayGetCount(array) == 0) {
+ CFRelease(array);
+ array = NULL;
+ }
+
+ if (sets != NULL) CFRelease(sets);
+ } else {
+ // known interface type, per-service configuration preferences
+ path = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL, // allocator
+ servicePrivate->serviceID, // service
+ *configurations[interfaceIndex].entity_hardware); // entity
+ CFArrayAppendValue(array, path);
+ CFRelease(path);
+ }
+
+ done :
+
+ return array;
+}
+
+
+/* ---------- preferences entity for interface ---------- */
+
+
+__private_extern__ CFDictionaryRef
+__SCNetworkInterfaceCopyInterfaceEntity(SCNetworkInterfaceRef interface)
+{
+ CFMutableDictionaryRef entity;
+ CFIndex interfaceIndex;
+ SCNetworkInterfacePrivateRef interfacePrivate = (SCNetworkInterfacePrivateRef)interface;
+
+ entity = CFDictionaryCreateMutable(NULL,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ if (interfacePrivate->entity_type != NULL) {
+ CFDictionarySetValue(entity,
+ kSCPropNetInterfaceType,
+ interfacePrivate->entity_type);
+ }
+ if (interfacePrivate->entity_subtype != NULL) {
+ CFDictionarySetValue(entity,
+ kSCPropNetInterfaceSubType,
+ interfacePrivate->entity_subtype);
+ }
+ if (interfacePrivate->entity_device != NULL) {
+ CFDictionarySetValue(entity,
+ kSCPropNetInterfaceDeviceName,
+ interfacePrivate->entity_device);
+ }
+
+ // match the "hardware" with the lowest layer
+ while (TRUE) {
+ SCNetworkInterfaceRef nextInterface;
+
+ nextInterface = SCNetworkInterfaceGetInterface(interface);
+ if (nextInterface == NULL) {
+ break;
+ }
+
+ interface = nextInterface;
+ }
+ interfacePrivate = (SCNetworkInterfacePrivateRef)interface;
+
+ interfaceIndex = findConfiguration(interfacePrivate->interface_type);
+ if (interfaceIndex != kCFNotFound) {
+ if (configurations[interfaceIndex].entity_hardware != NULL) {
+ CFDictionarySetValue(entity,
+ kSCPropNetInterfaceHardware,
+ *configurations[interfaceIndex].entity_hardware);
+ }
+ } else {
+ CFDictionarySetValue(entity,
+ kSCPropNetInterfaceHardware,
+ interfacePrivate->interface_type);
+ }
+
+ if (CFEqual(interfacePrivate->interface_type, kSCNetworkInterfaceTypeModem) &&
+ interfacePrivate->modemIsV92) {
+ int one = 1;
+ CFNumberRef num;
+
+ num = CFNumberCreate(NULL, kCFNumberIntType, &one);
+ CFDictionarySetValue(entity,
+ kSCPropNetInterfaceSupportsModemOnHold,
+ num);
+ CFRelease(num);
+ }
+
+ return entity;
+}
+
+
+/* ---------- interface from preferences entity ---------- */
__private_extern__ SCNetworkInterfaceRef
static mach_port_t masterPort = MACH_PORT_NULL;
CFArrayRef matching_interfaces = NULL;
+ /* initialize runtime (and kSCNetworkInterfaceIPv4) */
+ pthread_once(&initialized, __SCNetworkInterfaceInitialize);
+
if (masterPort == MACH_PORT_NULL) {
kern_return_t kr;
interfacePrivate = (SCNetworkInterfacePrivateRef)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4,
kSCNetworkInterfaceType6to4);
+ } else if (CFStringFind(ifType, CFSTR("."), 0).location != kCFNotFound) {
+ interfacePrivate = (SCNetworkInterfacePrivateRef)SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4,
+ ifType);
}
if (matching_interfaces != NULL) {
CFRetain(interfacePrivate);
break;
default :
- SCPrint(TRUE, stderr, CFSTR("more than one interface matches %@\n"), ifDevice);
+ SCLog(TRUE, LOG_DEBUG, CFSTR("__SCNetworkInterfaceCreateWithEntity() failed, more than one interface matches %@"), ifDevice);
if (matching_interfaces != NULL) CFRelease(matching_interfaces);
_SCErrorSet(kSCStatusFailed);
return NULL;
done :
if (interfacePrivate == NULL) {
+ CFStringRef entity_hardware;
+
/*
* if device not present on this system
*/
interfacePrivate->entity_type = ifType;
interfacePrivate->entity_subtype = ifSubType;
interfacePrivate->entity_device = (ifDevice != NULL) ? CFStringCreateCopy(NULL, ifDevice) : NULL;
- interfacePrivate->entity_hardware = CFDictionaryGetValue(interface_entity, kSCPropNetInterfaceHardware);
+ entity_hardware = CFDictionaryGetValue(interface_entity, kSCPropNetInterfaceHardware);
if (CFEqual(ifType, kSCValNetInterfaceTypeEthernet)) {
- if ((interfacePrivate->entity_hardware != NULL) &&
- CFEqual(interfacePrivate->entity_hardware, kSCEntNetAirPort)) {
+ if ((entity_hardware != NULL) &&
+ CFEqual(entity_hardware, kSCEntNetAirPort)) {
interfacePrivate->interface_type = kSCNetworkInterfaceTypeIEEE80211;
} else {
interfacePrivate->interface_type = kSCNetworkInterfaceTypeEthernet;
}
-/* ---------- helper functions ---------- */
-
-
-static CFIndex
-findConfiguration(CFStringRef interface_type)
-{
- CFIndex i;
-
- for (i = 0; i < sizeof(configurations)/sizeof(configurations[0]); i++) {
- if (CFEqual(interface_type, *configurations[i].interface_type)) {
- return i;
- }
- }
-
- return kCFNotFound;
-}
-
-
-static CFArrayRef
-copyConfigurationPaths(SCNetworkInterfacePrivateRef interfacePrivate)
-{
- CFMutableArrayRef array = NULL;
- CFIndex interfaceIndex;
- CFStringRef path;
- SCNetworkServicePrivateRef servicePrivate;
-
- interfaceIndex = findConfiguration(interfacePrivate->interface_type);
- if (interfaceIndex == kCFNotFound) {
- // if unknown interface type
- return NULL;
- }
-
- servicePrivate = (SCNetworkServicePrivateRef)interfacePrivate->service;
- if (servicePrivate == NULL) {
- // if not associated with a service (yet)
- return NULL;
- }
-
- array = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
-
- if (configurations[interfaceIndex].per_interface_config) {
- CFIndex i;
- CFIndex n;
- CFArrayRef sets;
-
- /*
- * per-interface configuration preferences
- *
- * 1. look for all sets which contain the associated service
- * 2. add a per-set path for the interface configuration for
- * each set.
- */
-
- sets = SCNetworkSetCopyAll(servicePrivate->prefs);
- n = (sets != NULL) ? CFArrayGetCount(sets) : 0;
-
- for (i = 0; i < n; i++) {
- CFArrayRef services;
- SCNetworkSetRef set;
-
- set = CFArrayGetValueAtIndex(sets, i);
- services = SCNetworkSetCopyServices(set);
- if (CFArrayContainsValue(services,
- CFRangeMake(0, CFArrayGetCount(services)),
- interfacePrivate->service)) {
- path = SCPreferencesPathKeyCreateSetNetworkInterfaceEntity(NULL, // allocator
- SCNetworkSetGetSetID(set), // set
- interfacePrivate->entity_device, // service
- interfacePrivate->entity_type); // entity
- CFArrayAppendValue(array, path);
- CFRelease(path);
- }
- CFRelease(services);
- }
-
- if (CFArrayGetCount(array) == 0) {
- CFRelease(array);
- array = NULL;
- }
-
- CFRelease(sets);
- } else {
- // per-service configuration preferences
- path = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL, // allocator
- servicePrivate->serviceID, // service
- interfacePrivate->entity_type); // entity
- CFArrayAppendValue(array, path);
- CFRelease(path);
- }
-
- return array;
-}
-
-
/* ---------- SCNetworkInterface APIs ---------- */
CFIndex i;
SCNetworkInterfacePrivateRef interfacePrivate = (SCNetworkInterfacePrivateRef)interface;
+ /* initialize runtime (and kSCNetworkInterfaceIPv4) */
+ pthread_once(&initialized, __SCNetworkInterfaceInitialize);
+
if (interfacePrivate->supported_interface_types != NULL) {
goto done;
}
- /* initialize runtime (and kSCNetworkInterfaceIPv4) */
- pthread_once(&initialized, __SCNetworkInterfaceInitialize);
-
i = findConfiguration(interfacePrivate->interface_type);
if (i != kCFNotFound) {
if (configurations[i].supported_interfaces != doNone) {
CFIndex i;
SCNetworkInterfacePrivateRef interfacePrivate = (SCNetworkInterfacePrivateRef)interface;
+ /* initialize runtime (and kSCNetworkInterfaceIPv4) */
+ pthread_once(&initialized, __SCNetworkInterfaceInitialize);
+
if (interfacePrivate->supported_protocol_types != NULL) {
goto done;
}
- /* initialize runtime (and kSCNetworkInterfaceIPv4) */
- pthread_once(&initialized, __SCNetworkInterfaceInitialize);
-
i = findConfiguration(interfacePrivate->interface_type);
if (i != kCFNotFound) {
if (configurations[i].supported_protocols != doNone) {
parentPrivate->interface_type = kSCNetworkInterfaceType6to4;
parentPrivate->entity_type = kSCEntNet6to4;
parentPrivate->entity_device = CFRetain(CFSTR("stf0"));
- CFRetain(parentPrivate->entity_device);
+ } else if (CFStringFind(interfaceType, CFSTR("."), 0).location != kCFNotFound) {
+ // if custom interface type
+ parentPrivate->interface_type = interfaceType;
+ parentPrivate->entity_type = interfaceType; // interface config goes into a
+ // a dictionary with the same
+ // name as the interfaceType
} else {
// unknown interface type
goto fail;
}
- parentPrivate->entity_hardware = childPrivate->entity_hardware;
parentPrivate->sort_order = childPrivate->sort_order;
return (SCNetworkInterfaceRef)parentPrivate;
return interfacePrivate->address;
}
+
SCNetworkInterfaceRef
SCNetworkInterfaceGetInterface(SCNetworkInterfaceRef interface)
{
CFStringRef child = NULL;
CFMutableStringRef local = NULL;
- pthread_once(&initialized, __SCNetworkInterfaceInitialize); /* initialize runtime */
-
if (interfacePrivate->interface != NULL) {
child = SCNetworkInterfaceGetLocalizedDisplayName(interfacePrivate->interface);
}
- if (interfacePrivate->localized_key != NULL) {
+ if ((bundle != NULL) && (interfacePrivate->localized_key != NULL)) {
CFStringRef fmt;
fmt = CFBundleCopyLocalizedString(bundle,
}
+__private_extern__
+CFStringRef
+__SCNetworkInterfaceGetModemCCL(SCNetworkInterfaceRef interface)
+{
+ SCNetworkInterfacePrivateRef interfacePrivate = (SCNetworkInterfacePrivateRef)interface;
+
+ return interfacePrivate->modemCCL;
+}
+
+
+__private_extern__
+Boolean
+__SCNetworkInterfaceIsModemV92(SCNetworkInterfaceRef interface)
+{
+ SCNetworkInterfacePrivateRef interfacePrivate = (SCNetworkInterfacePrivateRef)interface;
+
+ return interfacePrivate->modemIsV92;
+}
+
+
CFTypeID
SCNetworkInterfaceGetTypeID(void)
{
SCNetworkInterfacePrivateRef oldPrivate = (SCNetworkInterfacePrivateRef)interface;
SCNetworkInterfacePrivateRef newPrivate;
+ /* initialize runtime (and kSCNetworkInterfaceIPv4) */
+ pthread_once(&initialized, __SCNetworkInterfaceInitialize);
+
newPrivate = __SCNetworkInterfaceCreatePrivate(NULL, NULL, NULL, NULL);
- newPrivate->interface_type = CFRetain(oldPrivate->interface_type);
+ newPrivate->interface_type = oldPrivate->interface_type;
if (oldPrivate->interface != NULL) {
newPrivate->interface = (SCNetworkInterfaceRef)__SCNetworkInterfaceCreateCopy(NULL, // allocator
oldPrivate->interface, // interface
newPrivate->service = service;
newPrivate->unsaved = (oldPrivate->unsaved != NULL) ? CFRetain(oldPrivate->unsaved) : NULL;
newPrivate->entity_device = (oldPrivate->entity_device != NULL) ? CFRetain(oldPrivate->entity_device) : NULL;
- newPrivate->entity_hardware = CFRetain(oldPrivate->entity_hardware);
newPrivate->entity_type = oldPrivate->entity_type;
newPrivate->entity_subtype = oldPrivate->entity_subtype;
if (oldPrivate->supported_interface_types != NULL) {
newPrivate->builtin = oldPrivate->builtin;
newPrivate->path = (oldPrivate->path != NULL) ? CFRetain(oldPrivate->path) : NULL;
newPrivate->location = (oldPrivate->location != NULL) ? CFRetain(oldPrivate->location) : NULL;
- newPrivate->supportsDeviceOnHold = oldPrivate->supportsDeviceOnHold;
+ newPrivate->modemCCL = (oldPrivate->modemCCL != NULL) ? CFRetain(oldPrivate->modemCCL) : NULL;
+ newPrivate->modemIsV92 = oldPrivate->modemIsV92;
newPrivate->supportsBond = oldPrivate->supportsBond;
newPrivate->supportsVLAN = oldPrivate->supportsVLAN;
newPrivate->sort_order = oldPrivate->sort_order;