|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
25: *
26: * getDevPort.c - Get device ports from Config.
27: *
28: * HISTORY
29: * 25-Jun-92 Doug Mitchell at NeXT
30: * Created.
31: */
32:
33: #import <driverkit/driverServer.h>
34: #import <driverkit/userConfigServer.h>
35: #import <driverkit/generalFuncs.h>
36: #import <mach/mach_error.h>
37: #import <bsd/sys/types.h>
38: #import <mach/mach.h>
39: #import <servers/bootstrap.h>
40: #import <servers/netname.h>
41: #import <bsd/libc.h>
42:
43: #define DPRINT_DEBUG 0
44: #if DPRINT_DEBUG
45: #define dprintf(x,a,b,c,d,e) IOLog(x,a,b,c,d,e)
46: #else DPRINT_DEBUG
47: #define dprintf(x,a,b,c,d,e)
48: #endif DPRINT_DEBUG
49:
50: #define LOG_SERVICE_NAMES 0
51:
52: /*
53: * look up all of a driver's devicePorts. returns # of ports found in
54: * *numDevicePorts.
55: * Returns IO_CNF_SUCCESS normally (even if no ports found);
56: * IO_CNF_BOOTSTRAP on other error.
57: */
58: IOConfigReturn IOGetDevicePorts(int maxDevices,
59: const char *driverName, // for error logging only
60: port_t *devicePorts, // returned
61: int *numDevicePorts, // returned
62: port_t *driverSigPort) // returned
63: {
64: int i;
65: name_array_t service_names;
66: unsigned int service_cnt;
67: name_array_t server_names;
68: unsigned int server_cnt;
69: bool_array_t service_active;
70: unsigned int service_active_cnt;
71: kern_return_t krtn;
72: int port_index = 0;
73:
74: *numDevicePorts = 0;
75:
76: /*
77: * Get some basic communication ports.
78: */
79: krtn = bootstrap_look_up(bootstrap_port,
80: SIG_PORT_NAME,
81: driverSigPort);
82: if(krtn) {
83: IOLog("%s: can't find %s: %s\n", driverName,
84: SIG_PORT_NAME, mach_error_string(krtn));
85: return IO_CNF_BOOTSTRAP;
86: }
87:
88: /*
89: * Look for our device ports, provided to us by Config.
90: */
91: krtn = bootstrap_info(bootstrap_port,
92: &service_names,
93: &service_cnt,
94: &server_names,
95: &server_cnt,
96: &service_active,
97: &service_active_cnt);
98: if (krtn != BOOTSTRAP_SUCCESS) {
99: IOLog("%s: bootstrap_info: %s", driverName,
100: mach_error_string(krtn));
101: return IO_CNF_BOOTSTRAP;
102: }
103:
104: /*
105: * Search for dev_port_XXX. Later - versions and dev_index via
106: * dev_port_to_type().
107: */
108: dprintf("%s: service_cnt %d\n", driverName, service_cnt, 3,4,5);
109: for (i = 0; i < service_cnt; i++) {
110: #if LOG_SERVICE_NAMES
111: printf("%s: service_name %s\n", driverName, service_names[i],
112: 4,5);
113: #endif LOG_SERVICE_NAMES
114: if(strncmp(service_names[i],
115: "dev_port_", strlen("dev_port_")) == 0) {
116: dprintf("%s: port %s found\n",
117: driverName, service_names[i], 3,4,5);
118:
119: /*
120: * Get the dev_port.
121: */
122: krtn = bootstrap_look_up(bootstrap_port,
123: service_names[i],
124: &devicePorts[port_index]);
125: if(krtn) {
126: IOLog("%s: bootstrap_look_up: %s",
127: driverName, mach_error_string(krtn));
128: return IO_CNF_BOOTSTRAP;
129: }
130: else {
131: if(++port_index > maxDevices) {
132: IOLog("%s: num_devices exceeded\n",
133: driverName);
134: *numDevicePorts = port_index;
135: return IO_CNF_SUCCESS;
136: }
137: }
138: } /* device port found */
139: } /* for each port in bootstrap server */
140:
141: dprintf("%s: %d devPorts found\n", driverName, port_index, 3,4,5);
142: *numDevicePorts = port_index;
143: return IO_CNF_SUCCESS;
144: }
145:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.