1 | /*␊ |
2 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "modules.h"␊ |
8 | #include "boot.h"␊ |
9 | #include "bootstruct.h"␊ |
10 | #include "pci.h"␊ |
11 | #include "device_inject.h"␊ |
12 | ␊ |
13 | #ifndef DEBUG_ETHERNET␊ |
14 | #define DEBUG_ETHERNET 0␊ |
15 | #endif␊ |
16 | ␊ |
17 | #if DEBUG_ETHERNET␊ |
18 | #define DBG(x...) printf(x)␊ |
19 | #else␊ |
20 | #define DBG(x...)␊ |
21 | #endif␊ |
22 | #define kEnableWifi␉␉␉"EnableWifi"␉␊ |
23 | #define kEthernetBuiltIn␉"EthernetBuiltIn"␉␊ |
24 | #define kEnableNetworking␉"EnableNetworkModule"␊ |
25 | ␊ |
26 | void set_eth_builtin(pci_dt_t *eth_dev);␊ |
27 | void set_wifi_airport(pci_dt_t *wlan_dev);␊ |
28 | ␊ |
29 | uint32_t builtin_set = 0;␊ |
30 | ␊ |
31 | ␊ |
32 | ␊ |
33 | void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
34 | {␊ |
35 | ␉pci_dt_t* current = arg1;␊ |
36 | ␉␊ |
37 | ␉if(current->class_id == PCI_CLASS_NETWORK_ETHERNET)␊ |
38 | ␉{␊ |
39 | ␉␉// LAN␊ |
40 | ␉␉␊ |
41 | ␉␉bool do_eth_devprop = true;␉␊ |
42 | ␉␉getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->bootConfig);␊ |
43 | ␉␉␊ |
44 | ␉␉if (do_eth_devprop)␊ |
45 | ␉␉{␊ |
46 | ␉␉␉set_eth_builtin(current);␊ |
47 | ␉␉}␊ |
48 | ␉}␊ |
49 | ␉else if(current->class_id == PCI_CLASS_NETWORK_OTHER)␊ |
50 | ␉{␊ |
51 | ␉␉// WIFI␊ |
52 | ␉␉bool do_wifi_devprop = true;␉␊ |
53 | ␉␉getBoolForKey(kEnableWifi, &do_wifi_devprop, &bootInfo->bootConfig);␊ |
54 | ␉␉␊ |
55 | ␉␉if (do_wifi_devprop)␉␉␊ |
56 | ␉␉set_wifi_airport(current);␊ |
57 | ␉␉␊ |
58 | ␉}␊ |
59 | ␉␊ |
60 | }␊ |
61 | ␊ |
62 | void Networking_start()␊ |
63 | {␊ |
64 | ␉bool enable = true;␊ |
65 | ␉getBoolForKey(kEnableNetworking, &enable, &bootInfo->bootConfig) ;␊ |
66 | ␉␊ |
67 | ␉if (enable) {␊ |
68 | ␉␉register_hook_callback("PCIDevice", &Networking_hook);␊ |
69 | ␉}␊ |
70 | }␊ |
71 | ␊ |
72 | /* a fine place for this code */␊ |
73 | ␊ |
74 | int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)␊ |
75 | {␊ |
76 | ␉uint8_t builtin = 0x0;␊ |
77 | ␉␊ |
78 | ␉if(device)␊ |
79 | ␉{␊ |
80 | ␉␉␊ |
81 | ␉␉if((vendor_id != 0x168c) && (builtin_set == 0)) ␊ |
82 | ␉␉{␊ |
83 | ␉␉␉builtin_set = 1;␊ |
84 | ␉␉␉builtin = 0x01;␊ |
85 | ␉␉}␊ |
86 | ␉␉␊ |
87 | ␉␉if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))␊ |
88 | ␉␉{␊ |
89 | ␉␉␉return 0;␊ |
90 | ␉␉}␊ |
91 | ␉␉␊ |
92 | ␉␉devices_number++;␊ |
93 | ␉␉return 1;␊ |
94 | ␉}␊ |
95 | ␉else␊ |
96 | ␉{␊ |
97 | ␉␉return 0;␊ |
98 | ␉}␊ |
99 | ␉␊ |
100 | }␊ |
101 | ␊ |
102 | void set_eth_builtin(pci_dt_t *eth_dev)␊ |
103 | {␊ |
104 | ␉char *devicepath = get_pci_dev_path(eth_dev);␊ |
105 | ␉struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));␊ |
106 | ␉␊ |
107 | ␉verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);␊ |
108 | ␉␊ |
109 | ␉if (!string)␊ |
110 | ␉␉string = devprop_create_string();␊ |
111 | ␉␊ |
112 | ␉device = devprop_add_device(string, devicepath);␊ |
113 | ␉if(device)␊ |
114 | ␉{␊ |
115 | ␉␉verbose("Setting up lan keys\n");␊ |
116 | ␉␉devprop_add_network_template(device, eth_dev->vendor_id);␊ |
117 | ␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
118 | ␉␉if(stringdata)␊ |
119 | ␉␉{␊ |
120 | ␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
121 | ␉␉␉stringlength = string->length;␊ |
122 | ␉␉}␊ |
123 | ␉}␊ |
124 | }␊ |
125 | ␊ |
126 | ␊ |
127 | struct wifi_cards␊ |
128 | {␊ |
129 | ␉uint16_t␉vendor_id;␊ |
130 | ␉uint16_t␉device_id;␊ |
131 | ␉char*␉␉model;␊ |
132 | };␊ |
133 | ␊ |
134 | struct wifi_cards known_wifi_cards[] =␊ |
135 | {␊ |
136 | ␉{0x14e4, 0x4315, "Dell Wireless 1395"},␊ |
137 | ␉{0x14e4, 0x432b, "Dell Wireless 1510"},␊ |
138 | ␉{0x168C, 0x002B, "Atheros 9285 8802.11 b/g/n Wireless Network Adapter"},␊ |
139 | };␊ |
140 | ␊ |
141 | void set_wifi_airport(pci_dt_t *wlan_dev)␊ |
142 | {␊ |
143 | ␉char tmp[16];␊ |
144 | ␉␊ |
145 | ␉char *devicepath = get_pci_dev_path(wlan_dev);␊ |
146 | ␉struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));␊ |
147 | ␉␊ |
148 | ␉verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath);␊ |
149 | ␉␊ |
150 | ␉if (!string)␊ |
151 | ␉␉string = devprop_create_string();␊ |
152 | ␉␊ |
153 | ␉device = devprop_add_device(string, devicepath);␊ |
154 | ␉if(device)␊ |
155 | ␉{␊ |
156 | ␉␉sprintf(tmp, "Airport");␊ |
157 | ␉␉devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
158 | ␉␉devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
159 | ␊ |
160 | ␉␉␊ |
161 | ␉␉unsigned int i = 0;␊ |
162 | ␉␉for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)␊ |
163 | ␉␉{␊ |
164 | ␉␉␉if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id &&␊ |
165 | ␉␉␉ wlan_dev->device_id == known_wifi_cards[i].device_id)␊ |
166 | ␉␉␉{␊ |
167 | ␉␉␉␉verbose("Setting up wifi keys\n");␊ |
168 | ␉␉␉␉␊ |
169 | ␉␉␉␉devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));␊ |
170 | ␉␉␉␉␊ |
171 | ␉␉␉␉// NOTE: I would set the subsystem id and subsystem vendor id here,␊ |
172 | ␉␉␉␉// however, those values seem to be ovverriden in the boot process.␊ |
173 | ␉␉␉␉// A batter method would be injecting the DTGP dsdt method␊ |
174 | ␉␉␉␉// and then injectinve the subsystem id there.␊ |
175 | ␉␉␉␉␊ |
176 | ␉␉␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
177 | ␉␉␉␉if(stringdata)␊ |
178 | ␉␉␉␉{␊ |
179 | ␉␉␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
180 | ␉␉␉␉␉stringlength = string->length;␊ |
181 | ␉␉␉␉}␊ |
182 | ␉␉␉␉␊ |
183 | ␉␉␉␉return;␊ |
184 | ␉␉␉␉␊ |
185 | ␉␉␉}␊ |
186 | ␉␉}␊ |
187 | ␉␉␊ |
188 | ␉␉␊ |
189 | ␉}␊ |
190 | }␊ |
191 | |