/
ibft.h
183 lines (165 loc) · 4.69 KB
/
ibft.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*-
* Copyright (C) 2010 Daisuke Aoyama <aoyama@peach.ne.jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef IBFT_H
#define IBFT_H
#define IBFT_PTOV(addr) ((addr) + KERNBASE)
#define IBFT_VTOP(addr) ((addr) - KERNBASE)
#define IBFT_ALIGN 16
#define IBFT_SIGNATURE "iBFT"
#define IBFT_SIGNATURE_LENGTH 4
#define IBFT_LOW_ADDR (512*1024)
#define IBFT_HIGH_ADDR (1024*1024)
#define IBFT_IP_LEN 16
#define IBFT_ID_RESERVED 0
#define IBFT_ID_CONTROL 1
#define IBFT_ID_INITIATOR 2
#define IBFT_ID_NIC 3
#define IBFT_ID_TARGET 4
#define IBFT_ID_EXTENSIONS 5
/* word(2byte), dword(4byte) are little endian */
/* word must be on an even byte boundary */
/* strcutre must be on an 8 byte boundary */
/* IP address is stored in IPv6 format */
struct ibft_header {
/* iBFT Standard Structure Header */
uint8_t id;
uint8_t version;
uint16_t length;
uint8_t index;
uint8_t flags;
};
/* iBF Table Header 48 bytes */
struct ibft_table_header {
/* iBF Table Header */
uint8_t signature[4];
uint32_t length;
uint8_t revision;
uint8_t checksum;
uint8_t oemid[6];
uint8_t oemtableid[8];
uint8_t reserved[24];
};
/* Control Structure 18 bytes(min) */
struct ibft_control {
/* iBFT Standard Structure Header */
uint8_t id;
uint8_t version;
uint16_t length;
uint8_t index;
uint8_t flags;
/* Structure Type Specific */
uint16_t extensions;
uint16_t initiator_offset;
uint16_t nic0_offset;
uint16_t target0_offset;
uint16_t nic1_offset;
uint16_t target1_offset;
/* Optional Structure Expansion */
/* ... */
};
/* Initiator Structure 74 bytes */
struct ibft_initiator {
/* iBFT Standard Structure Header */
uint8_t id;
uint8_t version;
uint16_t length;
uint8_t index;
uint8_t flags;
/* Structure Type Specific */
uint8_t isns[16];
uint8_t slp[16];
uint8_t pri_radius[16];
uint8_t sec_radius[16];
/* Initiator */
uint16_t name_length;
uint16_t name_offset;
};
/* NIC Structure 102 bytes */
struct ibft_nic {
/* iBFT Standard Structure Header */
uint8_t id;
uint8_t version;
uint16_t length;
uint8_t index;
uint8_t flags;
/* Structure Type Specific */
uint8_t ip[16];
uint8_t mask_prefix;
uint8_t origin;
uint8_t gateway[16];
uint8_t pri_dns[16];
uint8_t sec_dns[16];
uint8_t dhcp[16];
uint16_t vlan;
uint8_t mac[6];
uint16_t pci_bus_dev_func; /* bus=8, dev=5, func=3 bits */
/* Host */
uint16_t host_name_length;
uint16_t host_name_offset;
};
/* Target Structure 54 bytes */
struct ibft_target {
/* iBFT Standard Structure Header */
uint8_t id;
uint8_t version;
uint16_t length;
uint8_t index;
uint8_t flags;
/* Structure Type Specific */
uint8_t ip[16];
uint16_t port;
uint64_t lun;
uint8_t chap_type;
uint8_t nic_index;
/* Target */
uint16_t name_length;
uint16_t name_offset;
/* CHAP */
uint16_t chap_name_length;
uint16_t chap_name_offset;
uint16_t chap_secret_length;
uint16_t chap_secret_offset;
/* Reverse CHAP */
uint16_t rev_chap_name_length;
uint16_t rev_chap_name_offset;
uint16_t rev_chap_secret_length;
uint16_t rev_chap_secret_offset;
};
uint8_t *ibft_get_signature(void);
uint8_t *ibft_get_nic0_mac(void);
struct ibft_initiator *ibft_get_initiator(void);
struct ibft_nic *ibft_get_nic0(void);
struct ibft_target *ibft_get_target0(void);
struct ibft_nic *ibft_get_nic1(void);
struct ibft_target *ibft_get_target1(void);
int ibft_is_zero_address(uint8_t *addr);
void ibft_print_address(uint8_t *addr);
void ibft_print_mac(uint8_t *addr);
int ibft_init(void);
#endif /* IBFT_H */