1/* 2 * Copyright (c) 2003-2014 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#ifndef _S_BSDP_H 25#define _S_BSDP_H 26 27/* 28 * bsdp.h 29 * - Boot Server Discovery Protocol (BSDP) definitions 30 */ 31 32/* 33 * Modification History 34 * 35 * Dieter Siegmund (dieter@apple.com) November 24, 1999 36 * - created 37 */ 38 39#include <mach/boolean.h> 40#include <string.h> 41#include <sys/types.h> 42#include "dhcp.h" 43#include "dhcp_options.h" 44 45/* 46 * The boot_image_id consists of: (highest byte,bit to lowest bit,byte: 47 * struct boot_image_id { 48 * u_int16_t attributes; 49 * u_int16_t index; 50 * }; 51 * 52 * The attributes field contains: 53 * struct bsdp_image_attributes { 54 * u_int16_t install:1, 55 * kind:7, 56 * reserved:8; 57 */ 58#define BOOT_IMAGE_ID_NULL ((bsdp_image_id_t)0) 59#define BSDP_IMAGE_INDEX_MAX 0xffff 60#define BSDP_IMAGE_ATTRIBUTES_INSTALL ((u_int16_t)0x8000) 61#define BSDP_IMAGE_ATTRIBUTES_KIND_MASK ((u_int16_t)0x7f00) 62#define BSDP_IMAGE_ATTRIBUTES_KIND_MAX 0x7f 63 64#define BSDP_PRIORITY_MIN ((bsdp_priority_t) 0) 65#define BSDP_PRIORITY_MAX ((bsdp_priority_t) 65535) 66 67#define BSDP_PRIORITY_BASE ((bsdp_priority_t) 32768) 68 69#define BSDP_VENDOR_CLASS_ID "AAPLBSDPC" 70#define BSDP_VERSION_1_0 ((unsigned short)0x0100) 71#define BSDP_VERSION_1_1 ((unsigned short)0x0101) 72#define BSDP_VERSION_0_0 ((unsigned short)0x0) 73 74typedef enum { 75 bsdp_image_kind_MacOS9 = 0, 76 bsdp_image_kind_MacOSX = 1, 77 bsdp_image_kind_MacOSXServer = 2, 78 bsdp_image_kind_Diagnostics = 3, 79} bsdp_image_kind_t; 80 81/* 82 * the maximum length of name 83 * = DHCP_OPTION_SIZE_MAX - OPTION_OFFSET - OPTION_OFFSET 84 * - sizeof(bsdp_image_description_t) 85 * = 255 (max option size) 86 * - 2 (vendor specific option's tag/len) 87 * - 2 (this option's tag/len) 88 * - 5 (this struct's boot_image_id + length) 89 * = 246 90 */ 91#define BSDP_IMAGE_NAME_MAX (DHCP_OPTION_SIZE_MAX - 2 * OPTION_OFFSET - 5) 92typedef struct { 93 u_int8_t boot_image_id[4]; 94 u_int8_t name_length; 95 u_int8_t name[0]; 96} bsdp_image_description_t; 97 98typedef u_int16_t bsdp_priority_t; 99typedef u_int16_t bsdp_version_t; 100typedef u_int32_t bsdp_image_id_t; 101 102static __inline__ u_int16_t 103bsdp_image_index(bsdp_image_id_t image_id) 104{ 105 return (image_id & 0xffff); 106} 107 108static __inline__ u_int16_t 109bsdp_image_attributes(bsdp_image_id_t image_id) 110{ 111 return (image_id >> 16); 112} 113 114static __inline__ bsdp_image_id_t 115bsdp_image_id_make(u_int16_t index, u_int16_t attributes) 116{ 117 return (index | ((bsdp_image_id_t)attributes << 16)); 118} 119 120static __inline__ boolean_t 121bsdp_image_index_is_server_local(u_int16_t index) 122{ 123 return (index < 4096); 124} 125 126static __inline__ boolean_t 127bsdp_image_identifier_is_server_local(u_int32_t identifier) 128{ 129 return (bsdp_image_index_is_server_local(bsdp_image_index(identifier))); 130} 131 132static __inline__ boolean_t 133bsdp_image_identifier_is_install(u_int32_t identifier) 134{ 135 if ((bsdp_image_attributes(identifier) & BSDP_IMAGE_ATTRIBUTES_INSTALL) 136 != 0) { 137 return (TRUE); 138 } 139 return (FALSE); 140} 141 142static __inline__ bsdp_image_kind_t 143bsdp_image_kind_from_attributes(u_int16_t attr) 144{ 145 return ((attr & BSDP_IMAGE_ATTRIBUTES_KIND_MASK) >> 8); 146} 147 148static __inline__ u_int16_t 149bsdp_image_attributes_from_kind(bsdp_image_kind_t kind) 150{ 151 return ((kind << 8) & BSDP_IMAGE_ATTRIBUTES_KIND_MASK); 152} 153 154typedef enum { 155 /* protocol-specific */ 156 bsdptag_message_type_e = 1, 157 bsdptag_version_e = 2, 158 bsdptag_server_identifier_e = 3, 159 bsdptag_server_priority_e = 4, 160 bsdptag_reply_port_e = 5, 161 bsdptag_boot_image_list_path_e = 6, /* not used */ 162 bsdptag_default_boot_image_e = 7, 163 bsdptag_selected_boot_image_e = 8, 164 bsdptag_boot_image_list_e = 9, 165 bsdptag_netboot_1_0_firmware_e = 10, 166 bsdptag_image_attributes_filter_list_e = 11, 167 bsdptag_max_message_size_e = 12, 168 169 /* protocol-specific bounds */ 170 bsdptag_first_e = 1, 171 bsdptag_last_e = 12, 172 173 /* image-specific */ 174 bsdptag_shadow_mount_path_e = 128, /* string (URL) */ 175 bsdptag_shadow_file_path_e = 129, /* string (URL) */ 176 bsdptag_machine_name_e = 130, /* string */ 177} bsdptag_t; 178 179typedef enum { 180 bsdp_msgtype_none_e = 0, 181 bsdp_msgtype_list_e = 1, 182 bsdp_msgtype_select_e = 2, 183 bsdp_msgtype_failed_e = 3, 184} bsdp_msgtype_t; 185 186dhcptype_t 187bsdptag_type(bsdptag_t tag); 188 189const char * 190bsdptag_name(bsdptag_t tag); 191 192const char * 193bsdp_msgtype_names(bsdp_msgtype_t type); 194 195/* 196 * Function: bsdp_parse_class_id 197 * 198 * Purpose: 199 * Parse the given option into the arch and system identifier 200 * fields. 201 * 202 * The format is "AAPLBSDPC/<arch>/<system_id>" for client-generated 203 * requests and "AAPLBSDPC" for server-generated responses. 204 */ 205boolean_t 206bsdp_parse_class_id(void * buf, int buf_len, char * arch, 207 char * sysid); 208#endif /* _S_BSDP_H */ 209