1 /* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2009 Erwan Velu - All Rights Reserved
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
12 * conditions:
13 *
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * -----------------------------------------------------------------------
27 */
28
29 #include "hdt-menu.h"
30 #include <sys/gpxe.h>
31
32 /* Main Kernel menu */
compute_PXE(struct s_my_menu * menu,struct s_hardware * hardware)33 void compute_PXE(struct s_my_menu *menu, struct s_hardware *hardware)
34 {
35 char buffer[SUBMENULEN + 1];
36 char infobar[STATLEN + 1];
37 char gpxe[4]={0};
38
39 if (hardware->is_pxe_valid == false)
40 return;
41
42 menu->menu = add_menu(" PXE ", -1);
43 menu->items_count = 0;
44 set_menu_pos(SUBMENU_Y, SUBMENU_X);
45
46 struct s_pxe *p = &hardware->pxe;
47
48 if ((hardware->pci_ids_return_code == -ENOPCIIDS)
49 || (p->pci_device == NULL)) {
50 snprintf(buffer, sizeof buffer, "PCI Vendor : %d", p->vendor_id);
51 snprintf(infobar, sizeof infobar, "PCI Vendor : %d", p->vendor_id);
52 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
53 menu->items_count++;
54
55 snprintf(buffer, sizeof buffer, "PCI Product : %d", p->vendor_id);
56 snprintf(infobar, sizeof infobar, "PCI Product : %d", p->vendor_id);
57 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
58 menu->items_count++;
59
60 snprintf(buffer, sizeof buffer, "PCI SubVendor : %d", p->subvendor_id);
61 snprintf(infobar, sizeof infobar, "PCI SubVendor : %d",
62 p->subvendor_id);
63 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
64 menu->items_count++;
65
66 snprintf(buffer, sizeof buffer, "PCI SubProduct : %d",
67 p->subproduct_id);
68 snprintf(infobar, sizeof infobar, "PCI SubProduct : %d",
69 p->subproduct_id);
70 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
71 menu->items_count++;
72
73 snprintf(buffer, sizeof buffer, "PCI Revision : %d", p->rev);
74 snprintf(infobar, sizeof infobar, "PCI Revision : %d", p->rev);
75 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
76 menu->items_count++;
77
78 snprintf(buffer, sizeof buffer,
79 "PCI Bus Pos. : %02x:%02x.%02x", p->pci_bus,
80 p->pci_dev, p->pci_func);
81 snprintf(infobar, sizeof infobar,
82 "PCI Bus Pos. : %02x:%02x.%02x", p->pci_bus,
83 p->pci_dev, p->pci_func);
84 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
85 menu->items_count++;
86
87 } else {
88
89 snprintf(buffer, sizeof buffer, "Manufacturer : %s",
90 p->pci_device->dev_info->vendor_name);
91 snprintf(infobar, sizeof infobar, "Manufacturer : %s",
92 p->pci_device->dev_info->vendor_name);
93 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
94 menu->items_count++;
95
96 snprintf(buffer, sizeof buffer, "Product : %s",
97 p->pci_device->dev_info->product_name);
98 snprintf(infobar, sizeof infobar, "Product : %s",
99 p->pci_device->dev_info->product_name);
100 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
101 menu->items_count++;
102 }
103
104 snprintf(buffer, sizeof buffer, "MAC Address : %s", p->mac_addr);
105 snprintf(infobar, sizeof infobar, "MAC Address : %s", p->mac_addr);
106 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
107 menu->items_count++;
108
109 snprintf(buffer, sizeof buffer, "IP Address : %d.%d.%d.%d",
110 p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3]);
111 snprintf(infobar, sizeof infobar, "IP Address : %d.%d.%d.%d",
112 p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3]);
113 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
114 menu->items_count++;
115
116 if (is_gpxe()) snprintf(gpxe,sizeof(gpxe),"%s","Yes");
117 else snprintf (gpxe, sizeof(gpxe), "%s", "No");
118
119 snprintf(buffer, sizeof buffer, "gPXE Detected: %s", gpxe);
120 snprintf(infobar, sizeof infobar, "gPXE Detected: %s", gpxe);
121 add_item(buffer, infobar, OPT_INACTIVE, NULL, 0);
122 menu->items_count++;
123
124 printf("MENU: PXE menu done (%d items)\n", menu->items_count);
125 }
126