1 // Copyright 2016 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <arpa/inet.h> 8 #include <getopt.h> 9 #include <stdbool.h> 10 #include <stdint.h> 11 12 #include <zircon/boot/netboot.h> 13 14 #define MAXSIZE 1024 15 16 #define TFTP_DEFAULT_BLOCK_SZ 1024 17 #define TFTP_DEFAULT_WINDOW_SZ 256 18 19 typedef struct { 20 struct nbmsg_t hdr; 21 uint8_t data[MAXSIZE]; 22 } msg; 23 24 typedef enum device_state { 25 UNKNOWN, 26 OFFLINE, 27 DEVICE, 28 BOOTLOADER, 29 } device_state_t; 30 31 typedef struct device_info { 32 char nodename[MAX_NODENAME_LENGTH]; 33 char inet6_addr_s[INET6_ADDRSTRLEN]; 34 struct sockaddr_in6 inet6_addr; 35 device_state_t state; 36 uint32_t bootloader_version; 37 uint16_t bootloader_port; 38 } device_info_t; 39 40 extern uint16_t tftp_block_size, tftp_window_size; 41 42 // Handle netboot command line options. 43 int netboot_handle_getopt(int argc, char* const* argv); 44 int netboot_handle_custom_getopt(int argc, char* const* argv, 45 const struct option* custom_opts, 46 size_t num_custom_opts, 47 bool (*opt_callback)(int ch, int argc, char* const* argv)); 48 void netboot_usage(bool show_tftp_opts); 49 50 // Returns whether discovery should continue or not. 51 typedef bool (*on_device_cb)(device_info_t* device, void* cookie); 52 int netboot_discover(unsigned port, const char* ifname, on_device_cb callback, void* cookie); 53 54 int netboot_open(const char* hostname, const char* ifname, 55 struct sockaddr_in6* addr, bool make_connection); 56 57 int netboot_txn(int s, msg* in, msg* out, int outlen); 58