summaryrefslogtreecommitdiff
path: root/com32/lua
diff options
context:
space:
mode:
Diffstat (limited to 'com32/lua')
-rw-r--r--com32/lua/src/Makefile7
-rw-r--r--com32/lua/src/cpu.c4
-rw-r--r--com32/lua/src/dhcp.c358
-rw-r--r--com32/lua/src/dhcp.h49
-rw-r--r--com32/lua/src/dmi.c624
-rw-r--r--com32/lua/src/linit.c1
-rw-r--r--com32/lua/src/liolib.c40
-rw-r--r--com32/lua/src/lualib.h3
-rw-r--r--com32/lua/src/syslinux.c37
9 files changed, 899 insertions, 224 deletions
diff --git a/com32/lua/src/Makefile b/com32/lua/src/Makefile
index 4081bfe1..f03f7a7f 100644
--- a/com32/lua/src/Makefile
+++ b/com32/lua/src/Makefile
@@ -16,9 +16,9 @@
##
topdir = ../../..
-include ../../MCONFIG
+MAKEDIR = $(topdir)/mk
+include $(MAKEDIR)/com32.mk
-LIBS = ../../lib/libcom32.a $(LIBGCC)
LNXLIBS =
# Temporarily allow warnings not being treated as errors
@@ -44,6 +44,7 @@ LIBLUA_OBJS += dmi.o
LIBLUA_OBJS += cpu.o
LIBLUA_OBJS += pci.o
LIBLUA_OBJS += vesa.o
+LIBLUA_OBJS += dhcp.o
CFLAGS += -DLUA_ANSI
@@ -54,7 +55,7 @@ $(LIBLUA) : $(LIBLUA_OBJS)
$(AR) cq $@ $^
$(RANLIB) $@
-lua.elf : $(OBJS) $(LIBLUA) $(LIBS) $(C_LIBS)
+lua.elf : $(OBJS) $(LIBLUA) $(C_LIBS)
$(LD) $(LDFLAGS) -o $@ $^
tidy dist:
diff --git a/com32/lua/src/cpu.c b/com32/lua/src/cpu.c
index 8a246e3d..6ef4e5a3 100644
--- a/com32/lua/src/cpu.c
+++ b/com32/lua/src/cpu.c
@@ -9,13 +9,13 @@
#include"lualib.h"
#include"cpuid.h"
-static void add_string_item(lua_State *L, const char *item, const char *value_str) {
+void add_string_item(lua_State *L, const char *item, const char *value_str) {
lua_pushstring(L,item);
lua_pushstring(L,value_str);
lua_settable(L,-3);
}
-static void add_int_item(lua_State *L, const char *item, int value_int) {
+void add_int_item(lua_State *L, const char *item, int value_int) {
lua_pushstring(L,item);
lua_pushnumber(L,value_int);
lua_settable(L,-3);
diff --git a/com32/lua/src/dhcp.c b/com32/lua/src/dhcp.c
new file mode 100644
index 00000000..af948131
--- /dev/null
+++ b/com32/lua/src/dhcp.c
@@ -0,0 +1,358 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007 H. Peter Anvin - All Rights Reserved
+ * Copyright 2011 Timothy J Gleason <timmgleason_at_gmail.com> - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * dhcp.c
+ *
+ * Adds DHCPINFO functionality to the lua.c32 binary
+ *
+ * gettable() returns a table of the BOOTP message fields returned by
+ * the DHCP server for use in a Lua pxeboot script
+ * See http://tools.ietf.org/html/rfc1542
+ *
+ * lua key value RFC key
+ * -----------------------------------------------------------------------
+ * opcode op message opcode
+ * hardware.type htype Hardware address type
+ * hardware.length hlen Hardware address length
+ * hops hops Used by relay agents
+ * transaction.id xid transaction id
+ * elapsed.seconds secs Secs elapsed since client boot
+ * flags flags DHCP Flags field
+ * client.ip.addr ciaddr client IP addr
+ * your.ip.addr yiaddr 'Your' IP addr. (from server)
+ * server.ip.addr siaddr Boot server IP addr
+ * gateway.ip.addr giaddr Relay agent IP addr
+ * client.mac chaddr Client hardware addr
+ * server.hostname sname Optl. boot server hostname
+ * boot.file file boot file name (ascii path)
+ * magic.cookie cookie Magic cookie
+ *
+ * getoptions() returns a table of the DHCP Options field of the BOOTP
+ * message returned by the DHCP server for use in a Lua pxeboot script.
+ * Many of the options are reurned formatted in as strings in a standard,
+ * recognizable format, such as IP addresses.
+ *
+ * 1, 2, and 4 byte numerical options are returned as integers.
+ *
+ * Other Options with non-standard formats are returned as strings of the
+ * raw binary number that was returned by the DHCP server and must be decoded
+ * in a Lua script
+ *
+ * The Options table returns the Option code as the key except where there
+ * are multiple values returned. In those cases, an extra key increment number
+ * is added to allow individual access to each Option value.
+ *
+ * lua key value value Name
+ * -----------------------------------------------------------------------
+ * 1 Subnet Mask
+ * 6.1 DNS Server [element 1]
+ * 6.2 DNS Server [element 2]
+ * 6.3 DNS Server [element 3]
+ * 209 PXE Configuration File
+ * 21.1 Policy Filter [element 1]
+ * 21.2 Policy Filter [element 2]
+ *
+ * Options that can have a list of values, but contain only one (like Option 6)
+ * will not return with .sub key values.
+ *
+ * Usage:
+ t = dhcp.gettable()
+
+ for k,v in pairs(t) do
+ print(k.." : "..v)
+ end
+ */
+
+#include <stdio.h>
+#include "dhcp.h"
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+#include <syslinux/pxe.h>
+
+#define STR_BUF_SIZE 129 /* Sized to accomdate File field in BOOTP message */
+
+void
+ip_address_list(lua_State *L, uint8_t* value, uint8_t len, uint8_t option )
+{
+ static char op_name[64];
+ static char op_value[255];
+ int loop;
+
+ loop = len/4;
+
+ if ( loop == 1) {
+ sprintf(op_name, "%u", option);
+ lua_pushstring(L, op_name);
+ sprintf(op_value, "%u.%u.%u.%u", value[0], value[1], value[2], value[3]);
+ lua_pushstring(L, op_value);
+ lua_settable(L,-3);
+ } else {
+ for (int done = 0; done < loop; done++){
+ sprintf(op_name, "%u.%d", option, done+1);
+ lua_pushstring(L, op_name);
+ sprintf(op_value, "%u.%u.%u.%u", value[0+(done*4)], value[1+(done*4)], value[2+(done*4)], value[3+(done*4)]);
+ lua_pushstring(L, op_value);
+ lua_settable(L,-3);
+ }
+ }
+
+}
+
+static int dhcp_getoptions(lua_State *L)
+{
+ void* dhcpdata = 0;
+ dhcp_t* dhcp = 0;
+ size_t dhcplen = 0;
+
+ /* Append the DHCP info */
+ if (pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK,
+ &dhcpdata, &dhcplen))
+ {
+ return 0;
+ }
+
+ dhcp = (dhcp_t*)dhcpdata;
+
+ lua_newtable(L);
+
+ int done = 0;
+ uint8_t* ptr = (uint8_t*)&dhcp->options;
+ uint8_t len;
+ uint8_t option;
+ uint8_t* value;
+ static char op_name[64];
+
+ do {
+ option = *ptr++;
+ len = *ptr++;
+ value = ptr;
+ ptr += len;
+ switch (option) {
+// IP Address formatted lists, including singles
+ case 1:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 16:
+ case 21: /* Policy Filters - address/mask */
+ case 28:
+ case 32:
+ case 33: /* Static routes - destination/router */
+ case 41:
+ case 42:
+ case 44:
+ case 45:
+ case 47:
+ case 48:
+ case 49:
+ case 50:
+ case 51:
+ case 54:
+ case 65:
+ case 68:
+ case 69:
+ case 70:
+ case 71:
+ case 72:
+ case 73:
+ case 74:
+ case 75:
+ case 76:
+ ip_address_list(L, value, len, option);
+ break;
+// 4byte options - numerical
+ case 2:
+ case 24:
+ case 35:
+ case 38:
+ case 58:
+ case 59:
+ case 211:
+ sprintf(op_name, "%u", option);
+ lua_pushstring(L, op_name);
+ lua_pushinteger(L, ntohl(*(long*)value));
+ lua_settable(L,-3);
+ break;
+// 2byte options -numerical
+ case 13:
+ case 22:
+ case 26:
+ case 57:
+ sprintf(op_name, "%u", option);
+ lua_pushstring(L, op_name);
+ lua_pushinteger(L, ntohs(*(short*)value));
+ lua_settable(L,-3);
+ break;
+// 1byte options - numerical
+ case 19:
+ case 20:
+ case 23:
+ case 27:
+ case 29:
+ case 30:
+ case 31:
+ case 34:
+ case 36:
+ case 37:
+ case 39:
+ case 46:
+ case 52:
+ case 53:
+ sprintf(op_name, "%u", option);
+ lua_pushstring(L, op_name);
+ lua_pushinteger(L, *value);
+ lua_settable(L,-3);
+ break;
+ case 255:
+ done = 1;
+ break;
+ default:
+ sprintf(op_name, "%u", option);
+ lua_pushstring(L, op_name);
+ lua_pushlstring(L, (const char*)value, len);
+ lua_settable(L,-3);
+ break;
+ }
+
+ } while (!done);
+
+ return 1;
+}
+
+static int dhcp_gettable(lua_State *L)
+{
+ void* dhcpdata = 0;
+ dhcp_t* dhcp = 0;
+ size_t dhcplen = 0;
+ static char dhcp_arg[STR_BUF_SIZE];
+
+ /* Append the DHCP info */
+ if (pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK,
+ &dhcpdata, &dhcplen))
+ {
+ return 0;
+ }
+
+ dhcp = (dhcp_t*)dhcpdata;
+
+
+ lua_newtable(L);
+
+ lua_pushstring(L, "opcode");
+ lua_pushinteger(L, dhcp->op);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "hardware.type");
+ lua_pushinteger(L, dhcp->htype);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "hardware.length");
+ lua_pushinteger(L, dhcp->hlen);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "hops");
+ lua_pushinteger(L, dhcp->hops);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "transaction.id");
+ lua_pushinteger(L, ntohl(dhcp->xid));
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "elapsed.seconds");
+ lua_pushinteger(L, ntohs(dhcp->secs));
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "flags");
+ lua_pushinteger(L, ntohs(dhcp->flags));
+ lua_settable(L,-3);
+
+ sprintf(dhcp_arg, "%u.%u.%u.%u", dhcp->ciaddr[0], dhcp->ciaddr[1], dhcp->ciaddr[2], dhcp->ciaddr[3]);
+ lua_pushstring(L, "client.ip.addr");
+ lua_pushstring(L, dhcp_arg);
+ lua_settable(L,-3);
+
+ sprintf(dhcp_arg, "%u.%u.%u.%u", dhcp->yiaddr[0], dhcp->yiaddr[1], dhcp->yiaddr[2], dhcp->yiaddr[3]);
+ lua_pushstring(L, "your.ip.addr");
+ lua_pushstring(L, dhcp_arg);
+ lua_settable(L,-3);
+
+ sprintf(dhcp_arg, "%u.%u.%u.%u", dhcp->siaddr[0], dhcp->siaddr[1], dhcp->siaddr[2], dhcp->siaddr[3]);
+ lua_pushstring(L, "server.ip.addr");
+ lua_pushstring(L, dhcp_arg);
+ lua_settable(L,-3);
+
+ sprintf(dhcp_arg, "%u.%u.%u.%u", dhcp->giaddr[0], dhcp->giaddr[1], dhcp->giaddr[2], dhcp->giaddr[3]);
+ lua_pushstring(L, "gateway.ip.addr");
+ lua_pushstring(L, dhcp_arg);
+ lua_settable(L,-3);
+
+ sprintf(dhcp_arg, "%02X:%02X:%02X:%02X:%02X:%02X",
+ dhcp->chaddr[0], dhcp->chaddr[1], dhcp->chaddr[2],
+ dhcp->chaddr[3], dhcp->chaddr[4], dhcp->chaddr[5]);
+ lua_pushstring(L, "client.mac");
+ lua_pushstring(L, dhcp_arg);
+ lua_settable(L,-3);
+
+ snprintf(dhcp_arg, STR_BUF_SIZE, "%s", dhcp->sname);
+ dhcp_arg[STR_BUF_SIZE-1] = 0; /* Guarantee for lua_pushstring that dhcp_arg is 0 terminated /*/
+ lua_pushstring(L, "server.hostname");
+ lua_pushstring(L, dhcp_arg);
+ lua_settable(L,-3);
+
+ snprintf(dhcp_arg, STR_BUF_SIZE, "%s", dhcp->file);
+ dhcp_arg[STR_BUF_SIZE-1] = 0; /* Guarantee for lua_pushstring that dhcp_arg is 0 terminated /*/
+ lua_pushstring(L, "boot.file");
+ lua_pushstring(L, dhcp_arg);
+ lua_settable(L,-3);
+
+ sprintf(dhcp_arg, "%u.%u.%u.%u", dhcp->cookie[0], dhcp->cookie[1], dhcp->cookie[2], dhcp->cookie[3]);
+ lua_pushstring(L, "magic.cookie");
+ lua_pushstring(L, dhcp_arg);
+ lua_settable(L,-3);
+
+ return 1;
+}
+
+static const luaL_reg dhcplib[] = {
+ {"gettable", dhcp_gettable},
+ {"getoptions", dhcp_getoptions},
+ {NULL, NULL}
+};
+
+LUALIB_API int luaopen_dhcp (lua_State *L) {
+ luaL_openlib(L, LUA_DHCPLIBNAME, dhcplib, 0);
+ return 1;
+}
diff --git a/com32/lua/src/dhcp.h b/com32/lua/src/dhcp.h
new file mode 100644
index 00000000..a398cfc1
--- /dev/null
+++ b/com32/lua/src/dhcp.h
@@ -0,0 +1,49 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007 H. Peter Anvin - All Rights Reserved
+ * Copyright 2011 Timothy J Gleason <timmgleason_at_gmail.com> - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include <stdint.h>
+
+typedef struct dhcp {
+ uint8_t op; /* message opcode */
+ uint8_t htype; /* Hardware address type */
+ uint8_t hlen; /* Hardware address length */
+ uint8_t hops; /* Used by relay agents */
+ uint32_t xid; /* transaction id */
+ uint16_t secs; /* Secs elapsed since client boot */
+ uint16_t flags; /* DHCP Flags field */
+ uint8_t ciaddr[4]; /* client IP addr */
+ uint8_t yiaddr[4]; /* 'Your' IP addr. (from server) */
+ uint8_t siaddr[4]; /* Boot server IP addr */
+ uint8_t giaddr[4]; /* Relay agent IP addr */
+ uint8_t chaddr[16]; /* Client hardware addr */
+ uint8_t sname[64]; /* Optl. boot server hostname */
+ uint8_t file[128]; /* boot file name (ascii path) */
+ uint8_t cookie[4]; /* Magic cookie */
+ uint8_t options[1020]; /* Options */
+} dhcp_t;
+
diff --git a/com32/lua/src/dmi.c b/com32/lua/src/dmi.c
index c8329d33..984fb60c 100644
--- a/com32/lua/src/dmi.c
+++ b/com32/lua/src/dmi.c
@@ -9,275 +9,487 @@
#include "lualib.h"
#include "dmi/dmi.h"
-static int dmi_gettable(lua_State *L)
+extern void add_string_item(lua_State*, const char*, const char*);
+extern void add_int_item(lua_State*, const char*, int);
+typedef int (*table_fn)(lua_State*, s_dmi*);
+
+/* Add a Lua_String entry to the table on stack
+ xxx_P is the poiter version (i.e., pBase is a pointer)
+ xxx_S is the staic version (i.e., Base is the struct)
+*/
+#define LUA_ADD_STR_P(pLua_state, pBase, Field) \
+ add_string_item(pLua_state, #Field, pBase->Field);
+#define LUA_ADD_STR_S(pLua_state, Base, Field) \
+ add_string_item(pLua_state, #Field, Base.Field);
+
+/* Add a Lua_Number entry to the table on stack
+ xxx_P is the poiter version (i.e., pBase is a pointer)
+ xxx_S is the staic version (i.e., Base is the struct)
+*/
+#define LUA_ADD_NUM_P(pLua_state, pBase, Field) \
+ add_int_item(pLua_state, #Field, pBase->Field);
+#define LUA_ADD_NUM_S(pLua_state, Base, Field) \
+ add_int_item(pLua_state, #Field, Base.Field);
+
+/* Add a sub-DMI table to the table on stack
+ All (*table_fn)() have to be named as get_<tabel_name>_table() for this
+ macro to work. For example, for the bios subtable, the table_fn is
+ get_bios_table() and the subtable name is "bios".
+ All (*table_fn)() have to return 1 if a subtable is created on the stack
+ or 0 if the subtable is not created (no corresponding dim subtable found).
+*/
+#define LUA_ADD_TABLE(pLua_state, pDmi, tb_name) \
+ add_dmi_sub_table(pLua_state, pDmi, #tb_name, get_ ## tb_name ## _table);
+
+
+static void add_dmi_sub_table(lua_State *L, s_dmi *dmi_ptr, char *table_name,
+ table_fn get_table_fn)
{
- s_dmi dmi;
-
- lua_newtable(L);
-
- if ( ! dmi_iterate(&dmi) ) {
- printf("No DMI Structure found\n");
- return -1;
+ if (get_table_fn(L, dmi_ptr)) { /* only adding it when it is there */
+ lua_pushstring(L, table_name);
+ lua_insert(L, -2);
+ lua_settable(L,-3);
}
+}
- parse_dmitable(&dmi);
-
- /* bios */
- lua_pushstring(L, "bios.vendor");
- lua_pushstring(L, dmi.bios.vendor);
- lua_settable(L,-3);
-
- lua_pushstring(L, "bios.version");
- lua_pushstring(L, dmi.bios.version);
- lua_settable(L,-3);
-
- lua_pushstring(L, "bios.release_date");
- lua_pushstring(L, dmi.bios.release_date);
- lua_settable(L,-3);
- lua_pushstring(L, "bios.bios_revision");
- lua_pushstring(L, dmi.bios.bios_revision);
- lua_settable(L,-3);
+void get_bool_table(lua_State *L, const char *str_table[], int n_elem,
+ bool *bool_table)
+{
+ int i;
+ for (i = 0; i < n_elem; i++) {
+ if (!str_table[i] || !*str_table[i]) /* aviod NULL/empty string */
+ continue;
+
+ lua_pushstring(L, str_table[i]);
+ lua_pushboolean(L, bool_table[i]);
+ lua_settable(L,-3);
+ }
+}
- lua_pushstring(L, "bios.firmware_revision");
- lua_pushstring(L, dmi.bios.firmware_revision);
- lua_settable(L,-3);
- lua_pushstring(L, "bios.address");
- lua_pushnumber(L, dmi.bios.address);
- lua_settable(L,-3);
+/*
+** {======================================================
+** DMI subtables
+** =======================================================
+*/
+static int get_bios_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_bios *bios = &dmi_ptr->bios;
- lua_pushstring(L, "bios.runtime_size");
- lua_pushnumber(L, dmi.bios.runtime_size);
+ if (!bios->filled)
+ return 0;
+ /* bios */
+ lua_newtable(L);
+ LUA_ADD_STR_P(L, bios, vendor)
+ LUA_ADD_STR_P(L, bios, version)
+ LUA_ADD_STR_P(L, bios, release_date)
+ LUA_ADD_STR_P(L, bios, bios_revision)
+ LUA_ADD_STR_P(L, bios, firmware_revision)
+ LUA_ADD_NUM_P(L, bios, address)
+ LUA_ADD_NUM_P(L, bios, runtime_size)
+ LUA_ADD_STR_P(L, bios, runtime_size_unit)
+ LUA_ADD_NUM_P(L, bios, rom_size)
+ LUA_ADD_STR_P(L, bios, rom_size_unit)
+
+ /* bios characteristics */
+ lua_pushstring(L, "chars");
+ lua_newtable(L);
+ get_bool_table(L, bios_charac_strings,
+ sizeof(s_characteristics)/sizeof(bool),
+ (bool *)(&bios->characteristics));
+ get_bool_table(L, bios_charac_x1_strings,
+ sizeof(s_characteristics_x1)/sizeof(bool),
+ (bool *)(&bios->characteristics_x1));
+ get_bool_table(L, bios_charac_x2_strings,
+ sizeof(s_characteristics_x2)/sizeof(bool),
+ (bool *)(&bios->characteristics_x2));
lua_settable(L,-3);
- lua_pushstring(L, "bios.runtime_size_unit");
- lua_pushstring(L, dmi.bios.runtime_size_unit);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushstring(L, "bios.rom_size");
- lua_pushnumber(L, dmi.bios.rom_size);
- lua_settable(L,-3);
- lua_pushstring(L, "bios.rom_size_unit");
- lua_pushstring(L, dmi.bios.rom_size_unit);
- lua_settable(L,-3);
+static int get_system_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_system *system = &dmi_ptr->system;
+ if (!system->filled)
+ return 0;
/* system */
- lua_pushstring(L, "system.manufacturer");
- lua_pushstring(L, dmi.system.manufacturer);
- lua_settable(L,-3);
-
- lua_pushstring(L, "system.product_name");
- lua_pushstring(L, dmi.system.product_name);
- lua_settable(L,-3);
-
- lua_pushstring(L, "system.version");
- lua_pushstring(L, dmi.system.version);
- lua_settable(L,-3);
-
- lua_pushstring(L, "system.serial");
- lua_pushstring(L, dmi.system.serial);
- lua_settable(L,-3);
-
- lua_pushstring(L, "system.uuid");
- lua_pushstring(L, dmi.system.uuid);
- lua_settable(L,-3);
+ lua_newtable(L);
+ LUA_ADD_STR_P(L, system, manufacturer)
+ LUA_ADD_STR_P(L, system, product_name)
+ LUA_ADD_STR_P(L, system, version)
+ LUA_ADD_STR_P(L, system, serial)
+ LUA_ADD_STR_P(L, system, uuid)
+ LUA_ADD_STR_P(L, system, wakeup_type)
+ LUA_ADD_STR_P(L, system, sku_number)
+ LUA_ADD_STR_P(L, system, family)
+ LUA_ADD_STR_P(L, system, system_boot_status)
+ LUA_ADD_STR_P(L, system, configuration_options)
+
+ /* system reset */
+ if (system->system_reset.filled) {
+ lua_pushstring(L, "reset");
+ lua_newtable(L);
+ LUA_ADD_NUM_S(L, system->system_reset, status)
+ LUA_ADD_NUM_S(L, system->system_reset, watchdog)
+ LUA_ADD_STR_S(L, system->system_reset, boot_option)
+ LUA_ADD_STR_S(L, system->system_reset, boot_option_on_limit)
+ LUA_ADD_STR_S(L, system->system_reset, reset_count)
+ LUA_ADD_STR_S(L, system->system_reset, reset_limit)
+ LUA_ADD_STR_S(L, system->system_reset, timer_interval)
+ LUA_ADD_STR_S(L, system->system_reset, timeout)
+ lua_settable(L,-3);
+ }
- lua_pushstring(L, "system.wakeup_type");
- lua_pushstring(L, dmi.system.wakeup_type);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushstring(L, "system.sku_number");
- lua_pushstring(L, dmi.system.sku_number);
- lua_settable(L,-3);
- lua_pushstring(L, "system.family");
- lua_pushstring(L, dmi.system.family);
- lua_settable(L,-3);
+static int get_base_board_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_base_board *base_board = &dmi_ptr->base_board;
+ int n_dev = sizeof(base_board->devices_information) /
+ sizeof(base_board->devices_information[0]);
+ int i, j, has_dev;
+ if (!base_board->filled)
+ return 0;
/* base_board */
- lua_pushstring(L, "base_board.manufacturer");
- lua_pushstring(L, dmi.base_board.manufacturer);
- lua_settable(L,-3);
-
- lua_pushstring(L, "base_board.product_name");
- lua_pushstring(L, dmi.base_board.product_name);
- lua_settable(L,-3);
+ lua_newtable(L);
+ LUA_ADD_STR_P(L, base_board, manufacturer)
+ LUA_ADD_STR_P(L, base_board, product_name)
+ LUA_ADD_STR_P(L, base_board, version)
+ LUA_ADD_STR_P(L, base_board, serial)
+ LUA_ADD_STR_P(L, base_board, asset_tag)
+ LUA_ADD_STR_P(L, base_board, location)
+ LUA_ADD_STR_P(L, base_board, type)
+
+ /* base board features */
+ lua_pushstring(L, "features");
+ lua_newtable(L);
+ get_bool_table(L, base_board_features_strings,
+ sizeof(s_base_board_features)/sizeof(bool),
+ (bool *)(&base_board->features));
+ lua_settable(L,-3);
+
+ /* on-board devices */
+ for (has_dev = 0, i = 0; i < n_dev; i++)
+ if (*base_board->devices_information[i].type)
+ has_dev++;
+
+ if (has_dev) {
+ lua_pushstring(L, "devices");
+ lua_newtable(L);
+ for (i = 0, j = 1; i < n_dev; i++) {
+ if (!*base_board->devices_information[i].type) /* empty device */
+ continue;
+
+ lua_pushinteger(L, j++);
+ lua_newtable(L);
+ LUA_ADD_STR_S(L, base_board->devices_information[i], type)
+ LUA_ADD_STR_S(L, base_board->devices_information[i], description)
+ LUA_ADD_NUM_S(L, base_board->devices_information[i], status)
+ lua_settable(L,-3);
+ }
+ lua_settable(L,-3);
+ }
- lua_pushstring(L, "base_board.version");
- lua_pushstring(L, dmi.base_board.version);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushstring(L, "base_board.serial");
- lua_pushstring(L, dmi.base_board.serial);
- lua_settable(L,-3);
- lua_pushstring(L, "base_board.asset_tag");
- lua_pushstring(L, dmi.base_board.asset_tag);
- lua_settable(L,-3);
+static int get_chassis_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_chassis *chassis = &dmi_ptr->chassis;
- lua_pushstring(L, "base_board.location");
- lua_pushstring(L, dmi.base_board.location);
- lua_settable(L,-3);
+ if (!chassis->filled)
+ return 0;
+ /* chassis */
+ lua_newtable(L);
+ LUA_ADD_STR_P(L, chassis, manufacturer)
+ LUA_ADD_STR_P(L, chassis, type)
+ LUA_ADD_STR_P(L, chassis, lock)
+ LUA_ADD_STR_P(L, chassis, version)
+ LUA_ADD_STR_P(L, chassis, serial)
+ LUA_ADD_STR_P(L, chassis, asset_tag)
+ LUA_ADD_STR_P(L, chassis, boot_up_state)
+ LUA_ADD_STR_P(L, chassis, power_supply_state)
+ LUA_ADD_STR_P(L, chassis, thermal_state)
+ LUA_ADD_STR_P(L, chassis, security_status)
+ LUA_ADD_STR_P(L, chassis, oem_information)
+ LUA_ADD_NUM_P(L, chassis, height)
+ LUA_ADD_NUM_P(L, chassis, nb_power_cords)
- lua_pushstring(L, "base_board.type");
- lua_pushstring(L, dmi.base_board.type);
- lua_settable(L,-3);
+ return 1;
+}
- /* chassis */
- lua_pushstring(L, "chassis.manufacturer");
- lua_pushstring(L, dmi.chassis.manufacturer);
- lua_settable(L,-3);
- lua_pushstring(L, "chassis.type");
- lua_pushstring(L, dmi.chassis.type);
- lua_settable(L,-3);
+static int get_processor_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_processor *processor = &dmi_ptr->processor;
+ s_signature *signature = &processor->signature;
- lua_pushstring(L, "chassis.lock");
- lua_pushstring(L, dmi.chassis.lock);
+ if (!processor->filled)
+ return 0;
+ /* processor */
+ lua_newtable(L);
+ LUA_ADD_STR_P(L, processor, socket_designation)
+ LUA_ADD_STR_P(L, processor, type)
+ LUA_ADD_STR_P(L, processor, family)
+ LUA_ADD_STR_P(L, processor, manufacturer)
+ LUA_ADD_STR_P(L, processor, version)
+ LUA_ADD_NUM_P(L, processor, external_clock)
+ LUA_ADD_NUM_P(L, processor, max_speed)
+ LUA_ADD_NUM_P(L, processor, current_speed)
+ LUA_ADD_NUM_P(L, processor, voltage_mv)
+ LUA_ADD_STR_P(L, processor, status)
+ LUA_ADD_STR_P(L, processor, upgrade)
+ LUA_ADD_STR_P(L, processor, cache1)
+ LUA_ADD_STR_P(L, processor, cache2)
+ LUA_ADD_STR_P(L, processor, cache3)
+ LUA_ADD_STR_P(L, processor, serial)
+ LUA_ADD_STR_P(L, processor, part_number)
+ LUA_ADD_STR_P(L, processor, id)
+ LUA_ADD_NUM_P(L, processor, core_count)
+ LUA_ADD_NUM_P(L, processor, core_enabled)
+ LUA_ADD_NUM_P(L, processor, thread_count)
+
+ /* processor signature */
+ lua_pushstring(L, "signature");
+ lua_newtable(L);
+ LUA_ADD_NUM_P(L, signature, type)
+ LUA_ADD_NUM_P(L, signature, family)
+ LUA_ADD_NUM_P(L, signature, model)
+ LUA_ADD_NUM_P(L, signature, stepping)
+ LUA_ADD_NUM_P(L, signature, minor_stepping)
lua_settable(L,-3);
- lua_pushstring(L, "chassis.version");
- lua_pushstring(L, dmi.chassis.version);
+ /* processor flags */
+ lua_pushstring(L, "flags");
+ lua_newtable(L);
+ get_bool_table(L, cpu_flags_strings,
+ sizeof(s_dmi_cpu_flags)/sizeof(bool),
+ (bool *)(&processor->cpu_flags));
lua_settable(L,-3);
- lua_pushstring(L, "chassis.serial");
- lua_pushstring(L, dmi.chassis.serial);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushstring(L, "chassis.asset_tag");
- lua_pushstring(L, dmi.chassis.asset_tag);
- lua_settable(L,-3);
- lua_pushstring(L, "chassis.boot_up_state");
- lua_pushstring(L, dmi.chassis.boot_up_state);
- lua_settable(L,-3);
+static int get_battery_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_battery *battery = &dmi_ptr->battery;
- lua_pushstring(L, "chassis.power_supply_state");
- lua_pushstring(L, dmi.chassis.power_supply_state);
- lua_settable(L,-3);
+ if (!battery->filled)
+ return 0;
+ /* battery */
+ lua_newtable(L);
+ LUA_ADD_STR_P(L, battery, location)
+ LUA_ADD_STR_P(L, battery, manufacturer)
+ LUA_ADD_STR_P(L, battery, manufacture_date)
+ LUA_ADD_STR_P(L, battery, serial)
+ LUA_ADD_STR_P(L, battery, name)
+ LUA_ADD_STR_P(L, battery, chemistry)
+ LUA_ADD_STR_P(L, battery, design_capacity)
+ LUA_ADD_STR_P(L, battery, design_voltage)
+ LUA_ADD_STR_P(L, battery, sbds)
+ LUA_ADD_STR_P(L, battery, sbds_serial)
+ LUA_ADD_STR_P(L, battery, maximum_error)
+ LUA_ADD_STR_P(L, battery, sbds_manufacture_date)
+ LUA_ADD_STR_P(L, battery, sbds_chemistry)
+ LUA_ADD_STR_P(L, battery, oem_info)
- lua_pushstring(L, "chassis.thermal_state");
- lua_pushstring(L, dmi.chassis.thermal_state);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushstring(L, "chassis.security_status");
- lua_pushstring(L, dmi.chassis.security_status);
- lua_settable(L,-3);
- lua_pushstring(L, "chassis.oem_information");
- lua_pushstring(L, dmi.chassis.oem_information);
- lua_settable(L,-3);
+static int get_memory_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_memory *memory = dmi_ptr->memory;
+ int i, j, n_mem = dmi_ptr->memory_count;
- lua_pushstring(L, "chassis.height");
- lua_pushnumber(L, dmi.chassis.height);
- lua_settable(L,-3);
+ if (n_mem <= 0) /* no memory info */
+ return 0;
- lua_pushstring(L, "chassis.nb_power_cords");
- lua_pushnumber(L, dmi.chassis.nb_power_cords);
- lua_settable(L,-3);
+ /* memory */
+ lua_newtable(L);
+ for (j = 1, i = 0; i < n_mem; i++) {
+ if (!memory[i].filled)
+ continue;
+
+ lua_pushinteger(L, j++);
+ lua_newtable(L);
+ LUA_ADD_STR_S(L, memory[i], manufacturer)
+ LUA_ADD_STR_S(L, memory[i], error)
+ LUA_ADD_STR_S(L, memory[i], total_width)
+ LUA_ADD_STR_S(L, memory[i], data_width)
+ LUA_ADD_STR_S(L, memory[i], size)
+ LUA_ADD_STR_S(L, memory[i], form_factor)
+ LUA_ADD_STR_S(L, memory[i], device_set)
+ LUA_ADD_STR_S(L, memory[i], device_locator)
+ LUA_ADD_STR_S(L, memory[i], bank_locator)
+ LUA_ADD_STR_S(L, memory[i], type)
+ LUA_ADD_STR_S(L, memory[i], type_detail)
+ LUA_ADD_STR_S(L, memory[i], speed)
+ LUA_ADD_STR_S(L, memory[i], serial)
+ LUA_ADD_STR_S(L, memory[i], asset_tag)
+ LUA_ADD_STR_S(L, memory[i], part_number)
+ lua_settable(L,-3);
+ }
+ return 1;
+}
- /* processor */
- lua_pushstring(L, "processor.socket_designation");
- lua_pushstring(L, dmi.processor.socket_designation);
- lua_settable(L,-3);
- lua_pushstring(L, "processor.type");
- lua_pushstring(L, dmi.processor.type);
- lua_settable(L,-3);
+static int get_memory_module_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_memory_module *memory_module = dmi_ptr->memory_module;
+ int i, j, n_mem = dmi_ptr->memory_module_count;
- lua_pushstring(L, "processor.family");
- lua_pushstring(L, dmi.processor.family);
- lua_settable(L,-3);
+ if (n_mem <= 0) /* no memory module info */
+ return 0;
- lua_pushstring(L, "processor.manufacturer");
- lua_pushstring(L, dmi.processor.manufacturer);
- lua_settable(L,-3);
+ /* memory module */
+ lua_newtable(L);
+ for (j = 1, i = 0; i < n_mem; i++) {
+ if (!memory_module[i].filled)
+ continue;
+
+ lua_pushinteger(L, j++);
+ lua_newtable(L);
+ LUA_ADD_STR_S(L, memory_module[i], socket_designation)
+ LUA_ADD_STR_S(L, memory_module[i], bank_connections)
+ LUA_ADD_STR_S(L, memory_module[i], speed)
+ LUA_ADD_STR_S(L, memory_module[i], type)
+ LUA_ADD_STR_S(L, memory_module[i], installed_size)
+ LUA_ADD_STR_S(L, memory_module[i], enabled_size)
+ LUA_ADD_STR_S(L, memory_module[i], error_status)
+ lua_settable(L,-3);
+ }
+ return 1;
+}
- lua_pushstring(L, "processor.version");
- lua_pushstring(L, dmi.processor.version);
- lua_settable(L,-3);
- lua_pushstring(L, "processor.external_clock");
- lua_pushnumber(L, dmi.processor.external_clock);
- lua_settable(L,-3);
+static int get_cache_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_cache *cache = dmi_ptr->cache;
+ int i, n_cache = dmi_ptr->cache_count;
- lua_pushstring(L, "processor.max_speed");
- lua_pushnumber(L, dmi.processor.max_speed);
- lua_settable(L,-3);
+ if (n_cache <= 0) /* no cache info */
+ return 0;
- lua_pushstring(L, "processor.current_speed");
- lua_pushnumber(L, dmi.processor.current_speed);
- lua_settable(L,-3);
+ /* memory */
+ lua_newtable(L);
+ for (i = 0; i < n_cache; i++) {
+ lua_pushinteger(L, i + 1);
+ lua_newtable(L);
+ LUA_ADD_STR_S(L, cache[i], socket_designation)
+ LUA_ADD_STR_S(L, cache[i], configuration)
+ LUA_ADD_STR_S(L, cache[i], mode)
+ LUA_ADD_STR_S(L, cache[i], location)
+ LUA_ADD_NUM_S(L, cache[i], installed_size)
+ LUA_ADD_NUM_S(L, cache[i], max_size)
+ LUA_ADD_STR_S(L, cache[i], supported_sram_types)
+ LUA_ADD_STR_S(L, cache[i], installed_sram_types)
+ LUA_ADD_NUM_S(L, cache[i], speed)
+ LUA_ADD_STR_S(L, cache[i], error_correction_type)
+ LUA_ADD_STR_S(L, cache[i], system_type)
+ LUA_ADD_STR_S(L, cache[i], associativity)
+ lua_settable(L,-3);
+ }
+ return 1;
+}
- lua_pushstring(L, "processor.signature.type");
- lua_pushnumber(L, dmi.processor.signature.type);
- lua_settable(L,-3);
- lua_pushstring(L, "processor.signature.family");
- lua_pushnumber(L, dmi.processor.signature.family);
- lua_settable(L,-3);
+static int get_hardware_security_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ if (!dmi_ptr->hardware_security.filled)
+ return 0;
+ /* hardware_security */
+ lua_newtable(L);
+ LUA_ADD_STR_S(L, dmi_ptr->hardware_security, power_on_passwd_status)
+ LUA_ADD_STR_S(L, dmi_ptr->hardware_security, keyboard_passwd_status)
+ LUA_ADD_STR_S(L, dmi_ptr->hardware_security, administrator_passwd_status)
+ LUA_ADD_STR_S(L, dmi_ptr->hardware_security, front_panel_reset_status)
- lua_pushstring(L, "processor.signature.model");
- lua_pushnumber(L, dmi.processor.signature.model);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushstring(L, "processor.signature.stepping");
- lua_pushnumber(L, dmi.processor.signature.stepping);
- lua_settable(L,-3);
- lua_pushstring(L, "processor.signature.minor_stepping");
- lua_pushnumber(L, dmi.processor.signature.minor_stepping);
- lua_settable(L,-3);
+static int get_dmi_info_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ dmi_table *dmitable = &dmi_ptr->dmitable;
- lua_pushstring(L, "processor.voltage_mv");
- lua_pushnumber(L, dmi.processor.voltage_mv);
- lua_settable(L,-3);
+ /* dmi info */
+ lua_newtable(L);
+ LUA_ADD_NUM_P(L, dmitable, num)
+ LUA_ADD_NUM_P(L, dmitable, len)
+ LUA_ADD_NUM_P(L, dmitable, ver)
+ LUA_ADD_NUM_P(L, dmitable, base)
+ LUA_ADD_NUM_P(L, dmitable, major_version)
+ LUA_ADD_NUM_P(L, dmitable, minor_version)
- lua_pushstring(L, "processor.status");
- lua_pushstring(L, dmi.processor.status);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushstring(L, "processor.upgrade");
- lua_pushstring(L, dmi.processor.upgrade);
- lua_settable(L,-3);
- lua_pushstring(L, "processor.cache1");
- lua_pushstring(L, dmi.processor.cache1);
- lua_settable(L,-3);
+static int get_ipmi_table(lua_State *L, s_dmi *dmi_ptr)
+{
+ s_ipmi *ipmi = &dmi_ptr->ipmi;
- lua_pushstring(L, "processor.cache2");
- lua_pushstring(L, dmi.processor.cache2);
- lua_settable(L,-3);
+ if (!ipmi->filled)
+ return 0;
+ /* ipmi */
+ lua_newtable(L);
+ LUA_ADD_STR_P(L, ipmi, interface_type)
+ LUA_ADD_NUM_P(L, ipmi, major_specification_version)
+ LUA_ADD_NUM_P(L, ipmi, minor_specification_version)
+ LUA_ADD_NUM_P(L, ipmi, I2C_slave_address)
+ LUA_ADD_NUM_P(L, ipmi, nv_address)
+ LUA_ADD_NUM_P(L, ipmi, base_address)
+ LUA_ADD_NUM_P(L, ipmi, irq)
- lua_pushstring(L, "processor.cache3");
- lua_pushstring(L, dmi.processor.cache3);
- lua_settable(L,-3);
+ return 1;
+}
+/*
+** {======================================================
+** End of DMI subtables
+** =======================================================
+*/
- lua_pushstring(L, "processor.serial");
- lua_pushstring(L, dmi.processor.serial);
- lua_settable(L,-3);
- lua_pushstring(L, "processor.part_number");
- lua_pushstring(L, dmi.processor.part_number);
- lua_settable(L,-3);
+static int dmi_gettable(lua_State *L)
+{
+ s_dmi dmi;
- lua_pushstring(L, "processor.id");
- lua_pushstring(L, dmi.processor.id);
- lua_settable(L,-3);
+ lua_newtable(L);
- lua_pushstring(L, "processor.core_count");
- lua_pushnumber(L, dmi.processor.core_count);
- lua_settable(L,-3);
+ if ( ! dmi_iterate(&dmi) ) {
+ printf("No DMI Structure found\n");
+ return -1;
+ }
- lua_pushstring(L, "processor.core_enabled");
- lua_pushnumber(L, dmi.processor.core_enabled);
- lua_settable(L,-3);
+ parse_dmitable(&dmi);
- lua_pushstring(L, "processor.thread_count");
- lua_pushnumber(L, dmi.processor.thread_count);
- lua_settable(L,-3);
+ LUA_ADD_NUM_S(L, dmi, memory_module_count)
+ LUA_ADD_NUM_S(L, dmi, memory_count)
+ LUA_ADD_NUM_S(L, dmi, cache_count)
+ LUA_ADD_STR_S(L, dmi, oem_strings)
+
+ LUA_ADD_TABLE(L, &dmi, bios)
+ LUA_ADD_TABLE(L, &dmi, system)
+ LUA_ADD_TABLE(L, &dmi, base_board)
+ LUA_ADD_TABLE(L, &dmi, chassis)
+ LUA_ADD_TABLE(L, &dmi, processor)
+ LUA_ADD_TABLE(L, &dmi, battery)
+ LUA_ADD_TABLE(L, &dmi, memory)
+ LUA_ADD_TABLE(L, &dmi, memory_module)
+ LUA_ADD_TABLE(L, &dmi, cache)
+ LUA_ADD_TABLE(L, &dmi, ipmi)
+ LUA_ADD_TABLE(L, &dmi, hardware_security)
+ LUA_ADD_TABLE(L, &dmi, dmi_info)
/* set global variable: lua_setglobal(L, "dmitable"); */
diff --git a/com32/lua/src/linit.c b/com32/lua/src/linit.c
index 6c7f63e4..6e978736 100644
--- a/com32/lua/src/linit.c
+++ b/com32/lua/src/linit.c
@@ -33,6 +33,7 @@ static const luaL_Reg lualibs[] = {
{LUA_PCILIBNAME, luaopen_pci},
{LUA_SYSLINUXLIBNAME, luaopen_syslinux},
{LUA_VESALIBNAME, luaopen_vesa},
+ {LUA_DHCPLIBNAME, luaopen_dhcp},
#endif
{NULL, NULL}
};
diff --git a/com32/lua/src/liolib.c b/com32/lua/src/liolib.c
index 3f27395d..cf9dca22 100644
--- a/com32/lua/src/liolib.c
+++ b/com32/lua/src/liolib.c
@@ -18,12 +18,18 @@
#include "lauxlib.h"
#include "lualib.h"
-
+#ifdef SYSLINUX
+ #define NO_TMP_FILE 1
+ #define NO_READ_NUMBER 1
+ #define NO_TEST_EOF 1
+ #define NO_CLEAR_ERR 1
+ #define NO_F_SEEK 1
+ #define NO_F_SETVBUF 1
+#endif
#define IO_INPUT 1
#define IO_OUTPUT 2
-
static const char *const fnames[] = {"input", "output"};
@@ -180,7 +186,7 @@ static int io_popen (lua_State *L) {
}
-#ifndef SYSLINUX
+#ifndef NO_TMP_FILE
static int io_tmpfile (lua_State *L) {
FILE **pf = newfile(L);
*pf = tmpfile();
@@ -271,7 +277,7 @@ static int io_lines (lua_State *L) {
** =======================================================
*/
-#ifndef SYSLINUX
+#ifndef NO_READ_NUMBER /* No fscanf() and thus no read_number() */
static int read_number (lua_State *L, FILE *f) {
lua_Number d;
if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
@@ -283,8 +289,9 @@ static int read_number (lua_State *L, FILE *f) {
return 0; /* read fails */
}
}
+#endif
-
+#ifndef NO_TEST_EOF /* no buffering -> no ungetc() -> no EOF test */
static int test_eof (lua_State *L, FILE *f) {
int c = getc(f);
ungetc(c, f);
@@ -315,7 +322,6 @@ static int read_line (lua_State *L, FILE *f) {
}
}
-#ifndef SYSLINUX /* Not used */
static int read_chars (lua_State *L, FILE *f, size_t n) {
size_t rlen; /* how much to read */
size_t nr; /* number of chars actually read */
@@ -337,7 +343,9 @@ static int g_read (lua_State *L, FILE *f, int first) {
int nargs = lua_gettop(L) - 1;
int success;
int n;
+#ifndef NO_CLEAR_ERR
clearerr(f);
+#endif
if (nargs == 0) { /* no arguments? */
success = read_line(L, f);
n = first+1; /* to return 1 result */
@@ -348,14 +356,22 @@ static int g_read (lua_State *L, FILE *f, int first) {
for (n = first; nargs-- && success; n++) {
if (lua_type(L, n) == LUA_TNUMBER) {
size_t l = (size_t)lua_tointeger(L, n);
+#ifndef NO_TEST_EOF
success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
+#else /* we don't have test_eof defined */
+ success = (l == 0) ? 1 : read_chars(L, f, l);
+#endif
}
else {
const char *p = lua_tostring(L, n);
luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
switch (p[1]) {
case 'n': /* number */
+#ifndef NO_READ_NUMBER
success = read_number(L, f);
+#else
+ return luaL_argerror(L, n, "\"*number\" not supported");
+#endif
break;
case 'l': /* line */
success = read_line(L, f);
@@ -388,7 +404,6 @@ static int io_read (lua_State *L) {
static int f_read (lua_State *L) {
return g_read(L, tofile(L), 2);
}
-#endif
static int io_readline (lua_State *L) {
@@ -441,7 +456,7 @@ static int f_write (lua_State *L) {
return g_write(L, tofile(L), 2);
}
-#ifndef SYSLINUX
+#ifndef NO_F_SEEK
static int f_seek (lua_State *L) {
static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
static const char *const modenames[] = {"set", "cur", "end", NULL};
@@ -456,8 +471,9 @@ static int f_seek (lua_State *L) {
return 1;
}
}
+#endif
-
+#ifndef NO_F_SETVBUF
static int f_setvbuf (lua_State *L) {
static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
static const char *const modenames[] = {"no", "full", "line", NULL};
@@ -488,8 +504,8 @@ static const luaL_Reg iolib[] = {
{"open", io_open},
{"output", io_output},
{"popen", io_popen},
-#ifndef SYSLINUX
{"read", io_read},
+#ifndef NO_TMP_FILE
{"tmpfile", io_tmpfile},
#endif
{"type", io_type},
@@ -502,9 +518,11 @@ static const luaL_Reg flib[] = {
{"close", io_close},
{"flush", f_flush},
{"lines", f_lines},
-#ifndef SYSLINUX
{"read", f_read},
+#ifndef NO_F_SEEK
{"seek", f_seek},
+#endif
+#ifndef NO_F_SETVBUF
{"setvbuf", f_setvbuf},
#endif
{"write", f_write},
diff --git a/com32/lua/src/lualib.h b/com32/lua/src/lualib.h
index 0ae6ba75..40d1bf29 100644
--- a/com32/lua/src/lualib.h
+++ b/com32/lua/src/lualib.h
@@ -54,6 +54,9 @@ LUALIB_API int (luaopen_vesa) (lua_State *L);
#define LUA_CPULIBNAME "cpu"
LUALIB_API int (luaopen_cpu) (lua_State *L);
+
+#define LUA_DHCPLIBNAME "dhcp"
+LUALIB_API int (luaopen_dhcp) (lua_State *L);
#endif
/* open all previous libraries */
diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c
index 9b207db7..afcdcaad 100644
--- a/com32/lua/src/syslinux.c
+++ b/com32/lua/src/syslinux.c
@@ -39,6 +39,7 @@
#include "syslinux/loadfile.h"
#include "syslinux/linux.h"
#include "syslinux/config.h"
+#include "syslinux/reboot.h"
int __parse_argv(char ***argv, const char *str);
@@ -278,7 +279,7 @@ static int sl_boot_linux(lua_State * L)
msleep(10000);
*/
- ret = syslinux_boot_linux(kernel_data, kernel_len, initramfs, newcmdline);
+ ret = syslinux_boot_linux(kernel_data, kernel_len, initramfs, NULL, newcmdline);
printf("syslinux_boot_linux returned %d\n", ret);
@@ -405,7 +406,36 @@ static int sl_boot_it(lua_State * L)
(void)mem_limit;
return syslinux_boot_linux(kernel->data, kernel->size,
- initramfs, (char *)cmdline);
+ initramfs, NULL, (char *)cmdline);
+}
+
+static int sl_config_file(lua_State * L)
+{
+ const char *config_file = syslinux_config_file();
+ lua_pushstring(L, config_file);
+ return 1;
+}
+
+static int sl_reboot(lua_State * L)
+{
+ int warm_boot = luaL_optint(L, 1, 0);
+ /* explicitly convert it to 1 or 0 */
+ warm_boot = warm_boot? 1 : 0;
+ syslinux_reboot(warm_boot);
+ return 0;
+}
+
+static int sl_ipappend_strs(lua_State * L)
+{
+ int i;
+ const struct syslinux_ipappend_strings *ip_strs = syslinux_ipappend_strings();
+ lua_newtable(L);
+ for (i = 0; i < ip_strs->count; i++) {
+ lua_pushinteger(L, i + 1);
+ lua_pushstring(L, ip_strs->ptr[i]);
+ lua_settable(L,-3);
+ }
+ return 1;
}
static int sl_derivative(lua_State * L)
@@ -459,6 +489,9 @@ static const luaL_reg syslinuxlib[] = {
{"initramfs_load_archive", sl_initramfs_load_archive},
{"initramfs_add_file", sl_initramfs_add_file},
{"boot_it", sl_boot_it},
+ {"config_file", sl_config_file},
+ {"ipappend_strs", sl_ipappend_strs},
+ {"reboot", sl_reboot},
{"derivative", sl_derivative},
{"version", sl_version},
{NULL, NULL}