From: Manoel R. Abranches <> Date: Thu, 16 Sep 2010 19:57:31 +0000 (+0200) Subject: Merge grub_net into net. Compiles but is broken right now. X-Git-Tag: 2.00~1195^2~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7bb47706c9f41e70153a496d383cdd981d0fd8cd;p=thirdparty%2Fgrub.git Merge grub_net into net. Compiles but is broken right now. --- 7bb47706c9f41e70153a496d383cdd981d0fd8cd diff --cc grub-core/Makefile.core.def index bd5d78160,000000000..5cacb6851 mode 100644,000000..100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@@ -1,1383 -1,0 +1,1400 @@@ +AutoGen definitions Makefile.tpl; + +kernel = { + name = kernel; + + nostrip = emu; + + emu_ldflags = '-Wl,-r,-d'; + x86_efi_ldflags = '-Wl,-r,-d'; + x86_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment'; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_KERNEL_MACHINE_LINK_ADDR)'; + + i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_KERNEL_MACHINE_LINK_ADDR)'; + + i386_coreboot_ldflags = '-Wl,-Ttext=$(GRUB_KERNEL_MACHINE_LINK_ADDR)'; + i386_multiboot_ldflags = '-Wl,-Ttext=$(GRUB_KERNEL_MACHINE_LINK_ADDR)'; + i386_ieee1275_ldflags = '-Wl,-Ttext=$(GRUB_KERNEL_MACHINE_LINK_ADDR)'; + mips_yeeloong_ldflags = '-Wl,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR)'; + powerpc_ieee1275_ldflags = '-Wl,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR)'; + + mips_yeeloong_cppflags = '-DUSE_ASCII_FAILBACK'; + i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; + i386_qemu_ccasflags = '-DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)'; + emu_cflags = '$(CFLAGS_GNULIB)'; + emu_cppflags = '$(CPPFLAGS_GNULIB)'; + + mips_ldadd = '-lgcc'; + powerpc_ldadd = '-lgcc'; + sparc64_ldadd = '-lgcc'; + + i386_pc_startup = kern/i386/pc/startup.S; + i386_efi_startup = kern/i386/efi/startup.S; + x86_64_efi_startup = kern/x86_64/efi/startup.S; + i386_qemu_startup = kern/i386/qemu/startup.S; + i386_ieee1275_startup = kern/i386/ieee1275/startup.S; + i386_coreboot_startup = kern/i386/coreboot/startup.S; + i386_multiboot_startup = kern/i386/coreboot/startup.S; + mips_yeeloong_startup = kern/mips/startup.S; + sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S; + powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S; + + common = kern/command.c; + common = kern/corecmd.c; + common = kern/device.c; + common = kern/disk.c; + common = kern/dl.c; + common = kern/env.c; + common = kern/err.c; + common = kern/file.c; + common = kern/fs.c; + common = kern/list.c; + common = kern/main.c; + common = kern/misc.c; + common = kern/parser.c; + common = kern/partition.c; + common = kern/rescue_parser.c; + common = kern/rescue_reader.c; + common = kern/term.c; + + noemu = kern/mm.c; + noemu = kern/time.c; + noemu = kern/generic/millisleep.c; + + noemu_nodist = symlist.c; + + i386_pc = kern/generic/rtc_get_time_ms.c; + x86_efi = kern/generic/rtc_get_time_ms.c; + i386_qemu = kern/generic/rtc_get_time_ms.c; + i386_coreboot = kern/generic/rtc_get_time_ms.c; + i386_multiboot = kern/generic/rtc_get_time_ms.c; + mips_yeeloong = kern/generic/rtc_get_time_ms.c; + + ieee1275 = disk/ieee1275/ofdisk.c; + ieee1275 = kern/ieee1275/cmain.c; + ieee1275 = kern/ieee1275/ieee1275.c; + ieee1275 = kern/ieee1275/mmap.c; + ieee1275 = kern/ieee1275/openfw.c; + ieee1275 = term/ieee1275/ofconsole.c; + + ieee1275 = term/terminfo.c; + ieee1275 = term/tparm.c; + mips = term/terminfo.c; + mips = term/tparm.c; + + i386 = kern/i386/dl.c; + + i386_coreboot_multiboot_qemu = kern/i386/coreboot/init.c; + i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c; + + i386_coreboot_multiboot_qemu = term/i386/vga_common.c; + i386_pc = term/i386/vga_common.c; + + x86 = kern/i386/pit.c; + + x86_efi = disk/efi/efidisk.c; + x86_efi = kern/efi/efi.c; + x86_efi = kern/efi/init.c; + x86_efi = kern/efi/mm.c; + x86_efi = kern/i386/efi/init.c; + x86_efi = term/efi/console.c; + + i386_efi = kern/i386/tsc.c; + + x86_64_efi = kern/i386/tsc.c; + x86_64_efi = kern/x86_64/dl.c; + x86_64_efi = kern/x86_64/efi/callwrap.S; + + i386_pc = kern/i386/pc/init.c; + i386_pc = kern/i386/pc/mmap.c; + i386_pc = kern/i386/tsc.c; + i386_pc = term/i386/pc/console.c; + + i386_qemu = bus/pci.c; + i386_qemu = kern/i386/qemu/init.c; + i386_qemu = kern/i386/qemu/mmap.c; + i386_qemu = kern/i386/tsc.c; + + i386_coreboot = kern/i386/coreboot/mmap.c; + i386_coreboot = kern/i386/tsc.c; + + i386_multiboot = kern/i386/multiboot_mmap.c; + i386_multiboot = kern/i386/tsc.c; + + i386_ieee1275 = kern/ieee1275/init.c; + + mips_yeeloong = term/ns8250.c; + mips_yeeloong = bus/bonito.c; + mips_yeeloong = bus/cs5536.c; + mips_yeeloong = bus/pci.c; + mips_yeeloong = kern/mips/cache.S; + mips_yeeloong = kern/mips/dl.c; + mips_yeeloong = kern/mips/init.c; + mips_yeeloong = kern/mips/yeeloong/init.c; + mips_yeeloong = term/at_keyboard.c; + mips_yeeloong = term/serial.c; + mips_yeeloong = video/sm712.c; + + powerpc_ieee1275 = kern/ieee1275/init.c; + powerpc_ieee1275 = kern/powerpc/cache.S; + powerpc_ieee1275 = kern/powerpc/dl.c; + + sparc64_ieee1275 = kern/sparc64/cache.S; + sparc64_ieee1275 = kern/sparc64/dl.c; + sparc64_ieee1275 = kern/sparc64/ieee1275/ieee1275.c; + sparc64_ieee1275 = kern/sparc64/ieee1275/init.c; + + emu = disk/host.c; + emu = gnulib/progname.c; + emu = kern/emu/console.c; + emu = kern/emu/getroot.c; + emu = kern/emu/hostdisk.c; + emu = kern/emu/hostfs.c; + emu = kern/emu/main.c; + emu = kern/emu/misc.c; + emu = kern/emu/mm.c; + emu = kern/emu/time.c; + + videoinkernel = lib/arg.c; + videoinkernel = term/gfxterm.c; + videoinkernel = commands/extcmd.c; + videoinkernel = font/font.c; + videoinkernel = font/font_cmd.c; + videoinkernel = io/bufio.c; + videoinkernel = video/bitmap.c; + videoinkernel = video/bitmap_scale.c; + videoinkernel = video/fb/fbblit.c; + videoinkernel = video/fb/fbfill.c; + videoinkernel = video/fb/fbutil.c; + videoinkernel = video/fb/video_fb.c; + videoinkernel = video/video.c; + + extra_dist = kern/i386/realmode.S; + extra_dist = kern/i386/pc/lzma_decode.S; + extra_dist = kern/mips/cache_flush.S; +}; + +program = { + name = grub-emu; + mansection = 1; + + emu = kern/emu/full.c; + emu_nodist = grub_emu_init.c; + + ldadd = 'kernel.img$(EXEEXT)'; + ldadd = '$(MODULE_FILES)'; + ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER)'; + + enable = emu; +}; + +program = { + name = grub-emu-lite; + + emu = kern/emu/lite.c; + emu = kern/emu/cache.S; + emu_nodist = symlist.c; + + ldadd = 'kernel.img$(EXEEXT)'; + ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER)'; + + enable = emu; +}; + +image = { + name = boot; + i386_pc = boot/i386/pc/boot.S; + i386_qemu = boot/i386/qemu/boot.S; + sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + + i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)'; + i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; + + sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big'; + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000'; + + objcopyflags = '-O binary'; + enable = i386_pc; + enable = i386_qemu; + enable = sparc64_ieee1275; +}; + +image = { + name = cdboot; + i386_pc = boot/i386/pc/cdboot.S; + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + objcopyflags = '-O binary'; + enable = i386_pc; +}; + +image = { + name = pxeboot; + i386_pc = boot/i386/pc/pxeboot.S; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + + objcopyflags = '-O binary'; + enable = i386_pc; +}; + +image = { + name = diskboot; + i386_pc = boot/i386/pc/diskboot.S; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8000'; + + sparc64_ieee1275 = boot/sparc64/ieee1275/diskboot.S; + sparc64_ieee1275_ldflags = '-Wl,-Ttext=0x4200'; + + objcopyflags = '-O binary'; + + enable = i386_pc; + enable = sparc64_ieee1275; +}; + +image = { + name = lnxboot; + i386_pc = boot/i386/pc/lnxboot.S; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x6000'; + + objcopyflags = '-O binary'; + enable = i386_pc; +}; + +image = { + name = fwstart; + mips_yeeloong = boot/mips/yeeloong/fwstart.S; + objcopyflags = '-O binary'; + enable = mips_yeeloong; +}; + +module = { + name = trig; + common_nodist = trigtables.c; + extra_dist = gentrigtables.c; +}; + +module = { + name = cs5536; + x86 = bus/cs5536.c; + enable = x86; +}; + +module = { + name = libusb; + emu = bus/usb/emu/usb.c; + enable = emu; + condition = COND_GRUB_EMU_USB; +}; + +module = { + name = lsspd; + mips_yeeloong = commands/mips/yeeloong/lsspd.c; + enable = mips_yeeloong; +}; + +module = { + name = usb; + common = bus/usb/usb.c; + noemu = bus/usb/usbtrans.c; + noemu = bus/usb/usbhub.c; + enable = emu; + enable = usb; + emu_condition = COND_GRUB_EMU_USB; +}; + +module = { + name = usbserial_common; + common = bus/usb/serial/common.c; + enable = emu; + enable = usb; + emu_condition = COND_GRUB_EMU_USB; +}; + +module = { + name = usbserial_pl2303; + common = bus/usb/serial/pl2303.c; + enable = emu; + enable = usb; + emu_condition = COND_GRUB_EMU_USB; +}; + +module = { + name = usbserial_ftdi; + common = bus/usb/serial/ftdi.c; + enable = emu; + enable = usb; + emu_condition = COND_GRUB_EMU_USB; +}; + +module = { + name = uhci; + common = bus/usb/uhci.c; + enable = x86; +}; + +module = { + name = ohci; + common = bus/usb/ohci.c; + enable = pci; +}; + +module = { + name = pci; + noemu = bus/pci.c; + emu = bus/emu/pci.c; + emu = commands/lspci.c; + + enable = emu; + enable = i386_pc; + enable = x86_efi; + enable = i386_ieee1275; + enable = i386_coreboot; + enable = i386_multiboot; + emu_condition = COND_GRUB_EMU_PCI; +}; + +library = { + name = libgnulib.a; + common = gnulib/regex.c; + + extra_dist = gnulib/regcomp.c; + extra_dist = gnulib/regexec.c; + extra_dist = gnulib/fnmatch_loop.c; + extra_dist = gnulib/regex_internal.c; + + cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; +}; + +module = { + name = cmostest; + common = commands/i386/cmostest.c; + enable = cmos; +}; + +module = { + name = iorw; + common = commands/iorw.c; + enable = x86; +}; + +module = { + name = regexp; + common = commands/regexp.c; + ldadd = libgnulib.a; + cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; +}; + +module = { + name = acpi; + + x86 = commands/acpi.c; + x86_efi = commands/efi/acpi.c; + i386_pc = commands/i386/pc/acpi.c; + i386_coreboot = commands/i386/pc/acpi.c; + i386_multiboot = commands/i386/pc/acpi.c; + + enable = x86_efi; + enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; +}; + +module = { + name = blocklist; + common = commands/blocklist.c; +}; + +module = { + name = boot; + common = commands/boot.c; + i386_pc = lib/i386/pc/biosnum.c; +}; + +module = { + name = cat; + common = commands/cat.c; +}; + +module = { + name = cmp; + common = commands/cmp.c; +}; + +module = { + name = configfile; + common = commands/configfile.c; +}; + +module = { + name = cpuid; + x86 = commands/i386/cpuid.c; + enable = x86; +}; + +module = { + name = crc; + common = commands/crc.c; + common = lib/crc.c; +}; + +module = { + name = date; + common = commands/date.c; +}; + +module = { + name = drivemap; + + i386_pc = commands/i386/pc/drivemap.c; + i386_pc = commands/i386/pc/drivemap_int13h.S; + enable = i386_pc; +}; + +module = { + name = echo; + common = commands/echo.c; +}; + +module = { + name = extcmd; + common = commands/extcmd.c; + common = lib/arg.c; +}; + +module = { + name = fixvideo; + x86_efi = commands/efi/fixvideo.c; + enable = x86_efi; +}; + +module = { + name = gptsync; + common = commands/gptsync.c; +}; + +module = { + name = halt; + nopc = commands/halt.c; + i386_pc = commands/i386/pc/halt.c; + i386_multiboot = lib/i386/halt.c; + i386_coreboot = lib/i386/halt.c; + i386_qemu = lib/i386/halt.c; + x86_efi = lib/efi/halt.c; + ieee1275 = lib/ieee1275/halt.c; + emu = lib/emu/halt.c; +}; + +module = { + name = hashsum; + common = commands/hashsum.c; +}; + +module = { + name = hdparm; + common = commands/hdparm.c; + common = lib/hexdump.c; + enable = pci; +}; + +module = { + name = help; + common = commands/help.c; +}; + +module = { + name = hexdump; + common = commands/hexdump.c; + common = lib/hexdump.c; +}; + +module = { + name = keystatus; + common = commands/keystatus.c; +}; + +module = { + name = loadbios; + x86_efi = commands/efi/loadbios.c; + enable = x86_efi; +}; + +module = { + name = loadenv; + common = commands/loadenv.c; + common = lib/envblk.c; +}; + +module = { + name = ls; + common = commands/ls.c; +}; + +module = { + name = lsmmap; + common = commands/lsmmap.c; +}; + +module = { + name = lspci; + common = commands/lspci.c; + + enable = pci; +}; + +module = { + name = memrw; + common = commands/memrw.c; +}; + +module = { + name = minicmd; + common = commands/minicmd.c; +}; + +module = { + name = parttool; + common = commands/parttool.c; +}; + +module = { + name = password; + common = commands/password.c; +}; + +module = { + name = password_pbkdf2; + common = commands/password_pbkdf2.c; +}; + +module = { + name = play; + x86 = commands/i386/pc/play.c; + enable = x86; +}; + +module = { + name = probe; + common = commands/probe.c; +}; + +module = { + name = pxecmd; + i386_pc = commands/i386/pc/pxecmd.c; + enable = i386_pc; +}; + +module = { + name = read; + common = commands/read.c; +}; + +module = { + name = reboot; + common = commands/reboot.c; +}; + +module = { + name = search; + common = commands/search_wrap.c; + extra_dist = commands/search.c; +}; + +module = { + name = search_fs_file; + common = commands/search_file.c; +}; + +module = { + name = search_fs_uuid; + common = commands/search_uuid.c; +}; + +module = { + name = search_label; + common = commands/search_label.c; +}; + +module = { + name = setpci; + common = commands/setpci.c; + enable = x86; +}; + +module = { + name = sleep; + common = commands/sleep.c; +}; + +module = { + name = suspend; + ieee1275 = commands/ieee1275/suspend.c; + enable = i386_ieee1275; + enable = powerpc_ieee1275; +}; + +module = { + name = terminal; + common = commands/terminal.c; +}; + +module = { + name = test; + common = commands/test.c; +}; + +module = { + name = true; + common = commands/true.c; +}; + +module = { + name = usbtest; + common = commands/usbtest.c; + enable = usb; + enable = emu; + emu_condition = COND_GRUB_EMU_USB; +}; + +module = { + name = vbeinfo; + i386_pc = commands/i386/pc/vbeinfo.c; + enable = i386_pc; +}; + +module = { + name = vbetest; + i386_pc = commands/i386/pc/vbetest.c; + enable = i386_pc; +}; + +module = { + name = videotest; + common = commands/videotest.c; +}; + +module = { + name = xnu_uuid; + common = commands/xnu_uuid.c; +}; + +module = { + name = dm_nv; + common = disk/dmraid_nvidia.c; +}; + +module = { + name = loopback; + common = disk/loopback.c; +}; + +module = { + name = lvm; + common = disk/lvm.c; +}; + +module = { + name = mdraid; + common = disk/mdraid_linux.c; +}; + +module = { + name = raid; + common = disk/raid.c; +}; + +module = { + name = raid5rec; + common = disk/raid5_recover.c; +}; + +module = { + name = raid6rec; + common = disk/raid6_recover.c; +}; + +module = { + name = scsi; + common = disk/scsi.c; +}; + +module = { + name = memdisk; + common = disk/memdisk.c; +}; + +module = { + name = ata; + common = disk/ata.c; + enable = pci; +}; + +module = { + name = ata_pthru; + common = disk/ata_pthru.c; + enable = pci; +}; + +module = { + name = biosdisk; + i386_pc = disk/i386/pc/biosdisk.c; + enable = i386_pc; +}; + +module = { + name = usbms; + common = disk/usbms.c; + enable = usb; + enable = emu; + emu_condition = COND_GRUB_EMU_USB; +}; + +module = { + name = nand; + ieee1275 = disk/ieee1275/nand.c; + enable = i386_ieee1275; +}; + +module = { + name = efiemu; + common = efiemu/main.c; + common = efiemu/i386/loadcore32.c; + common = efiemu/i386/loadcore64.c; + i386_pc = efiemu/i386/pc/cfgtables.c; + i386_coreboot = efiemu/i386/pc/cfgtables.c; + i386_multiboot = efiemu/i386/pc/cfgtables.c; + i386_ieee1275 = efiemu/i386/nocfgtables.c; + i386_qemu = efiemu/i386/nocfgtables.c; + common = efiemu/mm.c; + common = efiemu/loadcore_common.c; + common = efiemu/symbols.c; + common = efiemu/loadcore32.c; + common = efiemu/loadcore64.c; + common = efiemu/prepare32.c; + common = efiemu/prepare64.c; + common = efiemu/pnvram.c; + common = efiemu/i386/coredetect.c; + + extra_dist = efiemu/prepare.c; + extra_dist = efiemu/loadcore.c; + extra_dist = efiemu/runtime/efiemu.S; + extra_dist = efiemu/runtime/efiemu.c; + + enable = i386_pc; + enable = i386_coreboot; + enable = i386_ieee1275; + enable = i386_multiboot; + enable = i386_qemu; +}; + +module = { + name = font; + common = font/font.c; + common = font/font_cmd.c; + enable = videomodules; +}; + +module = { + name = affs; + common = fs/affs.c; +}; + +module = { + name = afs; + common = fs/afs.c; +}; + +module = { + name = afs_be; + common = fs/afs_be.c; +}; + +module = { + name = befs; + common = fs/befs.c; +}; + +module = { + name = befs_be; + common = fs/befs_be.c; +}; + +module = { + name = cpio; + common = fs/cpio.c; +}; + +module = { + name = ext2; + common = fs/ext2.c; +}; + +module = { + name = fat; + common = fs/fat.c; +}; + +module = { + name = fshelp; + common = fs/fshelp.c; +}; + +module = { + name = hfs; + common = fs/hfs.c; +}; + +module = { + name = hfsplus; + common = fs/hfsplus.c; +}; + +module = { + name = iso9660; + common = fs/iso9660.c; +}; + +module = { + name = jfs; + common = fs/jfs.c; +}; + +module = { + name = minix; + common = fs/minix.c; +}; + +module = { + name = nilfs2; + common = fs/nilfs2.c; +}; + +module = { + name = ntfs; + common = fs/ntfs.c; +}; + +module = { + name = ntfscomp; + common = fs/ntfscomp.c; +}; + +module = { + name = reiserfs; + common = fs/reiserfs.c; +}; + +module = { + name = sfs; + common = fs/sfs.c; +}; + +module = { + name = tar; + common = fs/tar.c; +}; + +module = { + name = udf; + common = fs/udf.c; +}; + +module = { + name = ufs1; + common = fs/ufs.c; +}; + +module = { + name = ufs2; + common = fs/ufs2.c; +}; + +module = { + name = xfs; + common = fs/xfs.c; +}; + +module = { + name = pxe; + i386_pc = net/i386/pc/pxe.c; + enable = i386_pc; +}; + +module = { + name = gettext; + common = gettext/gettext.c; +}; + +module = { + name = gfxmenu; + common = gfxmenu/gfxmenu.c; + common = gfxmenu/model.c; + common = gfxmenu/view.c; + common = gfxmenu/font.c; + common = gfxmenu/icon_manager.c; + common = gfxmenu/theme_loader.c; + common = gfxmenu/widget-box.c; + common = gfxmenu/gui_canvas.c; + common = gfxmenu/gui_circular_progress.c; + common = gfxmenu/gui_box.c; + common = gfxmenu/gui_label.c; + common = gfxmenu/gui_list.c; + common = gfxmenu/gui_image.c; + common = gfxmenu/gui_progress_bar.c; + common = gfxmenu/gui_util.c; + common = gfxmenu/gui_string_util.c; + common = gfxmenu/named_colors.c; +}; + +module = { + name = hello; + common = hello/hello.c; +}; + +module = { + name = gzio; + common = io/gzio.c; +}; + +module = { + name = bufio; + common = io/bufio.c; + enable = videomodules; +}; + +module = { + name = elf; + common = kern/elf.c; +}; + +module = { + name = crypto; + common = lib/crypto.c; + + extra_dist = lib/libgcrypt-grub/cipher/crypto.lst; +}; + +module = { + name = pbkdf2; + common = lib/pbkdf2.c; +}; + +module = { + name = relocator; + common = lib/relocator.c; + x86 = lib/i386/relocator16.S; + x86 = lib/i386/relocator32.S; + x86 = lib/i386/relocator64.S; + i386 = lib/i386/relocator_asm.S; + x86_64 = lib/x86_64/relocator_asm.S; + x86 = lib/i386/relocator.c; + ieee1275 = lib/ieee1275/relocator.c; + x86_efi = lib/efi/relocator.c; + mips = lib/mips/relocator_asm.S; + mips = lib/mips/relocator.c; + powerpc = lib/powerpc/relocator_asm.S; + powerpc = lib/powerpc/relocator.c; + + enable = mips; + enable = powerpc; + enable = x86; +}; + +module = { + name = datetime; + cmos = lib/cmos_datetime.c; + x86_efi = lib/efi/datetime.c; + sparc64_ieee1275 = lib/ieee1275/datetime.c; + powerpc_ieee1275 = lib/ieee1275/datetime.c; + enable = noemu; +}; + +module = { + name = setjmp; + common = lib/setjmp.S; + extra_dist = lib/i386/setjmp.S; + extra_dist = lib/mips/setjmp.S; + extra_dist = lib/x86_64/setjmp.S; + extra_dist = lib/sparc64/setjmp.S; + extra_dist = lib/powerpc/setjmp.S; +}; + +module = { + name = aout; + common = loader/aout.c; + enable = x86; +}; + +module = { + name = bsd; + x86 = loader/i386/bsd.c; + x86 = loader/i386/bsd32.c; + x86 = loader/i386/bsd64.c; + + extra_dist = loader/i386/bsdXX.c; + extra_dist = loader/i386/bsd_pagetable.c; + + enable = x86; +}; + +module = { + name = linux16; + i386_pc = loader/i386/pc/linux.c; + enable = i386_pc; +}; + +module = { + name = ntldr; + i386_pc = loader/i386/pc/ntldr.c; + enable = i386_pc; +}; + +module = { + name = multiboot2; + cppflags = "-DGRUB_USE_MULTIBOOT2"; + + common = loader/multiboot.c; + common = loader/multiboot_mbi2.c; + enable = x86; + enable = mips; +}; + +module = { + name = multiboot; + common = loader/multiboot.c; + x86 = loader/i386/multiboot_mbi.c; + extra_dist = loader/multiboot_elfxx.c; + enable = x86; +}; + +module = { + name = linux; + x86 = loader/i386/linux.c; + mips = loader/mips/linux.c; + powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c; + sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; + enable = noemu; +}; + +module = { + name = xnu; + x86 = loader/xnu_resume.c; + x86 = loader/i386/xnu.c; + x86 = loader/macho32.c; + x86 = loader/macho64.c; + x86 = loader/macho.c; + x86 = loader/xnu.c; + + extra_dist = loader/machoXX.c; + enable = x86; +}; + +module = { + name = appleldr; + x86_efi = loader/efi/appleloader.c; + enable = x86_efi; +}; + +module = { + name = chain; + x86_efi = loader/efi/chainloader.c; + i386_pc = loader/i386/pc/chainloader.c; + enable = i386_pc; + enable = x86_efi; +}; + +module = { + name = mmap; + common = mmap/mmap.c; + x86 = mmap/i386/uppermem.c; + x86 = mmap/i386/mmap.c; + + i386_pc = mmap/i386/pc/mmap.c; + i386_pc = mmap/i386/pc/mmap_helper.S; + + x86_efi = mmap/efi/mmap.c; + + mips_yeeloong = mmap/mips/yeeloong/uppermem.c; + + enable = x86; + enable = mips_yeeloong; +}; + +module = { + name = normal; + common = normal/main.c; + common = normal/cmdline.c; + common = normal/dyncmd.c; + common = normal/auth.c; + common = normal/autofs.c; + common = normal/color.c; + common = normal/completion.c; + common = normal/datetime.c; + common = normal/menu.c; + common = normal/menu_entry.c; + common = normal/menu_text.c; + common = normal/misc.c; + common = normal/crypto.c; + common = normal/term.c; + common = normal/context.c; + common = normal/charset.c; + + common = script/main.c; + common = script/script.c; + common = script/execute.c; + common = script/function.c; + common = script/lexer.c; + common = script/argv.c; + + common = unidata.c; + common_nodist = grub_script.tab.c; + common_nodist = grub_script.yy.c; + common_nodist = grub_script.tab.h; + common_nodist = grub_script.yy.h; + + extra_dist = script/yylex.l; + extra_dist = script/parser.y; + + cflags = '$(CFLAGS_POSIX) -Wno-error'; + cppflags = '$(CPPFLAGS_POSIX)'; +}; + +module = { + name = part_acorn; + common = partmap/acorn.c; +}; + +module = { + name = part_amiga; + common = partmap/amiga.c; +}; + +module = { + name = part_apple; + common = partmap/apple.c; +}; + +module = { + name = part_gpt; + common = partmap/gpt.c; +}; + +module = { + name = part_msdos; + common = partmap/msdos.c; +}; + +module = { + name = part_sun; + common = partmap/sun.c; +}; + +module = { + name = part_bsd; + common = partmap/bsdlabel.c; +}; + +module = { + name = part_sunpc; + common = partmap/sunpc.c; +}; + +module = { + name = msdospart; + common = parttool/msdospart.c; +}; + +module = { + name = at_keyboard; + common = term/at_keyboard.c; + enable = x86; +}; + +module = { + name = gfxterm; + common = term/gfxterm.c; + enable = videomodules; +}; + +module = { + name = serial; + common = term/serial.c; + x86 = term/ns8250.c; + + enable = emu; + enable = i386; + enable = x86_64_efi; + emu_condition = COND_GRUB_EMU_USB; +}; + +module = { + name = sendkey; + i386_pc = commands/i386/pc/sendkey.c; + enable = i386_pc; +}; + +module = { + name = terminfo; + common = term/terminfo.c; + common = term/tparm.c; +}; + +module = { + name = usb_keyboard; + common = term/usb_keyboard.c; + enable = usb; +}; + +module = { + name = vga; + i386_pc = video/i386/pc/vga.c; + enable = i386_pc; +}; + +module = { + name = vga_text; + common = term/i386/pc/vga_text.c; + common = term/i386/vga_common.c; + enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; +}; + +module = { + name = video_cirrus; + x86 = video/cirrus.c; + enable = x86; +}; + +module = { + name = video_bochs; + x86 = video/bochs.c; + enable = x86; +}; + +module = { + name = functional_test; + common = tests/lib/functional_test.c; + common = tests/lib/test.c; +}; + +module = { + name = example_functional_test; + common = tests/example_functional_test.c; + cflags = -Wno-format; +}; + +module = { + name = bitmap; + common = video/bitmap.c; + enable = videomodules; +}; + +module = { + name = bitmap_scale; + common = video/bitmap_scale.c; + enable = videomodules; +}; + +module = { + name = efi_gop; + x86_efi = video/efi_gop.c; + enable = x86_efi; +}; + +module = { + name = efi_uga; + x86_efi = video/efi_uga.c; + enable = x86_efi; +}; + +module = { + name = jpeg; + common = video/readers/jpeg.c; +}; + +module = { + name = png; + common = video/readers/png.c; +}; + +module = { + name = tga; + common = video/readers/tga.c; +}; + +module = { + name = vbe; + i386_pc = video/i386/pc/vbe.c; + enable = i386_pc; +}; + +module = { + name = video_fb; + common = video/fb/video_fb.c; + common = video/fb/fbblit.c; + common = video/fb/fbfill.c; + common = video/fb/fbutil.c; + enable = videomodules; +}; + +module = { + name = video; + common = video/video.c; + enable = videomodules; +}; + +module = { + name = ieee1275_fb; + ieee1275 = video/ieee1275.c; + enable = powerpc; + enable = sparc64; +}; + +module = { + name = sdl; + emu = video/emu/sdl.c; + enable = emu; + condition = COND_GRUB_EMU_SDL; +}; + +module = { + name = datehook; + common = hook/datehook.c; +}; + +module = { + name = net; + common = net/net.c; - }; ++ common = net/ip.c; ++ common = net/udp.c; ++ common = net/ethernet.c; ++ common = net/arp.c; ++ common = net/interface.c; ++ common = net/netbuff.c; ++}; ++ ++module = { ++ name = tftp; ++ common = net/tftp.c; ++}; ++ ++module = { ++ name = ofnet; ++ ieee1275 = net/drivers/ieee1275/ofnet.c; ++ enable = ieee1275; ++}; diff --cc grub-core/kern/ieee1275/openfw.c index fcd43f617,2650ff3d4..6670804b7 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@@ -420,6 -434,123 +434,7 @@@ voi grub_reboot (void) { grub_ieee1275_interpret ("reset-all", 0); + for (;;) ; } #endif + -void -grub_halt (void) -{ - /* Not standardized. We try three known commands. */ - - grub_ieee1275_interpret ("shut-down", 0); - grub_ieee1275_interpret ("power-off", 0); - grub_ieee1275_interpret ("poweroff", 0); -} - -static const struct -{ - char *name; - int offset; -} - -bootp_response_properties[] = -{ - { .name = "bootp-response", .offset = 0 }, - { .name = "dhcp-response", .offset = 0 }, - { .name = "bootpreply-packet", .offset = 0x2a }, -}; - -#define SIZE(X) ( sizeof (X) / sizeof(X[0])) - -grub_bootp_t -grub_getbootp( void ) -{ - grub_bootp_t packet = grub_malloc(sizeof *packet); - void *bootp_response = NULL; - grub_ssize_t size; - unsigned int i; - // grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen); - for ( i = 0; i < SIZE(bootp_response_properties); i++) - { - if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, - bootp_response_properties[i].name, &size)>=0) - break; - } - - if ( size <0 ) - { - grub_printf("Error to get bootp\n"); - return NULL; - } - - if (grub_ieee1275_get_property (grub_ieee1275_chosen, bootp_response_properties[i].name , bootp_response , - size, 0) < 0) - { - grub_printf("Error to get bootp\n"); - return NULL; - } - - packet = (void *) ((int)bootp_response + bootp_response_properties[i].offset); - return packet; -} - -void grub_ofnet_findcards (void) -{ - struct grub_net_card *card; - int i = 0; - - auto int search_net_devices (struct grub_ieee1275_devalias *alias); - - int search_net_devices (struct grub_ieee1275_devalias *alias) - { - if ( !grub_strcmp (alias->type,"network") ) - { - - card = grub_malloc (sizeof (struct grub_net_card)); - struct grub_ofnetcard_data *ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data)); - ofdata->path = grub_strdup (alias->path); - card->data = ofdata; - card->name = grub_xasprintf("eth%d",i++); // grub_strdup (alias->name); - grub_net_card_register (card); - } - return 0; - } - - /*Look at all nodes for devices of the type network*/ - grub_ieee1275_devices_iterate (search_net_devices); - -} - -void grub_ofnet_probecards (void) -{ - struct grub_net_card *card; - struct grub_net_card_driver *driver; - - /*Assign correspondent driver for each device. */ - FOR_NET_CARDS (card) - { - FOR_NET_CARD_DRIVERS (driver) - { - if (driver->init(card) == GRUB_ERR_NONE) - { - card->driver = driver; - continue; - } - } - } -} - -void -grub_ofnet_init(void) -{ - - ofdriver_ini(); - grub_ofnet_findcards(); - grub_ofnet_probecards(); - - /*init tftp stack - will be handled by module subsystem in the future*/ - tftp_ini (); - /*get bootp packet - won't be needed in the future*/ - bootp_pckt = grub_getbootp (); - grub_disknet_init(); -} diff --cc grub-core/net/arp.c index 000000000,000000000..5e10938ae new file mode 100644 --- /dev/null +++ b/grub-core/net/arp.c @@@ -1,0 -1,0 +1,158 @@@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++static struct arp_entry arp_table[SIZE_ARP_TABLE]; ++static grub_int8_t new_table_entry = -1; ++ ++static ++void arp_init_table(void) ++{ ++ grub_memset (arp_table, 0, sizeof (arp_table)); ++ new_table_entry = 0; ++} ++ ++static struct arp_entry * ++arp_find_entry (const grub_net_network_level_address_t *proto) ++{ ++ grub_uint8_t i; ++ for(i=0;i < SIZE_ARP_TABLE; i++) ++ { ++ if(arp_table[i].avail == 1 && ++ arp_table[i].nl_address.ipv4 == proto->ipv4) ++ return &(arp_table[i]); ++ } ++ return NULL; ++} ++ ++grub_err_t ++grub_net_arp_resolve(struct grub_net_network_level_interface *inf, ++ const grub_net_network_level_address_t *proto_addr, ++ grub_net_link_level_address_t *hw_addr) ++{ ++ struct arp_entry *entry; ++ struct grub_net_buff *nb; ++ struct arphdr *arp_header; ++ grub_net_link_level_address_t target_hw_addr; ++ grub_uint8_t *aux, i; ++ ++ /* Check cache table */ ++ entry = arp_find_entry (proto_addr); ++ if (entry) ++ { ++ *hw_addr = entry->ll_address; ++ return GRUB_ERR_NONE; ++ } ++ /* Build a request packet */ ++ nb = grub_malloc (2048); ++ grub_netbuff_reserve(nb, 2048); ++ grub_netbuff_push(nb, sizeof(*arp_header) + 2 * (6 + 6)); ++ arp_header = (struct arphdr *)nb->data; ++ arp_header->hrd = 0; ++ arp_header->pro = 0; ++ arp_header->hln = 6; ++ arp_header->pln = 6; ++ arp_header->op = ARP_REQUEST; ++ aux = (grub_uint8_t *)arp_header + sizeof(*arp_header); ++ /* Sender hardware address */ ++ grub_memcpy(aux, &inf->hwaddress.mac, 6); ++ aux += 6; ++ /* Sender protocol address */ ++ grub_memcpy(aux, &inf->address.ipv4, 4); ++ aux += 6; ++ /* Target hardware address */ ++ for(i=0; i < 6; i++) ++ aux[i] = 0x00; ++ aux += 6; ++ /* Target protocol address */ ++ grub_memcpy(aux, &proto_addr->ipv4, 4); ++ ++ grub_memset (&target_hw_addr.mac, 0xff, 6); ++ ++ send_ethernet_packet (inf, nb, target_hw_addr, ARP_ETHERTYPE); ++ grub_netbuff_clear(nb); ++ grub_netbuff_reserve(nb, 2048); ++ ++ grub_uint64_t start_time, current_time; ++ start_time = grub_get_time_ms(); ++ do ++ { ++ grub_net_recv_ethernet_packet (inf, nb, ARP_ETHERTYPE); ++ /* Now check cache table again */ ++ entry = arp_find_entry(proto_addr); ++ if (entry) ++ { ++ grub_memcpy(hw_addr, &entry->ll_address, sizeof (*hw_addr)); ++ grub_netbuff_clear(nb); ++ return GRUB_ERR_NONE; ++ } ++ current_time = grub_get_time_ms(); ++ if (current_time - start_time > TIMEOUT_TIME_MS) ++ break; ++ } while (! entry); ++ grub_netbuff_clear(nb); ++ return grub_error (GRUB_ERR_TIMEOUT, "Timeout: could not resolve hardware address."); ++} ++ ++grub_err_t ++grub_net_arp_receive(struct grub_net_network_level_interface *inf, ++ struct grub_net_buff *nb) ++{ ++ struct arphdr *arp_header = (struct arphdr *)nb->data; ++ struct arp_entry *entry; ++ grub_uint8_t merge = 0; ++ grub_uint8_t *sender_hardware_address, *sender_protocol_address; ++ grub_uint8_t *target_hardware_address, *target_protocol_address; ++ grub_net_network_level_address_t hwaddress; ++ ++ sender_hardware_address = (grub_uint8_t *)arp_header + sizeof(*arp_header); ++ sender_protocol_address = sender_hardware_address + arp_header->hln; ++ target_hardware_address = sender_protocol_address + arp_header->pln; ++ target_protocol_address = target_hardware_address + arp_header->hln; ++ grub_memcpy (&hwaddress.ipv4, sender_protocol_address, 4); ++ /* Check if the sender is in the cache table */ ++ entry = arp_find_entry(&hwaddress); ++ /* Update sender hardware address */ ++ if (entry) ++ { ++ grub_memcpy(entry->ll_address.mac, sender_hardware_address, 6); ++ merge = 1; ++ } ++ /* Am I the protocol address target? */ ++ if (! grub_memcmp(target_protocol_address, inf->hwaddress.mac, 6)) ++ { ++ /* Add sender to cache table */ ++ if (! merge) ++ { ++ if (new_table_entry == -1) ++ arp_init_table(); ++ entry = &(arp_table[new_table_entry]); ++ entry->avail = 1; ++ grub_memcpy(&entry->nl_address.ipv4, sender_protocol_address, 4); ++ grub_memcpy(entry->ll_address.mac, sender_hardware_address, 6); ++ new_table_entry++; ++ if (new_table_entry == SIZE_ARP_TABLE) ++ new_table_entry = 0; ++ } ++ if (arp_header->op == ARP_REQUEST) ++ { ++ grub_net_link_level_address_t aux; ++ /* Swap hardware fields */ ++ grub_memcpy(target_hardware_address, sender_hardware_address, arp_header->hln); ++ grub_memcpy(sender_hardware_address, inf->hwaddress.mac, 6); ++ grub_memcpy(aux.mac, sender_protocol_address, 6); ++ grub_memcpy(sender_protocol_address, target_protocol_address, arp_header->pln); ++ grub_memcpy(target_protocol_address, aux.mac, arp_header->pln); ++ /* Change operation to REPLY and send packet */ ++ arp_header->op = ARP_REPLY; ++ grub_memcpy (aux.mac, target_hardware_address, 6); ++ send_ethernet_packet (inf, nb, aux, ARP_ETHERTYPE); ++ } ++ } ++ return GRUB_ERR_NONE; ++} diff --cc grub-core/net/device.c index 000000000,e69de29bb..e69de29bb mode 000000,100644..100644 --- a/grub-core/net/device.c +++ b/grub-core/net/device.c diff --cc grub-core/net/drivers/ieee1275/ofnet.c index 000000000,000000000..064f3d280 new file mode 100644 --- /dev/null +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@@ -1,0 -1,0 +1,175 @@@ ++#include ++#include ++#include ++#include ++ ++static ++grub_err_t card_open (struct grub_net_card *dev) ++{ ++ ++ struct grub_ofnetcard_data *data = dev->data; ++ return grub_ieee1275_open (data->path,&(data->handle)); ++} ++ ++static ++grub_err_t card_close (struct grub_net_card *dev) ++{ ++ ++ struct grub_ofnetcard_data *data = dev->data; ++ ++ if (data->handle) ++ grub_ieee1275_close (data->handle); ++ return GRUB_ERR_NONE; ++} ++ ++static ++grub_err_t send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) ++{ ++ ++ int actual; ++ struct grub_ofnetcard_data *data = dev->data; ++ ++ return grub_ieee1275_write (data->handle,pack->data,pack->tail - pack->data,&actual); ++} ++ ++static ++grub_err_t get_card_packet (struct grub_net_card *dev, struct grub_net_buff *pack) ++{ ++ ++ int actual, rc; ++ struct grub_ofnetcard_data *data = dev->data; ++ grub_netbuff_clear(pack); ++ ++ do ++ { ++ rc = grub_ieee1275_read (data->handle,pack->data,1500,&actual); ++ ++ }while (actual <= 0 || rc < 0); ++ grub_netbuff_put (pack, actual); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static struct grub_net_card_driver ofdriver = ++{ ++ .name = "ofnet", ++ .init = card_open, ++ .fini = card_close, ++ .send = send_card_buffer, ++ .recv = get_card_packet ++}; ++ ++static const struct ++{ ++ char *name; ++ int offset; ++} ++ ++bootp_response_properties[] = ++{ ++ { .name = "bootp-response", .offset = 0 }, ++ { .name = "dhcp-response", .offset = 0 }, ++ { .name = "bootpreply-packet", .offset = 0x2a }, ++}; ++ ++ ++grub_bootp_t ++grub_getbootp( void ) ++{ ++ grub_bootp_t packet = grub_malloc(sizeof *packet); ++ void *bootp_response = NULL; ++ grub_ssize_t size; ++ unsigned int i; ++ ++ for ( i = 0; i < ARRAY_SIZE (bootp_response_properties); i++) ++ if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, ++ bootp_response_properties[i].name, ++ &size) >= 0) ++ break; ++ ++ if (size < 0) ++ { ++ grub_printf("Error to get bootp\n"); ++ return NULL; ++ } ++ ++ if (grub_ieee1275_get_property (grub_ieee1275_chosen, ++ bootp_response_properties[i].name, ++ bootp_response , ++ size, 0) < 0) ++ { ++ grub_printf("Error to get bootp\n"); ++ return NULL; ++ } ++ ++ packet = (void *) ((int)bootp_response ++ + bootp_response_properties[i].offset); ++ return packet; ++} ++ ++void grub_ofnet_findcards (void) ++{ ++ struct grub_net_card *card; ++ int i = 0; ++ ++ auto int search_net_devices (struct grub_ieee1275_devalias *alias); ++ ++ int search_net_devices (struct grub_ieee1275_devalias *alias) ++ { ++ if ( !grub_strcmp (alias->type,"network") ) ++ { ++ ++ card = grub_malloc (sizeof (struct grub_net_card)); ++ struct grub_ofnetcard_data *ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data)); ++ ofdata->path = grub_strdup (alias->path); ++ card->data = ofdata; ++ card->name = grub_xasprintf("eth%d",i++); // grub_strdup (alias->name); ++ grub_net_card_register (card); ++ } ++ return 0; ++ } ++ ++ /*Look at all nodes for devices of the type network*/ ++ grub_ieee1275_devices_iterate (search_net_devices); ++ ++} ++ ++void grub_ofnet_probecards (void) ++{ ++ struct grub_net_card *card; ++ struct grub_net_card_driver *driver; ++ ++ /*Assign correspondent driver for each device. */ ++ FOR_NET_CARDS (card) ++ { ++ FOR_NET_CARD_DRIVERS (driver) ++ { ++ if (driver->init(card) == GRUB_ERR_NONE) ++ { ++ card->driver = driver; ++ continue; ++ } ++ } ++ } ++} ++ ++GRUB_MOD_INIT(ofnet) ++{ ++ grub_net_card_driver_register (&ofdriver); ++ grub_ofnet_findcards(); ++ grub_ofnet_probecards(); ++ ++ /*init tftp stack - will be handled by module subsystem in the future*/ ++ tftp_ini (); ++ /*get bootp packet - won't be needed in the future*/ ++ bootp_pckt = grub_getbootp (); ++ grub_disknet_init(); ++} ++ ++GRUB_MODE_FINI(ofnet) ++{ ++ grub_net_card_driver_unregister (&ofdriver); ++} ++ ++ ++ diff --cc grub-core/net/ethernet.c index 000000000,000000000..d3a34aec6 new file mode 100644 --- /dev/null +++ b/grub-core/net/ethernet.c @@@ -1,0 -1,0 +1,70 @@@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++grub_err_t ++send_ethernet_packet (struct grub_net_network_level_interface *inf, ++ struct grub_net_buff *nb, ++ grub_net_link_level_address_t target_addr, ++ grub_uint16_t ethertype) ++{ ++ struct etherhdr *eth; ++ ++ grub_netbuff_push (nb,sizeof(*eth)); ++ eth = (struct etherhdr *) nb->data; ++ grub_memcpy(eth->dst, target_addr.mac, 6); ++ grub_memcpy(eth->src, inf->hwaddress.mac, 6); ++ ++ eth->type = grub_cpu_to_be16 (ethertype); ++ ++ return inf->card->driver->send (inf->card,nb); ++} ++ ++grub_err_t ++grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf, ++ struct grub_net_buff *nb, ++ grub_uint16_t ethertype) ++{ ++ struct etherhdr *eth; ++ struct llchdr *llch; ++ struct snaphdr *snaph; ++ grub_uint16_t type; ++ ++ inf->card->driver->recv (inf->card, nb); ++ eth = (struct etherhdr *) nb->data; ++ type = eth->type; ++ grub_netbuff_pull(nb,sizeof (*eth)); ++ ++ if (eth->type <=1500) ++ { ++ llch = (struct llchdr *) nb->data; ++ type = llch->dsap & LLCADDRMASK; ++ ++ if (llch->dsap == 0xaa && llch->ssap == 0xaa && llch->ctrl == 0x3) ++ { ++ grub_netbuff_pull (nb,sizeof(*llch)); ++ snaph = (struct snaphdr *) nb->data; ++ type = snaph->type; ++ } ++ } ++ ++ /* ARP packet */ ++ if (type == ARP_ETHERTYPE) ++ { ++ grub_net_arp_receive(inf, nb); ++ if (ethertype == ARP_ETHERTYPE) ++ return GRUB_ERR_NONE; ++ } ++ /* IP packet */ ++ else if(type == IP_ETHERTYPE && ethertype == IP_ETHERTYPE) ++ return GRUB_ERR_NONE; ++ ++ return GRUB_ERR_NONE; ++} diff --cc grub-core/net/i386/pc/pxe.c index dc447d92c,000000000..347d8562b mode 100644,000000..100644 --- a/grub-core/net/i386/pc/pxe.c +++ b/grub-core/net/i386/pc/pxe.c @@@ -1,476 -1,0 +1,472 @@@ +/* pxe.c - Driver to provide access to the pxe filesystem */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define SEGMENT(x) ((x) >> 4) +#define OFFSET(x) ((x) & 0xF) +#define SEGOFS(x) ((SEGMENT(x) << 16) + OFFSET(x)) +#define LINEAR(x) (void *) (((x >> 16) << 4) + (x & 0xFFFF)) + +struct grub_pxe_bangpxe *grub_pxe_pxenv; +static grub_uint32_t grub_pxe_default_server_ip; +#if 0 +static grub_uint32_t grub_pxe_default_gateway_ip; +#endif +static unsigned grub_pxe_blksize = GRUB_PXE_MIN_BLKSIZE; +static grub_uint32_t pxe_rm_entry = 0; +static grub_file_t curr_file = 0; + +struct grub_pxe_data +{ + grub_uint32_t packet_number; + grub_uint32_t block_size; + grub_uint32_t server_ip; + grub_uint32_t gateway_ip; + char filename[0]; +}; + + +static struct grub_pxe_bangpxe * +grub_pxe_scan (void) +{ + struct grub_bios_int_registers regs; + struct grub_pxenv *pxenv; + struct grub_pxe_bangpxe *bangpxe; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + + regs.ebx = 0; + regs.ecx = 0; + regs.eax = 0x5650; + regs.es = 0; + + grub_bios_interrupt (0x1a, ®s); + + if ((regs.eax & 0xffff) != 0x564e) + return NULL; + + pxenv = (struct grub_pxenv *) ((regs.es << 4) + (regs.ebx & 0xffff)); + if (grub_memcmp (pxenv->signature, GRUB_PXE_SIGNATURE, + sizeof (pxenv->signature)) + != 0) + return NULL; + + if (pxenv->version < 0x201) + return NULL; + + bangpxe = (void *) ((((pxenv->pxe_ptr & 0xffff0000) >> 16) << 4) + + (pxenv->pxe_ptr & 0xffff)); + + if (!bangpxe) + return NULL; + + if (grub_memcmp (bangpxe->signature, GRUB_PXE_BANGPXE_SIGNATURE, + sizeof (bangpxe->signature)) != 0) + return NULL; + + pxe_rm_entry = bangpxe->rm_entry; + + return bangpxe; +} + +static grub_err_t +grub_pxefs_dir (grub_device_t device __attribute__ ((unused)), + const char *path __attribute__ ((unused)), + int (*hook) (const char *filename, + const struct grub_dirhook_info *info) + __attribute__ ((unused))) +{ + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_pxefs_open (struct grub_file *file, const char *name) +{ + union + { + struct grub_pxenv_tftp_get_fsize c1; + struct grub_pxenv_tftp_open c2; + } c; + struct grub_pxe_data *data; + grub_file_t file_int, bufio; + + data = grub_malloc (sizeof (*data)); + if (!data) + return grub_errno; + + { + grub_net_network_level_address_t addr; + grub_net_network_level_address_t gateway; + struct grub_net_network_level_interface *interf; + grub_err_t err; + + if (grub_strncmp (file->device->net->name, + "pxe,", sizeof ("pxe,") - 1) == 0 + || grub_strncmp (file->device->net->name, + "pxe:", sizeof ("pxe:") - 1) == 0) + { - const char *ptr; - - ptr = name + sizeof ("pxe,") - 1; - err = grub_net_resolve_address (name + sizeof ("pxe,") - 1, &addr); ++ err = grub_net_resolve_address (file->device->net->name ++ + sizeof ("pxe,") - 1, &addr); + if (err) + return err; + } + else + { + addr.ipv4 = grub_pxe_default_server_ip; + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + } + err = grub_net_route_address (addr, &gateway, &interf); + if (err) + return err; + data->server_ip = addr.ipv4; + data->gateway_ip = gateway.ipv4; + } + + if (curr_file != 0) + { + grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c.c2, pxe_rm_entry); + curr_file = 0; + } + + c.c1.server_ip = data->server_ip; + c.c1.gateway_ip = data->gateway_ip; + grub_strcpy ((char *)&c.c1.filename[0], name); + grub_pxe_call (GRUB_PXENV_TFTP_GET_FSIZE, &c.c1, pxe_rm_entry); + if (c.c1.status) + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + + file->size = c.c1.file_size; + + c.c2.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT); + c.c2.packet_size = grub_pxe_blksize; + grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &c.c2, pxe_rm_entry); + if (c.c2.status) + return grub_error (GRUB_ERR_BAD_FS, "open fails"); + + data = grub_zalloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1); + if (! data) + return grub_errno; + + data->block_size = c.c2.packet_size; + grub_strcpy (data->filename, name); + + file_int = grub_malloc (sizeof (*file_int)); + if (! file_int) + { + grub_free (data); + return grub_errno; + } + + file->data = data; + grub_memcpy (file_int, file, sizeof (struct grub_file)); + curr_file = file_int; + + bufio = grub_bufio_open (file_int, data->block_size); + if (! bufio) + { + grub_free (file_int); + grub_free (data); + return grub_errno; + } + + grub_memcpy (file, bufio, sizeof (struct grub_file)); + + return GRUB_ERR_NONE; +} + +static grub_ssize_t +grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len) +{ + struct grub_pxenv_tftp_read c; + struct grub_pxe_data *data; + grub_uint32_t pn, r; + + data = file->data; + + pn = grub_divmod64 (file->offset, data->block_size, &r); + if (r) + { + grub_error (GRUB_ERR_BAD_FS, + "read access must be aligned to packet size"); + return -1; + } + + if ((curr_file != file) || (data->packet_number > pn)) + { + struct grub_pxenv_tftp_open o; + + if (curr_file != 0) + grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &o, pxe_rm_entry); + + o.server_ip = data->server_ip; + o.gateway_ip = data->gateway_ip; + grub_strcpy ((char *)&o.filename[0], data->filename); + o.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT); + o.packet_size = grub_pxe_blksize; + grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &o, pxe_rm_entry); + if (o.status) + { + grub_error (GRUB_ERR_BAD_FS, "open fails"); + return -1; + } + data->block_size = o.packet_size; + data->packet_number = 0; + curr_file = file; + } + + c.buffer = SEGOFS (GRUB_MEMORY_MACHINE_SCRATCH_ADDR); + while (pn >= data->packet_number) + { + c.buffer_size = data->block_size; + grub_pxe_call (GRUB_PXENV_TFTP_READ, &c, pxe_rm_entry); + if (c.status) + { + grub_error (GRUB_ERR_BAD_FS, "read fails"); + return -1; + } + data->packet_number++; + } + + grub_memcpy (buf, (char *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, len); + + return len; +} + +static grub_err_t +grub_pxefs_close (grub_file_t file) +{ + struct grub_pxenv_tftp_close c; + + if (curr_file == file) + { + grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c, pxe_rm_entry); + curr_file = 0; + } + + grub_free (file->data); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_pxefs_label (grub_device_t device __attribute ((unused)), + char **label __attribute ((unused))) +{ + *label = 0; + return GRUB_ERR_NONE; +} + +static struct grub_fs grub_pxefs_fs = + { + .name = "pxe", + .dir = grub_pxefs_dir, + .open = grub_pxefs_open, + .read = grub_pxefs_read, + .close = grub_pxefs_close, + .label = grub_pxefs_label, + .next = 0 + }; + +static grub_size_t +grub_pxe_recv (struct grub_net_card *dev __attribute__ ((unused)), - void *buf __attribute__ ((unused)), - grub_size_t buflen __attribute__ ((unused))) ++ struct grub_net_buff *buf __attribute__ ((unused))) +{ + return 0; +} + +static grub_err_t +grub_pxe_send (struct grub_net_card *dev __attribute__ ((unused)), - void *buf __attribute__ ((unused)), - grub_size_t buflen __attribute__ ((unused))) ++ struct grub_net_buff *buf __attribute__ ((unused))) +{ + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "not implemented"); +} + +struct grub_net_card_driver grub_pxe_card_driver = +{ + .send = grub_pxe_send, + .recv = grub_pxe_recv +}; + +struct grub_net_card grub_pxe_card = +{ + .driver = &grub_pxe_card_driver, + .name = "pxe" +}; + +void +grub_pxe_unload (void) +{ + if (grub_pxe_pxenv) + { + grub_net_app_level_unregister (&grub_pxefs_fs); + grub_net_card_unregister (&grub_pxe_card); + grub_pxe_pxenv = 0; + } +} + +static void +set_ip_env (char *varname, grub_uint32_t ip) +{ + char buf[GRUB_NET_MAX_STR_ADDR_LEN]; + grub_net_network_level_address_t addr; + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + addr.ipv4 = ip; + + grub_net_addr_to_str (&addr, buf); + grub_env_set (varname, buf); +} + +static char * +write_ip_env (grub_uint32_t *ip, const char *val) +{ + char *buf; + grub_err_t err; + grub_net_network_level_address_t addr; + + err = grub_net_resolve_address (val, &addr); + if (err) + return 0; + if (addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4) + return NULL; + + /* Normalize the IP. */ + buf = grub_malloc (GRUB_NET_MAX_STR_ADDR_LEN); + if (!buf) + return 0; + grub_net_addr_to_str (&addr, buf); + + *ip = addr.ipv4; + + return buf; +} + +static char * +grub_env_write_pxe_default_server (struct grub_env_var *var + __attribute__ ((unused)), + const char *val) +{ + return write_ip_env (&grub_pxe_default_server_ip, val); +} + +#if 0 +static char * +grub_env_write_pxe_default_gateway (struct grub_env_var *var + __attribute__ ((unused)), + const char *val) +{ + return write_ip_env (&grub_pxe_default_gateway_ip, val); +} +#endif + +static char * +grub_env_write_pxe_blocksize (struct grub_env_var *var __attribute__ ((unused)), + const char *val) +{ + unsigned size; + char *buf; + + size = grub_strtoul (val, 0, 0); + if (grub_errno) + return 0; + + if (size < GRUB_PXE_MIN_BLKSIZE) + size = GRUB_PXE_MIN_BLKSIZE; + else if (size > GRUB_PXE_MAX_BLKSIZE) + size = GRUB_PXE_MAX_BLKSIZE; + + buf = grub_xasprintf ("%d", size); + if (!buf) + return 0; + + grub_pxe_blksize = size; + + return buf; +} + +GRUB_MOD_INIT(pxe) +{ + struct grub_pxe_bangpxe *pxenv; + struct grub_pxenv_get_cached_info ci; + struct grub_net_bootp_ack *bp; + char *buf; + + pxenv = grub_pxe_scan (); + if (! pxenv) + return; + + ci.packet_type = GRUB_PXENV_PACKET_TYPE_DHCP_ACK; + ci.buffer = 0; + ci.buffer_size = 0; + grub_pxe_call (GRUB_PXENV_GET_CACHED_INFO, &ci, pxe_rm_entry); + if (ci.status) + return; + + bp = LINEAR (ci.buffer); + + grub_pxe_default_server_ip = bp->server_ip; + grub_pxe_pxenv = pxenv; + + set_ip_env ("pxe_default_server", grub_pxe_default_server_ip); + grub_register_variable_hook ("pxe_default_server", 0, + grub_env_write_pxe_default_server); + +#if 0 + grub_pxe_default_gateway_ip = bp->gateway_ip; + + grub_register_variable_hook ("pxe_default_gateway", 0, + grub_env_write_pxe_default_gateway); +#endif + + buf = grub_xasprintf ("%d", grub_pxe_blksize); + if (buf) + grub_env_set ("pxe_blksize", buf); + grub_free (buf); + + grub_register_variable_hook ("pxe_blksize", 0, + grub_env_write_pxe_blocksize); + + grub_memcpy (grub_pxe_card.default_address.mac, bp->mac_addr, + bp->hw_len < sizeof (grub_pxe_card.default_address.mac) + ? bp->hw_len : sizeof (grub_pxe_card.default_address.mac)); + grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + + grub_net_app_level_register (&grub_pxefs_fs); + grub_net_card_register (&grub_pxe_card); + grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, + GRUB_NET_INTERFACE_PERMANENT + | GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE + | GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE, + bp, GRUB_PXE_BOOTP_SIZE); +} + +GRUB_MOD_FINI(pxe) +{ + grub_pxe_unload (); +} diff --cc grub-core/net/interface.c index 000000000,f17b3e66b..f17b3e66b mode 000000,100644..100644 --- a/grub-core/net/interface.c +++ b/grub-core/net/interface.c diff --cc grub-core/net/ip.c index 000000000,000000000..264195ad3 new file mode 100644 --- /dev/null +++ b/grub-core/net/ip.c @@@ -1,0 -1,0 +1,93 @@@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++grub_uint16_t ++ipchksum(void *ipv, int len) ++{ ++ grub_uint16_t *ip = (grub_uint16_t *)ipv; ++ grub_uint32_t sum = 0; ++ ++ len >>= 1; ++ while (len--) ++ { ++ sum += grub_be_to_cpu16 (*(ip++)); ++ if (sum > 0xFFFF) ++ sum -= 0xFFFF; ++ } ++ ++ return grub_cpu_to_be16 ((~sum) & 0x0000FFFF); ++} ++ ++grub_err_t ++grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, ++ const grub_net_network_level_address_t *target, ++ struct grub_net_buff *nb) ++{ ++ struct iphdr *iph; ++ static int id = 0x2400; ++ grub_net_link_level_address_t ll_target_addr; ++ grub_err_t err; ++ ++ grub_netbuff_push(nb,sizeof(*iph)); ++ iph = (struct iphdr *) nb->data; ++ ++ iph->verhdrlen = ((4 << 4) | 5); ++ iph->service = 0; ++ iph->len = grub_cpu_to_be16 (nb->tail - nb-> data); ++ iph->ident = grub_cpu_to_be16 (++id); ++ iph->frags = 0; ++ iph->ttl = 0xff; ++ iph->protocol = 0x11; ++ iph->src = inf->address.ipv4; ++ iph->dest = target->ipv4; ++ ++ iph->chksum = 0 ; ++ iph->chksum = ipchksum((void *)nb->data, sizeof(*iph)); ++ ++ /* Determine link layer target address via ARP */ ++ err = grub_net_arp_resolve(inf, target, &ll_target_addr); ++ if (err) ++ return err; ++ ++ return send_ethernet_packet (inf, nb, ll_target_addr, IP_ETHERTYPE); ++} ++ ++static int ++ip_filter (struct grub_net_buff *nb, ++ struct grub_net_network_level_interface *inf) ++{ ++ struct iphdr *iph = (struct iphdr *) nb->data; ++ grub_err_t err; ++ ++ if (nb->end - nb->data < (signed) sizeof (*iph)) ++ return 0; ++ ++ if (iph->protocol != 0x11 || ++ iph->dest != inf->address.ipv4) ++ return 0; ++ ++ grub_netbuff_pull (nb, sizeof (iph)); ++ err = grub_net_put_packet (&inf->nl_pending, nb); ++ if (err) ++ { ++ grub_print_error (); ++ return 0; ++ } ++ return 1; ++} ++ ++grub_err_t ++grub_net_recv_ip_packets (struct grub_net_network_level_interface *inf) ++{ ++ struct grub_net_buff nb; ++ grub_net_recv_ethernet_packet (inf, &nb, IP_ETHERTYPE); ++ ip_filter (&nb, inf); ++ return GRUB_ERR_NONE; ++} diff --cc grub-core/net/netbuff.c index 000000000,4f6a1da84..4f6a1da84 mode 000000,100644..100644 --- a/grub-core/net/netbuff.c +++ b/grub-core/net/netbuff.c diff --cc grub-core/net/tftp.c index 000000000,000000000..bb518b78f new file mode 100644 --- /dev/null +++ b/grub-core/net/tftp.c @@@ -1,0 -1,0 +1,215 @@@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++struct { ++ int block_size; ++ int size; ++} tftp_file; ++static int block; ++ ++ ++static char *get_tok_val(char **tok, char **val, char **str_opt,char *end); ++static void process_option(char *tok, char *val); ++ ++static char * ++get_tok_val(char **tok, char **val,char **str_opt,char *end) ++{ ++ char *p = *str_opt; ++ *tok = p; ++ p += grub_strlen(p) + 1; ++ ++ if(p > end) ++ return NULL; ++ ++ *val = p; ++ p += grub_strlen(p) + 1; ++ *str_opt = p; ++ return *tok; ++} ++ ++static void ++process_option(char *tok, char *val) ++{ ++ if (!grub_strcmp(tok,"blksize")) ++ { ++ tftp_file.block_size = grub_strtoul (val,NULL,0); ++ return; ++ } ++ ++ if (!grub_strcmp(tok,"tsize")) ++ { ++ tftp_file.size = grub_strtoul (val,NULL,0); ++ return; ++ } ++ ++} ++ ++//void tftp_open (char *options); ++ ++/*send read request*/ ++static grub_err_t ++tftp_open (struct grub_file *file, const char *filename) ++{ ++ struct tftphdr *tftph; ++ char *rrq; ++ int rrqlen; ++ int hdrlen; ++ struct grub_net_buff nb; ++ grub_net_network_level_address_t addr; ++ grub_err_t err; ++ ++ err = grub_net_resolve_address (file->device->net->name ++ + sizeof ("tftp,") - 1, &addr); ++ if (err) ++ return err; ++ ++ grub_memset (&nb, 0, sizeof (nb)); ++ grub_netbuff_push (&nb,sizeof (*tftph)); ++ ++ tftph = (struct tftphdr *) nb.data; ++ ++ rrq = (char *) tftph->u.rrq; ++ rrqlen = 0; ++ ++ tftph->opcode = TFTP_RRQ; ++ grub_strcpy (rrq, filename); ++ rrqlen += grub_strlen (filename) + 1; ++ rrq += grub_strlen (filename) + 1; ++ /*passar opcoes como parametro ou usar default?*/ ++ ++ grub_strcpy (rrq,"octet"); ++ rrqlen += grub_strlen ("octet") + 1; ++ rrq += grub_strlen ("octet") + 1; ++ ++ //grub_strcpy (rrq,"netascii"); ++ //rrqlen += grub_strlen ("netascii") + 1; ++ //rrq += grub_strlen ("netascii") + 1; ++ ++ grub_strcpy (rrq,"blksize"); ++ rrqlen += grub_strlen("blksize") + 1; ++ rrq += grub_strlen ("blksize") + 1; ++ ++ grub_strcpy (rrq,"1024"); ++ rrqlen += grub_strlen ("1024") + 1; ++ rrq += grub_strlen ("1024") + 1; ++ ++ grub_strcpy (rrq,"tsize"); ++ rrqlen += grub_strlen ("tsize") + 1; ++ rrq += grub_strlen ("tsize") + 1; ++ ++ grub_strcpy (rrq,"0"); ++ rrqlen += grub_strlen ("0") + 1; ++ rrq += grub_strlen ("0") + 1; ++ hdrlen = sizeof (tftph->opcode) + rrqlen; ++ ++ grub_netbuff_unput (&nb,nb.tail - (nb.data+hdrlen)); ++ ++ grub_net_send_udp_packet (&addr, ++ &nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); ++ ++ grub_net_send_udp_packet (&addr, &nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); ++ /*Receive OACK*/ ++ grub_netbuff_clear (&nb); ++ grub_netbuff_reserve (&nb,2048); ++ file->size = tftp_file.size; ++ ++ return grub_net_recv_udp_packet (&addr, &nb, ++ TFTP_CLIENT_PORT, TFTP_SERVER_PORT); ++} ++ ++static grub_ssize_t ++tftp_receive (struct grub_file *file, char *buf, grub_size_t len) ++{ ++ struct tftphdr *tftph; ++ char *token,*value,*temp; ++ grub_err_t err; ++ grub_net_network_level_address_t addr; ++ struct grub_net_buff nb; ++ ++ err = grub_net_resolve_address (file->device->net->name ++ + sizeof ("tftp,") - 1, &addr); ++ if (err) ++ return err; ++ ++ grub_net_recv_udp_packet (&addr, &nb, ++ TFTP_CLIENT_PORT, TFTP_SERVER_PORT); ++ ++ tftph = (struct tftphdr *) nb.data; ++ switch (tftph->opcode) ++ { ++ case TFTP_OACK: ++ /*process oack packet*/ ++ temp = (char *) tftph->u.oack.data; ++ while(get_tok_val(&token,&value,&temp,nb.tail)) ++ { ++ process_option(token,value); ++ } ++ ++ //buff_clean ++ grub_netbuff_clear(&nb); ++ // grub_printf("OACK---------------------------------------------------------\n"); ++ //grub_printf("block_size=%d\n",tftp_file.block_size); ++ // grub_printf("file_size=%d\n",tftp_file.size); ++ // grub_printf("OACK---------------------------------------------------------\n"); ++ block = 0; ++ break; ++ case TFTP_DATA: ++ grub_netbuff_pull (&nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block)); ++ if (tftph->u.data.block == block + 1) ++ { ++ block = tftph->u.data.block; ++ grub_memcpy (buf, nb.data, len); ++ } ++ else ++ grub_netbuff_clear(&nb); ++ break; ++ case TFTP_ERROR: ++ grub_netbuff_clear (&nb); ++ return grub_error (GRUB_ERR_ACCESS_DENIED, (char *)tftph->u.err.errmsg); ++ break; ++ } ++ ++ nb.data = nb.tail = nb.end; ++ ++ grub_netbuff_push (&nb,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block)); ++ ++ tftph = (struct tftphdr *) nb.data; ++ tftph->opcode = TFTP_ACK; ++ tftph->u.ack.block = block; ++ ++ return grub_net_send_udp_packet (&addr, &nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); ++} ++ ++static grub_err_t ++tftp_close (struct grub_file *file __attribute__ ((unused))) ++{ ++ return 0; ++} ++ ++static struct grub_fs grub_tftp_protocol = ++{ ++ .name = "tftp", ++ .open = tftp_open, ++ .read = tftp_receive, ++ .close = tftp_close ++}; ++ ++GRUB_MOD_INIT (tftp) ++{ ++ grub_net_app_level_register (&grub_tftp_protocol); ++} ++ ++GRUB_MOD_FINI (tftp) ++{ ++ grub_net_app_level_unregister (&grub_tftp_protocol); ++} diff --cc grub-core/net/udp.c index 000000000,000000000..27e23e826 new file mode 100644 --- /dev/null +++ b/grub-core/net/udp.c @@@ -1,0 -1,0 +1,70 @@@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++grub_err_t ++grub_net_send_udp_packet (const grub_net_network_level_address_t *target, ++ struct grub_net_buff *nb, grub_uint16_t srcport, ++ grub_uint16_t destport) ++{ ++ struct udphdr *udph; ++ struct grub_net_network_level_interface *inf; ++ grub_err_t err; ++ grub_net_network_level_address_t gateway; ++ ++ err = grub_net_route_address (*target, &gateway, &inf); ++ if (err) ++ return err; ++ ++ grub_netbuff_push (nb,sizeof(*udph)); ++ ++ udph = (struct udphdr *) nb->data; ++ udph->src = grub_cpu_to_be16 (srcport); ++ udph->dst = grub_cpu_to_be16 (destport); ++ ++ /* No chechksum. */ ++ udph->chksum = 0; ++ udph->len = grub_cpu_to_be16 (nb->tail - nb->data); ++ ++ return grub_net_send_ip_packet (inf, target, nb); ++} ++ ++grub_err_t ++grub_net_recv_udp_packet (const grub_net_network_level_address_t *target, ++ struct grub_net_buff *buf, ++ grub_uint16_t srcport, grub_uint16_t destport) ++{ ++ grub_err_t err; ++ struct grub_net_packet *pkt; ++ struct grub_net_network_level_interface *inf; ++ grub_net_network_level_address_t gateway; ++ ++ err = grub_net_route_address (*target, &gateway, &inf); ++ if (err) ++ return err; ++ ++ (void) srcport; ++ ++ err = grub_net_recv_ip_packets (inf); ++ ++ FOR_NET_NL_PACKETS(inf, pkt) ++ { ++ struct udphdr *udph; ++ struct grub_net_buff *nb = pkt->nb; ++ udph = (struct udphdr *) nb->data; ++ if (grub_be_to_cpu16 (udph->dst) == destport) ++ { ++ grub_net_remove_packet (pkt); ++ grub_netbuff_pull (nb, sizeof(*udph)); ++ grub_memcpy (buf, nb, sizeof (buf)); ++ ++ return GRUB_ERR_NONE; ++ } ++ } ++ return GRUB_ERR_NONE; ++} diff --cc include/grub/err.h index 493796d62,493796d62..8b2ba4dde --- a/include/grub/err.h +++ b/include/grub/err.h @@@ -57,7 -57,7 +57,8 @@@ typedef enu GRUB_ERR_ACCESS_DENIED, GRUB_ERR_NET_BAD_ADDRESS, GRUB_ERR_NET_ROUTE_LOOP, -- GRUB_ERR_NET_NO_ROUTE ++ GRUB_ERR_NET_NO_ROUTE, ++ GRUB_ERR_WAIT } grub_err_t; diff --cc include/grub/net.h index a0737d574,18779dabe..ad553a69a --- a/include/grub/net.h +++ b/include/grub/net.h @@@ -22,55 -22,29 +22,61 @@@ #include #include #include +#include + #include + #include + #include -struct grub_net_card; +typedef struct grub_fs *grub_net_app_level_t; + +typedef struct grub_net +{ + char *name; + grub_net_app_level_t protocol; +} *grub_net_t; + +extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); + +typedef enum grub_link_level_protocol_id +{ + GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET +} grub_link_level_protocol_id_t; + +typedef struct grub_net_link_level_address +{ + grub_link_level_protocol_id_t type; + union + { + grub_uint8_t mac[6]; + }; +} grub_net_link_level_address_t; + +typedef enum grub_net_interface_flags + { + GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE = 1, + GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE = 2, + GRUB_NET_INTERFACE_PERMANENT = 4 + } grub_net_interface_flags_t; +typedef enum grub_net_card_flags + { + GRUB_NET_CARD_HWADDRESS_IMMUTABLE = 1, + GRUB_NET_CARD_NO_MANUAL_INTERFACES = 2 + } grub_net_card_flags_t; + +struct grub_net_card; struct grub_net_card_driver { - grub_err_t (*send) (struct grub_net_card *dev, void *buf, - grub_size_t buflen); - grub_size_t (*recv) (struct grub_net_card *dev, void *buf, - grub_size_t buflen); + struct grub_net_card_driver *next; + char *name; + grub_err_t (*init) (struct grub_net_card *dev); + grub_err_t (*fini) (struct grub_net_card *dev); - grub_err_t (*send) (struct grub_net_card *dev,struct grub_net_buff *nb); - grub_size_t (*recv) (struct grub_net_card *dev,struct grub_net_buff *nb); ++ grub_err_t (*send) (struct grub_net_card *dev, struct grub_net_buff *buf); ++ grub_size_t (*recv) (struct grub_net_card *dev, struct grub_net_buff *buf); }; -struct grub_net_addr -{ - grub_uint8_t *addr; - grub_size_t len; -}; + struct grub_net_card { struct grub_net_card *next; @@@ -81,47 -59,31 +87,100 @@@ void *data; }; -//struct grub_net_network_layer_interface; +struct grub_net_network_level_interface; -struct grub_net_network_layer_interface +typedef enum grub_network_level_protocol_id { - struct grub_net_network_layer_interface *next; - char *name; - /* Underlying protocol. */ - struct grub_net_network_layer_protocol *protocol; - struct grub_net_card *card; - grub_net_network_layer_address_t address; - void *data; -}; + GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 +} grub_network_level_protocol_id_t; -struct grub_net_route +typedef struct grub_net_network_level_address { - struct grub_net_route *next; - grub_net_network_layer_netaddress_t target; - char *name; - struct grub_net_network_layer_protocol *prot; - int is_gateway; + grub_network_level_protocol_id_t type; union { - struct grub_net_network_layer_interface *interface; - grub_net_network_layer_address_t gw; + grub_uint32_t ipv4; }; +} grub_net_network_level_address_t; + +typedef struct grub_net_network_level_netaddress +{ + grub_network_level_protocol_id_t type; + union + { + struct { + grub_uint32_t base; + int masksize; + } ipv4; + }; +} grub_net_network_level_netaddress_t; + - struct grub_net_network_level_interface; ++typedef struct grub_net_packet ++{ ++ struct grub_net_packet *next; ++ struct grub_net_packet *prev; ++ struct grub_net_packets *up; ++ struct grub_net_buff *nb; ++} grub_net_packet_t; ++ ++typedef struct grub_net_packets ++{ ++ struct grub_net_packet *first; ++ struct grub_net_packet *last; ++} grub_net_packets_t; ++ ++#define FOR_PACKETS(cont,var) for (var = (cont).first; var; var = var->next) ++ ++static inline grub_err_t ++grub_net_put_packet (grub_net_packets_t *pkts, struct grub_net_buff *nb) ++{ ++ struct grub_net_packet *n; ++ ++ n = grub_malloc (sizeof (*n)); ++ if (!n) ++ return grub_errno; ++ ++ n->nb = nb; ++ n->next = NULL; ++ n->prev = NULL; ++ n->up = pkts; ++ if (pkts->first) ++ { ++ pkts->last->next = n; ++ pkts->last = n; ++ n->prev = pkts->last; ++ } ++ else ++ pkts->first = pkts->last = n; ++ ++ return GRUB_ERR_NONE; ++} ++ ++static inline void ++grub_net_remove_packet (grub_net_packet_t *pkt) ++{ ++ if (pkt->prev) ++ pkt->prev->next = pkt->next; ++ else ++ pkt->up->first = pkt->next; ++ if (pkt->next) ++ pkt->next->prev = pkt->prev; ++ else ++ pkt->up->last = pkt->prev; ++} + +struct grub_net_network_level_interface +{ + struct grub_net_network_level_interface *next; + char *name; + struct grub_net_card *card; + grub_net_network_level_address_t address; + grub_net_link_level_address_t hwaddress; + grub_net_interface_flags_t flags; + struct grub_net_bootp_ack *dhcp_ack; + grub_size_t dhcp_acklen; ++ grub_net_packets_t nl_pending; + void *data; }; struct grub_net_session; @@@ -207,78 -176,49 +266,98 @@@ grub_net_card_unregister (struct grub_n } #define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next) -struct grub_net_card_driver *grub_net_card_drivers; -static inline void -grub_net_card_driver_register (struct grub_net_card_driver *driver) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_net_card_drivers), - GRUB_AS_LIST (driver)); -} +struct grub_net_session * +grub_net_open_tcp (char *address, grub_uint16_t port); -static inline void -grub_net_card_driver_unregister (struct grub_net_card_driver *driver) -{ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_card_drivers), - GRUB_AS_LIST (driver)); -} +grub_err_t +grub_net_resolve_address (const char *name, + grub_net_network_level_address_t *addr); -void ofdriver_ini(void); -void ofdriver_fini(void); +grub_err_t +grub_net_resolve_net_address (const char *name, + grub_net_network_level_netaddress_t *addr); -#define FOR_NET_CARD_DRIVERS(var) for (var = grub_net_card_drivers; var; var = var->next) +grub_err_t +grub_net_route_address (grub_net_network_level_address_t addr, + grub_net_network_level_address_t *gateway, + struct grub_net_network_level_interface **interf); -#define FOR_NET_NETWORK_LEVEL_PROTOCOLS(var) for ((var) = grub_net_network_layer_protocols; (var); (var) = (var)->next) -static inline grub_err_t -grub_net_resolve_address_in_protocol (struct grub_net_network_layer_protocol *prot, - char *name, - grub_net_network_layer_address_t *addr) +grub_err_t +grub_net_add_route (const char *name, + grub_net_network_level_netaddress_t target, + struct grub_net_network_level_interface *inter); + +grub_err_t +grub_net_add_route_gw (const char *name, + grub_net_network_level_netaddress_t target, + grub_net_network_level_address_t gw); + + +#define GRUB_NET_BOOTP_MAC_ADDR_LEN 16 + +typedef grub_uint8_t grub_net_bootp_mac_addr_t[GRUB_NET_BOOTP_MAC_ADDR_LEN]; + +struct grub_net_bootp_ack { - return prot->ntoa (name, addr); -} + grub_uint8_t opcode; + grub_uint8_t hw_type; /* hardware type. */ + grub_uint8_t hw_len; /* hardware addr len. */ + grub_uint8_t gate_hops; /* zero it. */ + grub_uint32_t ident; /* random number chosen by client. */ + grub_uint16_t seconds; /* seconds since did initial bootstrap. */ + grub_uint16_t flags; + grub_uint32_t client_ip; + grub_uint32_t your_ip; + grub_uint32_t server_ip; + grub_uint32_t gateway_ip; + grub_net_bootp_mac_addr_t mac_addr; + grub_uint8_t server_name[64]; + grub_uint8_t boot_file[128]; + grub_uint8_t vendor[0]; +} __attribute__ ((packed)); + +#define GRUB_NET_BOOTP_RFC1048_MAGIC 0x63825363L + +struct grub_net_network_level_interface * +grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, + grub_net_interface_flags_t flags, + struct grub_net_bootp_ack *bp, + grub_size_t size); -struct grub_net_session * -grub_net_open_tcp (char *address, grub_uint16_t port); +/* + Currently suppoerted adresses: + IPv4: XXX.XXX.XXX.XXX + */ +#define GRUB_NET_MAX_STR_ADDR_LEN sizeof ("XXX.XXX.XXX.XXX") -grub_err_t -grub_net_resolve_address (struct grub_net_network_layer_protocol **prot, - char *name, - grub_net_network_layer_address_t *addr); +void +grub_net_addr_to_str (const grub_net_network_level_address_t *target, + char *buf); + +extern struct grub_net_network_level_interface *grub_net_network_level_interfaces; +#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) + ++grub_err_t grub_net_send_link_layer (struct grub_net_network_level_interface *inf, ++ struct grub_net_buff *nb, ++ grub_net_link_level_address_t *target); ++ ++typedef int ++(*grub_net_packet_handler_t) (struct grub_net_buff *nb, ++ struct grub_net_network_level_interface *inf); ++ ++grub_err_t grub_net_recv_link_layer (struct grub_net_network_level_interface *inf, ++ grub_net_packet_handler_t handler); ++ ++grub_err_t ++grub_net_recv_ip_packets (struct grub_net_network_level_interface *inf); + + grub_err_t -grub_net_route_address (grub_net_network_layer_address_t addr, - grub_net_network_layer_address_t *gateway, - struct grub_net_network_layer_interface **interf); ++grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, ++ const grub_net_network_level_address_t *target, ++ struct grub_net_buff *nb); + ++#define FOR_NET_NL_PACKETS(inf, var) FOR_PACKETS(inf->nl_pending, var) #endif /* ! GRUB_NET_HEADER */ diff --cc include/grub/net/arp.h index 000000000,75260aeb3..e547669a2 mode 000000,100644..100644 --- a/include/grub/net/arp.h +++ b/include/grub/net/arp.h @@@ -1,0 -1,42 +1,40 @@@ + #ifndef GRUB_NET_ARP_HEADER + #define GRUB_NET_ARP_HEADER 1 + #include + #include + #include + + /* IANA ARP constant to define hardware type as ethernet */ + #define ARPHRD_ETHERNET 1 + /* IANA Ethertype */ + #define ARP_ETHERTYPE 0x806 + + /* Size for cache table */ + #define SIZE_ARP_TABLE 5 + + /* ARP header operation codes */ + #define ARP_REQUEST 1 + #define ARP_REPLY 2 + + struct arp_entry { - grub_uint8_t avail; - struct grub_net_network_layer_protocol *nl_protocol; - struct grub_net_link_layer_protocol *ll_protocol; - struct grub_net_addr nl_address; - struct grub_net_addr ll_address; ++ int avail; ++ grub_net_network_level_address_t nl_address; ++ grub_net_link_level_address_t ll_address; + }; + + struct arphdr { + grub_uint16_t hrd; + grub_uint16_t pro; + grub_uint8_t hln; + grub_uint8_t pln; + grub_uint16_t op; + } __attribute__ ((packed)); + -extern grub_err_t arp_receive(struct grub_net_network_layer_interface *inf __attribute__ ((unused)), -struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb); ++extern grub_err_t grub_net_arp_receive(struct grub_net_network_level_interface *inf, ++ struct grub_net_buff *nb); + -extern grub_err_t arp_resolve(struct grub_net_network_layer_interface *inf __attribute__ ((unused)), -struct grub_net_network_link_interface *net_link_inf, struct grub_net_addr *proto_addr, -struct grub_net_addr *hw_addr); ++extern grub_err_t grub_net_arp_resolve(struct grub_net_network_level_interface *inf, ++ const grub_net_network_level_address_t *addr, ++ grub_net_link_level_address_t *hw_addr); + + #endif diff --cc include/grub/net/ethernet.h index 000000000,f4a6c22cf..b4f07992b mode 000000,100644..100644 --- a/include/grub/net/ethernet.h +++ b/include/grub/net/ethernet.h @@@ -1,0 -1,41 +1,51 @@@ + #ifndef GRUB_NET_ETHERNET_HEADER + #define GRUB_NET_ETHERNET_HEADER 1 -#include ++#include ++#include ++ + #define LLCADDRMASK 0x7f + + struct etherhdr + { + grub_uint8_t dst[6]; + grub_uint8_t src[6]; + grub_uint16_t type; + } __attribute__ ((packed)); + + #define PCP(x) x & 0xe000 + #define CFI(x) x & 0x1000 + #define VID(x) x & 0x0fff + #define PRINT_ETH_ADDR(name,addr) grub_printf("%s %x:%x:%x:%x:%x:%x\n",\ + name,\ + addr[0],\ + addr[1],\ + addr[2],\ + addr[3],\ + addr[4],\ + addr[5]\ + ) + + struct llchdr + { -grub_uint8_t dsap; -grub_uint8_t ssap; -grub_uint8_t ctrl; ++ grub_uint8_t dsap; ++ grub_uint8_t ssap; ++ grub_uint8_t ctrl; + } __attribute__ ((packed)); + + struct snaphdr + { -grub_uint8_t oui[3]; -grub_uint16_t type; ++ grub_uint8_t oui[3]; ++ grub_uint16_t type; + } __attribute__ ((packed)); + -void ethernet_ini(void); -void ethernet_fini(void); ++grub_err_t ++send_ethernet_packet (struct grub_net_network_level_interface *inf, ++ struct grub_net_buff *nb, ++ grub_net_link_level_address_t target_addr, ++ grub_uint16_t ethertype); ++grub_err_t ++grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf, ++ struct grub_net_buff *nb, ++ grub_uint16_t ethertype); ++ + #endif diff --cc include/grub/net/ip.h index 000000000,5baacd439..765d8005e mode 000000,100644..100644 --- a/include/grub/net/ip.h +++ b/include/grub/net/ip.h @@@ -1,0 -1,38 +1,37 @@@ + #ifndef GRUB_NET_IP_HEADER + #define GRUB_NET_IP_HEADER 1 + #include + + #define IP_ETHERTYPE 0x800 /* IANA Ethertype */ + + struct iphdr { + grub_uint8_t verhdrlen; + grub_uint8_t service; + grub_uint16_t len; + grub_uint16_t ident; + grub_uint16_t frags; + grub_uint8_t ttl; + grub_uint8_t protocol; + grub_uint16_t chksum; + grub_uint32_t src; + grub_uint32_t dest; + } __attribute__ ((packed)) ; + + struct ip6hdr + { - grub_uint8_t version:4, - priority:4; ++ grub_uint8_t version:4, priority:4; + grub_uint8_t flow_lbl[3]; + grub_uint16_t payload_len; + grub_uint8_t nexthdr; + grub_uint8_t hop_limit; + grub_uint8_t saddr[16]; + grub_uint8_t daddr[16]; + } __attribute__ ((packed)); + + #define IP_UDP 17 /* UDP protocol */ + #define IP_BROADCAST 0xFFFFFFFF + + grub_uint16_t ipchksum(void *ipv, int len); + void ipv4_ini(void); + void ipv4_fini(void); + #endif diff --cc include/grub/net/protocol.h index 000000000,ce37404bc..da54b073f mode 000000,100644..100644 --- a/include/grub/net/protocol.h +++ b/include/grub/net/protocol.h @@@ -1,0 -1,106 +1,9 @@@ + #ifndef GRUB_PROTOCOL_HEADER + #define GRUB_PROTOCOL_HEADER + #include + #include + #include + #include + #include + -struct grub_net_protocol; -struct grub_net_protocol_stack; -struct grub_net_network_layer_interface; -struct grub_net_addr; - -typedef enum grub_network_layer_protocol_id -{ - GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 -} grub_network_layer_protocol_id_t; - -struct grub_net_application_layer_protocol -{ - struct grub_net_application_layer_protocol *next; - char *name; - grub_net_protocol_id_t id; - int (*get_file_size) (struct grub_net_network_layer_interface* inf, - struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb,char *filename); - grub_err_t (*open) (struct grub_net_network_layer_interface* inf, - struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb,char *filename); - grub_err_t (*send_ack) (struct grub_net_network_layer_interface* inf, - struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); - grub_err_t (*send) (struct grub_net_network_layer_interface *inf, - struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); - grub_err_t (*recv) (struct grub_net_network_layer_interface *inf, - struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); - grub_err_t (*close) (struct grub_net_network_layer_interface *inf, - struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); -}; - -struct grub_net_transport_layer_protocol -{ - struct grub_net_transport_layer_protocol *next; - char *name; - grub_net_protocol_id_t id; - //grub_transport_layer_protocol_id_t id; - grub_err_t (*open) (struct grub_net_network_layer_interface* inf, - struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb); - grub_err_t (*send_ack) (struct grub_net_network_layer_interface* inf, - struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); - grub_err_t (*send) (struct grub_net_network_layer_interface *inf, - struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb); - grub_err_t (*recv) (struct grub_net_network_layer_interface *inf, - struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb); - grub_err_t (*close) (struct grub_net_network_layer_interface *inf, - struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); -}; - -struct grub_net_network_layer_protocol -{ - struct grub_net_network_layer_protocol *next; - char *name; - grub_net_protocol_id_t id; - grub_uint16_t type; /* IANA Ethertype */ - //grub_network_layer_protocol_id_t id; - grub_err_t (*ntoa) (char *name, grub_net_network_layer_address_t *addr); - char * (*aton) (grub_net_network_layer_address_t addr); - grub_err_t (*net_ntoa) (char *name, - grub_net_network_layer_netaddress_t *addr); - char * (*net_aton) (grub_net_network_layer_netaddress_t addr); - int (* match_net) (grub_net_network_layer_netaddress_t net, - grub_net_network_layer_address_t addr); - grub_err_t (*send) (struct grub_net_network_layer_interface *inf , - struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb); - grub_err_t (*recv) (struct grub_net_network_layer_interface *inf , - struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb); -}; - -struct grub_net_link_layer_protocol -{ - - struct grub_net_link_layer_protocol *next; - char *name; - grub_uint16_t type; /* ARP hardware type */ - grub_net_protocol_id_t id; - grub_err_t (*send) (struct grub_net_network_layer_interface *inf , - struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb, - struct grub_net_addr target_addr, grub_uint16_t ethertype); - grub_err_t (*recv) (struct grub_net_network_layer_interface *inf , - struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb, - grub_uint16_t ethertype); -}; - -extern struct grub_net_network_layer_protocol *EXPORT_VAR(grub_net_network_layer_protocols); - -typedef struct grub_net_protocol *grub_net_protocol_t; -void grub_net_application_layer_protocol_register (struct grub_net_application_layer_protocol *prot); -void grub_net_application_layer_protocol_unregister (struct grub_net_application_layer_protocol *prot); -struct grub_net_application_layer_protocol *grub_net_application_layer_protocol_get (grub_net_protocol_id_t id); -void grub_net_transport_layer_protocol_register (struct grub_net_transport_layer_protocol *prot); -void grub_net_transport_layer_protocol_unregister (struct grub_net_transport_layer_protocol *prot); -struct grub_net_transport_layer_protocol *grub_net_transport_layer_protocol_get (grub_net_protocol_id_t id); -void grub_net_network_layer_protocol_register (struct grub_net_network_layer_protocol *prot); -void grub_net_network_layer_protocol_unregister (struct grub_net_network_layer_protocol *prot); -struct grub_net_network_layer_protocol *grub_net_network_layer_protocol_get (grub_net_protocol_id_t id); -void grub_net_link_layer_protocol_register (struct grub_net_link_layer_protocol *prot); -void grub_net_link_layer_protocol_unregister (struct grub_net_link_layer_protocol *prot); -struct grub_net_link_layer_protocol *grub_net_link_layer_protocol_get (grub_net_protocol_id_t id); + #endif diff --cc include/grub/net/udp.h index 000000000,dfc1776a4..f1992467d mode 000000,100644..100644 --- a/include/grub/net/udp.h +++ b/include/grub/net/udp.h @@@ -1,0 -1,23 +1,31 @@@ + #ifndef GRUB_NET_UDP_HEADER + #define GRUB_NET_UDP_HEADER 1 -#include ++#include ++#include + + struct udphdr + { + grub_uint16_t src; + grub_uint16_t dst; + grub_uint16_t len; + grub_uint16_t chksum; + } __attribute__ ((packed)); + -struct udp_interf -{ - grub_uint16_t src; - grub_uint16_t dst; -}; ++grub_err_t ++grub_net_send_udp_packet (const grub_net_network_level_address_t *target, ++ struct grub_net_buff *nb, grub_uint16_t srcport, ++ grub_uint16_t destport); ++ ++ ++grub_err_t ++grub_net_recv_udp_packets (struct grub_net_network_level_interface *inf); ++ ++grub_err_t ++grub_net_recv_udp_packet (const grub_net_network_level_address_t *target, ++ struct grub_net_buff *buf, ++ grub_uint16_t srcport, grub_uint16_t destport); + ++#define FOR_NET_UDP_PACKETS(inf, var) FOR_PACKETS(inf->udp_pending, var) + + -void udp_ini(void); -void udp_fini(void); + #endif