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