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