Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/817977/?format=api
{ "id": 817977, "url": "http://patchwork.ozlabs.org/api/patches/817977/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20170924195716.3433-18-xypron.glpk@gmx.de/", "project": { "id": 18, "url": "http://patchwork.ozlabs.org/api/projects/18/?format=api", "name": "U-Boot", "link_name": "uboot", "list_id": "u-boot.lists.denx.de", "list_email": "u-boot@lists.denx.de", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170924195716.3433-18-xypron.glpk@gmx.de>", "list_archive_url": null, "date": "2017-09-24T19:57:16", "name": "[U-Boot,17/17] efi_loader: supply EFI network test", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "57682776687ddc3c57a9269fde6c979d08d79ada", "submitter": { "id": 61270, "url": "http://patchwork.ozlabs.org/api/people/61270/?format=api", "name": "Heinrich Schuchardt", "email": "xypron.glpk@gmx.de" }, "delegate": { "id": 3400, "url": "http://patchwork.ozlabs.org/api/users/3400/?format=api", "username": "agraf", "first_name": "Alexander", "last_name": "Graf", "email": "agraf@suse.de" }, "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/20170924195716.3433-18-xypron.glpk@gmx.de/mbox/", "series": [ { "id": 4841, "url": "http://patchwork.ozlabs.org/api/series/4841/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=4841", "date": "2017-09-24T19:57:03", "name": "efi_loader: Simple Network Protocol", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/4841/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/817977/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/817977/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<u-boot-bounces@lists.denx.de>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": "ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)", "Received": [ "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3y0dT86gnVz9t3R\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 25 Sep 2017 06:03:56 +1000 (AEST)", "by lists.denx.de (Postfix, from userid 105)\n\tid 89B47C220FC; Sun, 24 Sep 2017 20:01:35 +0000 (UTC)", "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id AAD69C2213F;\n\tSun, 24 Sep 2017 19:58:50 +0000 (UTC)", "by lists.denx.de (Postfix, from userid 105)\n\tid 8B7F0C22141; Sun, 24 Sep 2017 19:58:21 +0000 (UTC)", "from mout.gmx.net (mout.gmx.net [212.227.17.22])\n\tby lists.denx.de (Postfix) with ESMTPS id E2C01C220F3\n\tfor <u-boot@lists.denx.de>; Sun, 24 Sep 2017 19:58:17 +0000 (UTC)", "from workstation4.fritz.box ([84.118.154.110]) by mail.gmx.com\n\t(mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id\n\t0LnUna-1dR09A2pG2-00hf8y; Sun, 24 Sep 2017 21:57:34 +0200" ], "X-Spam-Checker-Version": "SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de", "X-Spam-Level": "", "X-Spam-Status": "No, score=-0.7 required=5.0 tests=FREEMAIL_FROM,\n\tRCVD_IN_DNSWL_LOW,\n\tRCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no\n\tversion=3.4.0", "From": "Heinrich Schuchardt <xypron.glpk@gmx.de>", "To": "Alexander Graf <agraf@suse.de>", "Date": "Sun, 24 Sep 2017 21:57:16 +0200", "Message-Id": "<20170924195716.3433-18-xypron.glpk@gmx.de>", "X-Mailer": "git-send-email 2.14.1", "In-Reply-To": "<20170924195716.3433-1-xypron.glpk@gmx.de>", "References": "<20170924195716.3433-1-xypron.glpk@gmx.de>", "X-Provags-ID": "V03:K0:FndgS0nGPFX+/1qgWofcfTLSdUQCSALt6xErLwkm0YiWiqTBXGr\n\ti4cqRUBGgV/7eJLCRhdB1VUz3BkW1ByQQw7+Pzu6tt0BHydX9NlFWCyj2FQ7SHx2k3B0Od8\n\ttfcjwyHP+mrIJN0jOehE2GJOC00lBLOe0Z1OgL8d7LCIjo6+6xuVmm3ND64OBZtGwx2ZZ/d\n\tSlUAQAuVQpuUwoFKmsXqw==", "X-UI-Out-Filterresults": "notjunk:1; V01:K0:AeI6eVIf2ek=:la2KIWSw+hV3d74IfaB2xm\n\tE/LtpHEKjf0GrOtnfMOBl0yN5i7nFn71qys+sR8EE8t4e9IgYbytIQQUMQlvqaWfTdnnuz155\n\tjKaRMo1VjVIrPflysBnUh/Fb7SAcCYKp1b9/WRfaKTpExj5rtq96yCf3W7z2jNUWU8+7+VA1o\n\tFKXAHs0FWtdZFrWCTOIcPjYSm+wH78R7I8F8WYKpwyI4KdgPL1m6u2TMvCKxE+ckOn03PQ9++\n\tcMw+8EscB8LtL1DdVkMoNerJzCAk+Rl8sEWCKhq+rm4hqDQIAvJeqGlNnPzZH7uX8PcLlu2v4\n\tK0RgGGKeujNzas+00t3X+0UxV0gLKeR02a6fq3I5RuLqC8+iOBDcSdU1pwJ7I7y9kjuI6O7sA\n\tDXcZ0l+hnHXniRrdIy7iVJelFeQjEu9jEgSJ1UyiGhcMlfM4OVnUHgbPelTUgxr+MedeMjMxh\n\tcZOQBy05m3Sth3h74JBpdBopbNKHuotGf3Lg6yr6qQaWgGCbYerrqcih/S/pPvGffxVI9wUMr\n\th7Xhr6hrvLZ73AzYYRSZ69nqATryjRbSBqwdvRwnlaIFQruk4Xaqy/v+tMEmv6lhQhvlBQXPz\n\tmNYQZoBV3tZkLWqSFohCX/xwky2tJtaaVaAWD9/mAmhmrF6xPNYHMUTERSuD/8JsMQfR6gaS1\n\t0I2PFZQq0T15HL6XmTvZXplilA20xac/+yctIZ9eD6/Z87Z3OsEetxrkC9RI5vCmvra7uXdrK\n\tyrFQ5J0o2bVL2R89ZjidPXJZzCdDGLaqfvHlR+pQk1+ifLNCoV+8dRDwhPrZeuFPillFMLjri\n\tLROLSS+Gkl80ur9yjlirCoQELX/yg==", "Cc": "Heinrich Schuchardt <xypron.glpk@gmx.de>, u-boot@lists.denx.de", "Subject": "[U-Boot] [PATCH 17/17] efi_loader: supply EFI network test", "X-BeenThere": "u-boot@lists.denx.de", "X-Mailman-Version": "2.1.18", "Precedence": "list", "List-Id": "U-Boot discussion <u-boot.lists.denx.de>", "List-Unsubscribe": "<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>", "List-Archive": "<http://lists.denx.de/pipermail/u-boot/>", "List-Post": "<mailto:u-boot@lists.denx.de>", "List-Help": "<mailto:u-boot-request@lists.denx.de?subject=help>", "List-Subscribe": "<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "base64", "Errors-To": "u-boot-bounces@lists.denx.de", "Sender": "\"U-Boot\" <u-boot-bounces@lists.denx.de>" }, "content": "This patch provices an EFI application to check the correct function\nof the Simple Network Protocol implementation.\n\nIt sends a DHCP request and analyzes the DHCP offer.\n\nDifferent error conditions including a 10s timeout are checked.\n\nA successful execution will look like this:\n\n=> bootefi nettest\nScanning disk ide.blk#0...\nFound 1 disks\nWARNING: Invalid device tree, expect boot to fail\nNetwork test\nDHCP Discover\nDHCP reply received from 192.168.76.2 (52:55:c0:a8:4c:02)\nas broadcast message.\nOK. The test was completed successfully.\n\nSigned-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>\n---\n lib/efi_selftest/Makefile | 3 +\n lib/efi_selftest/efi_selftest_snp.c | 442 ++++++++++++++++++++++++++++++++++++\n 2 files changed, 445 insertions(+)\n create mode 100644 lib/efi_selftest/efi_selftest_snp.c", "diff": "diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile\nindex 30f1960933..9bfecf357b 100644\n--- a/lib/efi_selftest/Makefile\n+++ b/lib/efi_selftest/Makefile\n@@ -15,6 +15,8 @@ CFLAGS_efi_selftest_events.o := $(CFLAGS_EFI)\n CFLAGS_REMOVE_efi_selftest_events.o := $(CFLAGS_NON_EFI)\n CFLAGS_efi_selftest_exitbootservices.o := $(CFLAGS_EFI)\n CFLAGS_REMOVE_efi_selftest_exitbootservices.o := $(CFLAGS_NON_EFI)\n+CFLAGS_efi_selftest_snp.o := $(CFLAGS_EFI)\n+CFLAGS_REMOVE_efi_selftest_snp.o := $(CFLAGS_NON_EFI)\n CFLAGS_efi_selftest_tpl.o := $(CFLAGS_EFI)\n CFLAGS_REMOVE_efi_selftest_tpl.o := $(CFLAGS_NON_EFI)\n \n@@ -23,4 +25,5 @@ efi_selftest.o \\\n efi_selftest_console.o \\\n efi_selftest_events.o \\\n efi_selftest_exitbootservices.o \\\n+efi_selftest_snp.o \\\n efi_selftest_tpl.o\ndiff --git a/lib/efi_selftest/efi_selftest_snp.c b/lib/efi_selftest/efi_selftest_snp.c\nnew file mode 100644\nindex 0000000000..7bb81208ad\n--- /dev/null\n+++ b/lib/efi_selftest/efi_selftest_snp.c\n@@ -0,0 +1,442 @@\n+/*\n+ * efi_selftest_snp\n+ *\n+ * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>\n+ *\n+ * SPDX-License-Identifier:\tGPL-2.0+\n+ *\n+ * This unit test covers the Simple Network Protocol as well as\n+ * the CopyMem and SetMem boottime services.\n+ *\n+ * A DHCP discover message is sent. The test is successful if a\n+ * DHCP reply is received.\n+ *\n+ * TODO: Once ConnectController and DisconnectController are implemented\n+ *\t we should connect our code as controller.\n+ */\n+\n+#include <efi_selftest.h>\n+\n+/*\n+ * MAC address for broadcasts\n+ */\n+static const u8 BROADCAST_MAC[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\n+\n+struct dhcp_hdr {\n+\tu8 op;\n+#define BOOTREQUEST 1\n+#define BOOTREPLY 2\n+\tu8 htype;\n+# define HWT_ETHER 1\n+\tu8 hlen;\n+# define HWL_ETHER 6\n+\tu8 hops;\n+\tu32 xid;\n+\tu16 secs;\n+\tu16 flags;\n+#define DHCP_FLAGS_UNICAST\t0x0000\n+#define DHCP_FLAGS_BROADCAST\t0x0080\n+\tu32 ciaddr;\n+\tu32 yiaddr;\n+\tu32 siaddr;\n+\tu32 giaddr;\n+\tu8 chaddr[16];\n+\tu8 sname[64];\n+\tu8 file[128];\n+};\n+\n+/*\n+ * Message type option.\n+ */\n+#define DHCP_MESSAGE_TYPE\t0x35\n+#define DHCPDISCOVER\t\t1\n+#define DHCPOFFER\t\t2\n+#define DHCPREQUEST\t\t3\n+#define DHCPDECLINE\t\t4\n+#define DHCPACK\t\t\t5\n+#define DHCPNAK\t\t\t6\n+#define DHCPRELEASE\t\t7\n+\n+struct dhcp {\n+\tstruct ethernet_hdr eth_hdr;\n+\tstruct ip_udp_hdr ip_udp;\n+\tstruct dhcp_hdr dhcp_hdr;\n+\tu8 opt[128];\n+} __packed;\n+\n+static struct efi_boot_services *boottime;\n+static struct efi_simple_network *net;\n+static struct efi_event *timer;\n+static const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_GUID;\n+/* IP packet ID */\n+static unsigned int net_ip_id;\n+\n+/*\n+ * Compare memory.\n+ * We cannot use lib/string.c due to different CFLAGS values.\n+ *\n+ * Returns 0 if both buffers contain the same bytes.\n+ *\n+ * @buf1\tfirst buffer\n+ * @buf2\tsecond buffer\n+ * @length\tnumber of bytes to compare\n+ */\n+static int efi_st_memcmp(const void *buf1, const void *buf2, size_t length)\n+{\n+\tconst u8 *pos1 = buf1;\n+\tconst u8 *pos2 = buf2;\n+\n+\tfor (; length; --length) {\n+\t\tif (*pos1 != *pos2)\n+\t\t\treturn pos1 - pos2;\n+\t\t++pos1;\n+\t\t++pos2;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * Compute the checksum of the IP header. We cover even values of length only.\n+ * We cannot use net/checksum.c due to different CFLAGS values.\n+ *\n+ * @buf IP header\n+ * @len\tlength of header in bytes\n+ */\n+static unsigned int efi_ip_checksum(const void *buf, size_t len)\n+{\n+\tsize_t i;\n+\tu32 sum = 0;\n+\tconst u16 *pos = buf;\n+\n+\tfor (i = 0; i < len; i += 2)\n+\t\tsum += *pos++;\n+\n+\tsum = (sum >> 16) + (sum & 0xffff);\n+\tsum += sum >> 16;\n+\tsum = ~sum & 0xffff;\n+\n+\treturn sum;\n+}\n+\n+/*\n+ * Transmit a DHCPDISCOVER message.\n+ */\n+static efi_status_t send_dhcp_discover(void)\n+{\n+\tefi_status_t ret;\n+\tstruct dhcp p = {};\n+\n+\t/*\n+\t * Fill ethernet header\n+\t */\n+\tboottime->copy_mem(p.eth_hdr.et_dest, (void *)BROADCAST_MAC, ARP_HLEN);\n+\tboottime->copy_mem(p.eth_hdr.et_src, &net->mode->current_address,\n+\t\t\t ARP_HLEN);\n+\tp.eth_hdr.et_protlen = htons(PROT_IP);\n+\t/*\n+\t * Fill IP header\n+\t */\n+\tp.ip_udp.ip_hl_v\t= 0x45;\n+\tp.ip_udp.ip_len\t\t= htons(sizeof(struct dhcp) -\n+\t\t\t\t\tsizeof(struct ethernet_hdr));\n+\tp.ip_udp.ip_id\t\t= htons(++net_ip_id);\n+\tp.ip_udp.ip_off\t\t= htons(IP_FLAGS_DFRAG);\n+\tp.ip_udp.ip_ttl\t\t= 0xff; /* time to live */\n+\tp.ip_udp.ip_p\t\t= IPPROTO_UDP;\n+\tboottime->set_mem(&p.ip_udp.ip_dst, 4, 0xff);\n+\tp.ip_udp.ip_sum\t\t= efi_ip_checksum(&p.ip_udp, IP_HDR_SIZE);\n+\n+\t/*\n+\t * Fill UDP header\n+\t */\n+\tp.ip_udp.udp_src\t= htons(68);\n+\tp.ip_udp.udp_dst\t= htons(67);\n+\tp.ip_udp.udp_len\t= htons(sizeof(struct dhcp) -\n+\t\t\t\t\tsizeof(struct ethernet_hdr) -\n+\t\t\t\t\tsizeof(struct ip_hdr));\n+\t/*\n+\t * Fill DHCP header\n+\t */\n+\tp.dhcp_hdr.op\t\t= BOOTREQUEST;\n+\tp.dhcp_hdr.htype\t= HWT_ETHER;\n+\tp.dhcp_hdr.hlen\t\t= HWL_ETHER;\n+\tp.dhcp_hdr.flags\t= htons(DHCP_FLAGS_UNICAST);\n+\tboottime->copy_mem(&p.dhcp_hdr.chaddr,\n+\t\t\t &net->mode->current_address, ARP_HLEN);\n+\t/*\n+\t * Fill options\n+\t */\n+\tp.opt[0]\t= 0x63; /* DHCP magic cookie */\n+\tp.opt[1]\t= 0x82;\n+\tp.opt[2]\t= 0x53;\n+\tp.opt[3]\t= 0x63;\n+\tp.opt[4]\t= DHCP_MESSAGE_TYPE;\n+\tp.opt[5]\t= 0x01; /* length */\n+\tp.opt[6]\t= DHCPDISCOVER;\n+\tp.opt[7]\t= 0x39; /* maximum message size */\n+\tp.opt[8]\t= 0x02; /* length */\n+\tp.opt[9]\t= 0x02; /* 576 bytes */\n+\tp.opt[10]\t= 0x40;\n+\tp.opt[11]\t= 0xff; /* end of options */\n+\n+\t/*\n+\t * Transmit DHCPDISCOVER message.\n+\t */\n+\tret = net->transmit(net, 0, sizeof(struct dhcp), &p, NULL, NULL, 0);\n+\tif (ret != EFI_SUCCESS)\n+\t\tefi_st_error(\"Sending a DHCP request failed\\n\");\n+\telse\n+\t\tefi_st_printf(\"DHCP Discover\\n\");\n+\treturn ret;\n+}\n+\n+/*\n+ * Setup unit test.\n+ *\n+ * Create a 1 s periodic timer.\n+ * Start the network driver.\n+ *\n+ * @handle:\thandle of the loaded image\n+ * @systable:\tsystem table\n+ */\n+static int setup(const efi_handle_t handle,\n+\t\t const struct efi_system_table *systable)\n+{\n+\tefi_status_t ret;\n+\n+\tboottime = systable->boottime;\n+\n+\t/*\n+\t * Create a timer event.\n+\t */\n+\tret = boottime->create_event(EVT_TIMER, TPL_CALLBACK, NULL, NULL,\n+\t\t\t\t &timer);\n+\tif (ret != EFI_SUCCESS) {\n+\t\tefi_st_error(\"Failed to create event\\n\");\n+\t\treturn 1;\n+\t}\n+\t/*\n+\t * Set timer period to 1s.\n+\t */\n+\tret = boottime->set_timer(timer, EFI_TIMER_PERIODIC, 10000000);\n+\tif (ret != EFI_SUCCESS) {\n+\t\tefi_st_error(\"Failed to locate simple network protocol\\n\");\n+\t\treturn 1;\n+\t}\n+\t/*\n+\t * Find an interface implementing the SNP protocol.\n+\t */\n+\tret = boottime->locate_protocol(&efi_net_guid, NULL, (void **)&net);\n+\tif (ret != EFI_SUCCESS) {\n+\t\tefi_st_error(\"Failed to locate simple network protocol\\n\");\n+\t\treturn 1;\n+\t}\n+\t/*\n+\t * Check hardware address size.\n+\t */\n+\tif (!net->mode) {\n+\t\tefi_st_error(\"Mode not provided\\n\");\n+\t\treturn 1;\n+\t}\n+\tif (net->mode->hwaddr_size != ARP_HLEN) {\n+\t\tefi_st_error(\"HwAddressSize = %u, expected %u\\n\",\n+\t\t\t net->mode->hwaddr_size, ARP_HLEN);\n+\t\treturn 1;\n+\t}\n+\t/*\n+\t * Check that WaitForPacket event exists.\n+\t */\n+\tif (!net->wait_for_packet) {\n+\t\tefi_st_error(\"WaitForPacket event missing\\n\");\n+\t\treturn 1;\n+\t}\n+\t/*\n+\t * Initialize network adapter.\n+\t */\n+\tret = net->initialize(net, 0, 0);\n+\tif (ret != EFI_SUCCESS) {\n+\t\tefi_st_error(\"Failed to initialize network adapter\\n\");\n+\t\treturn 1;\n+\t}\n+\t/*\n+\t * Start network adapter.\n+\t */\n+\tret = net->start(net);\n+\tif (ret != EFI_SUCCESS) {\n+\t\tefi_st_error(\"Failed to start network adapter\\n\");\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * Execute unit test.\n+ *\n+ * A DHCP discover message is sent. The test is successful if a\n+ * DHCP reply is received within 10 seconds.\n+ */\n+static int execute(void)\n+{\n+\tefi_status_t ret;\n+\tstruct efi_event *events[2];\n+\tsize_t index;\n+\tunion {\n+\t\tstruct dhcp p;\n+\t\tu8 b[PKTSIZE];\n+\t} buffer;\n+\tstruct efi_mac_address srcaddr;\n+\tstruct efi_mac_address destaddr;\n+\tsize_t buffer_size;\n+\tu8 *addr;\n+\t/*\n+\t * The timeout is to occur after 10 s.\n+\t */\n+\tunsigned int timeout = 10;\n+\n+\t/*\n+\t * Send DHCP discover message\n+\t */\n+\tret = send_dhcp_discover();\n+\tif (ret != EFI_SUCCESS)\n+\t\treturn 1;\n+\n+\t/*\n+\t * If we would call WaitForEvent only with the WaitForPacket event,\n+\t * our code would block until a packet is received which might never\n+\t * occur. By calling WaitFor event with both a timer event and the\n+\t * WaitForPacket event we can escape this blocking situation.\n+\t *\n+\t * If the timer event occurs before we have received a DHCP reply\n+\t * a further DHCP discover message is sent.\n+\t */\n+\tevents[0] = timer;\n+\tevents[1] = net->wait_for_packet;\n+\tfor (;;) {\n+\t\t/*\n+\t\t * Wait for packet to be received or timer event.\n+\t\t */\n+\t\tboottime->wait_for_event(2, events, &index);\n+\t\tif (index == 0) {\n+\t\t\t/*\n+\t\t\t * The timer event occurred. Check for timeout.\n+\t\t\t */\n+\t\t\t--timeout;\n+\t\t\tif (!timeout) {\n+\t\t\t\tefi_st_error(\"Timeout occurred\\n\");\n+\t\t\t\treturn 1;\n+\t\t\t}\n+\t\t\t/*\n+\t\t\t * Send further DHCP discover message\n+\t\t\t */\n+\t\t\tret = send_dhcp_discover();\n+\t\t\tif (ret != EFI_SUCCESS)\n+\t\t\t\treturn 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\t/*\n+\t\t * Receive packet\n+\t\t */\n+\t\tbuffer_size = sizeof(buffer);\n+\t\tnet->receive(net, NULL, &buffer_size, &buffer,\n+\t\t\t &srcaddr, &destaddr, NULL);\n+\t\tif (ret != EFI_SUCCESS) {\n+\t\t\tefi_st_error(\"Failed to receive packet\");\n+\t\t\treturn 1;\n+\t\t}\n+\t\t/*\n+\t\t * Check the packet is meant for this system.\n+\t\t * Unfortunately QEMU ignores the broadcast flag.\n+\t\t * So we have to check for broadcasts too.\n+\t\t */\n+\t\tif (efi_st_memcmp(&destaddr, &net->mode->current_address,\n+\t\t\t\t ARP_HLEN) &&\n+\t\t efi_st_memcmp(&destaddr, BROADCAST_MAC, ARP_HLEN))\n+\t\t\tcontinue;\n+\t\t/*\n+\t\t * Check this is a DHCP reply\n+\t\t */\n+\t\tif (buffer.p.eth_hdr.et_protlen != ntohs(PROT_IP) ||\n+\t\t buffer.p.ip_udp.ip_hl_v != 0x45 ||\n+\t\t buffer.p.ip_udp.ip_p != IPPROTO_UDP ||\n+\t\t buffer.p.ip_udp.udp_src != ntohs(67) ||\n+\t\t buffer.p.ip_udp.udp_dst != ntohs(68) ||\n+\t\t buffer.p.dhcp_hdr.op != BOOTREPLY)\n+\t\t\tcontinue;\n+\t\t/*\n+\t\t * We successfully received a DHCP reply.\n+\t\t */\n+\t\tbreak;\n+\t}\n+\n+\t/*\n+\t * Write a log message.\n+\t */\n+\taddr = (u8 *)&buffer.p.ip_udp.ip_src;\n+\tefi_st_printf(\"DHCP reply received from %u.%u.%u.%u (%pm) \",\n+\t\t addr[0], addr[1], addr[2], addr[3], &srcaddr);\n+\tif (!efi_st_memcmp(&destaddr, BROADCAST_MAC, ARP_HLEN))\n+\t\tefi_st_printf(\"as broadcast message.\\n\");\n+\telse\n+\t\tefi_st_printf(\"as unicast message.\\n\");\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Tear down unit test.\n+ *\n+ * Close the timer event created in setup.\n+ * Shut down the network adapter.\n+ */\n+static int teardown(void)\n+{\n+\tefi_status_t ret;\n+\tint exit_status = 0;\n+\n+\tif (timer) {\n+\t\t/*\n+\t\t * Stop timer.\n+\t\t */\n+\t\tret = boottime->set_timer(timer, EFI_TIMER_STOP, 0);\n+\t\tif (ret != EFI_SUCCESS) {\n+\t\t\tefi_st_error(\"Failed to stop timer\");\n+\t\t\texit_status = 1;\n+\t\t}\n+\t\t/*\n+\t\t * Close timer event.\n+\t\t */\n+\t\tret = boottime->close_event(timer);\n+\t\tif (ret != EFI_SUCCESS) {\n+\t\t\tefi_st_error(\"Failed to close event\");\n+\t\t\texit_status = 1;\n+\t\t}\n+\t}\n+\tif (net) {\n+\t\t/*\n+\t\t * Stop network adapter.\n+\t\t */\n+\t\tret = net->stop(net);\n+\t\tif (ret != EFI_SUCCESS) {\n+\t\t\tefi_st_error(\"Failed to stop network adapter\\n\");\n+\t\t\texit_status = 1;\n+\t\t}\n+\t\t/*\n+\t\t * Shut down network adapter.\n+\t\t */\n+\t\tret = net->shutdown(net);\n+\t\tif (ret != EFI_SUCCESS) {\n+\t\t\tefi_st_error(\"Failed to shut down network adapter\\n\");\n+\t\t\texit_status = 1;\n+\t\t}\n+\t}\n+\n+\treturn exit_status;\n+}\n+\n+EFI_UNIT_TEST(snp) = {\n+\t.name = \"simple network protocol\",\n+\t.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,\n+\t.setup = setup,\n+\t.execute = execute,\n+\t.teardown = teardown,\n+};\n", "prefixes": [ "U-Boot", "17/17" ] }