Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/Networking/Networking.c

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

Archive Download this file

Revision: 789