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 19typedef struct { 20 struct nbmsg_t hdr; 21 uint8_t data[MAXSIZE]; 22} msg; 23 24typedef enum device_state { 25 UNKNOWN, OFFLINE, DEVICE, BOOTLOADER, 26} device_state_t; 27 28typedef struct device_info { 29 char nodename[MAX_NODENAME_LENGTH]; 30 char inet6_addr_s[INET6_ADDRSTRLEN]; 31 struct sockaddr_in6 inet6_addr; 32 device_state_t state; 33 uint32_t bootloader_version; 34 uint16_t bootloader_port; 35} device_info_t; 36 37extern uint16_t tftp_block_size, tftp_window_size; 38 39// Handle netboot command line options. 40int netboot_handle_getopt(int argc, char * const *argv); 41int netboot_handle_custom_getopt(int argc, char * const *argv, 42 const struct option *custom_opts, 43 size_t num_custom_opts, 44 bool (*opt_callback)(int ch, int argc, char * const *argv)); 45void netboot_usage(bool show_tftp_opts); 46 47// Returns whether discovery should continue or not. 48typedef bool (*on_device_cb)(device_info_t* device, void* cookie); 49int netboot_discover(unsigned port, const char* ifname, on_device_cb callback, void* cookie); 50 51int netboot_open(const char* hostname, const char* ifname, 52 struct sockaddr_in6* addr, bool make_connection); 53 54int netboot_txn(int s, msg* in, msg* out, int outlen); 55