-
Notifications
You must be signed in to change notification settings - Fork 1
/
fc.go
419 lines (390 loc) · 8.44 KB
/
fc.go
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
// Generated by Fibre Channel protocol generator
// Any manual changes will be lost
package fibrechannel
import (
"bytes"
"fmt"
"io"
"github.com/bluecmd/fibrechannel/els"
"github.com/bluecmd/fibrechannel/encoding"
)
var _ = bytes.NewReader
const (
EOFn = 0x1 // TODO
EOFt = 0x2 // TODO
EOFrt = 0x3 // TODO
EOFdt = 0x4 // TODO
EOFni = 0x5 // TODO
EOFdti = 0x6 // TODO
EOFrti = 0x7 // TODO
EOFa = 0x8 // TODO
SOFf = 0x1 // TODO
SOFi4 = 0x2 // TODO
SOFi2 = 0x3 // TODO
SOFi3 = 0x4 // TODO
SOFn4 = 0x5 // TODO
SOFn2 = 0x6 // TODO
SOFn3 = 0x7 // TODO
SOFc4 = 0x8 // TODO
TypeBLS = 0x0 // TODO
TypeELS = 0x1 // TODO
TypeLLCSNAP = 0x4 // TODO
TypeIP = 0x5 // TODO
TypeFCP = 0x8 // TODO
TypeGPP = 0x9 // TODO
TypeSBToCU = 0x1b // FICON / FC-SB-3: Control Unit -> Channel
TypeSBFromCU = 0x1c // FICON / FC-SB-3: Channel -> Control Unit
TypeFCCT = 0x20 // TODO
TypeSWILS = 0x22 // TODO
TypeAL = 0x23 // TODO
TypeSNMP = 0x24 // TODO
TypeNVME = 0x28 // TODO
TypeSPINFAB = 0xee // TODO
TypeDIAG = 0xef // TODO
)
type CSCtl struct {
Data uint8
}
type EOF uint8
type Frame struct {
RCtl uint8
DestinationID [3]byte
CsctlPriority interface{}
SourceID [3]byte
fcType Type
FCtl FrameControl
SeqID uint8
DFCtl uint8
SeqCount uint16
OXID uint16
RXID uint16
Parameters [4]byte
Payload interface{}
}
type FrameControl struct {
TODO1 int
PriorityEnable bool
TODO2 int
}
type Prio struct {
Data uint8
}
type SOF uint8
type Type uint8
func (o *CSCtl) ReadFrom(r io.Reader) (int64, error) {
_io := encoding.Reader{R: r}
fixup := []func() (int64, error){}
_io.ReadObject(&o.Data)
if _io.Error != nil {
return _io.Pos, _io.Error
}
for _, f := range fixup {
if _, err := f(); err != nil {
return _io.Pos, err
}
}
return _io.Pos, nil
}
func (o *CSCtl) WriteTo(w io.Writer) (int64, error) {
_io := encoding.Writer{W: w}
_io.WriteObject(o.Data)
if _io.Error != nil {
return _io.Pos, _io.Error
}
return _io.Pos, nil
}
func (o *EOF) String() string {
switch *o {
case 0x1:
return "EOFn <0x1> (TODO)"
case 0x2:
return "EOFt <0x2> (TODO)"
case 0x3:
return "EOFrt <0x3> (TODO)"
case 0x4:
return "EOFdt <0x4> (TODO)"
case 0x5:
return "EOFni <0x5> (TODO)"
case 0x6:
return "EOFdti <0x6> (TODO)"
case 0x7:
return "EOFrti <0x7> (TODO)"
case 0x8:
return "EOFa <0x8> (TODO)"
default:
return fmt.Sprintf("--Invalid Enum Value-- <0x%x>", *o)
}
}
func (o *Frame) ReadFrom(r io.Reader) (int64, error) {
_io := encoding.Reader{R: r}
fixup := []func() (int64, error){}
_io.ReadObject(&o.RCtl)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.DestinationID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
var __o_CsctlPriority_CsctlPriority [1]byte
_io.Read(__o_CsctlPriority_CsctlPriority[:])
fixup = append(fixup, func() (int64, error) {
_io := encoding.Reader{R: bytes.NewReader(__o_CsctlPriority_CsctlPriority[:])}
switch o.FCtl.PriorityEnable {
case false:
i := &CSCtl{}
if n, err := i.ReadFrom(&_io); err != nil {
return n, err
}
o.CsctlPriority = i
case true:
i := &Prio{}
if n, err := i.ReadFrom(&_io); err != nil {
return n, err
}
o.CsctlPriority = i
}
return 1, nil
})
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.SourceID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.fcType)
if _io.Error != nil {
return _io.Pos, _io.Error
}
{
var bs [3]byte
_io.Read(bs[:])
if _io.Error != nil {
return _io.Pos, _io.Error
}
o.FCtl.TODO1 = ((0 | int(bs[0]&0xfc)) >> 2)
o.FCtl.PriorityEnable = (0 | int(bs[0]&0x2)) == 0x2
o.FCtl.TODO2 = (0 | int(bs[0]&0x1)<<16 | int(bs[1]&0xff)<<8 | int(bs[2]&0xff))
}
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.SeqID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.DFCtl)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.SeqCount)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.OXID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.RXID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.ReadObject(&o.Parameters)
if _io.Error != nil {
return _io.Pos, _io.Error
}
switch o.fcType {
case TypeELS:
i := &els.Frame{}
if n, err := i.ReadFrom(&_io); err != nil {
return n, err
}
o.Payload = i
}
if _io.Error != nil {
return _io.Pos, _io.Error
}
for _, f := range fixup {
if _, err := f(); err != nil {
return _io.Pos, err
}
}
return _io.Pos, nil
}
func (o *Frame) WriteTo(w io.Writer) (int64, error) {
_io := encoding.Writer{W: w}
switch o.CsctlPriority.(type) {
case CSCtl:
o.FCtl.PriorityEnable = false
case Prio:
o.FCtl.PriorityEnable = true
}
switch o.Payload.(type) {
case els.Frame:
o.fcType = TypeELS
}
_io.WriteObject(o.RCtl)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.DestinationID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
switch i := o.CsctlPriority.(type) {
case *Prio:
if n, err := i.WriteTo(&_io); err != nil {
return n, err
}
case *CSCtl:
if n, err := i.WriteTo(&_io); err != nil {
return n, err
}
default:
return _io.Pos, fmt.Errorf("Unsupported type %v", i)
}
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.SourceID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.fcType)
if _io.Error != nil {
return _io.Pos, _io.Error
}
{
var bs [3]byte
bool2int := func(v bool) int {
if v {
return 1
}
return 0
}
bs[0] = byte(0 | (int(o.FCtl.TODO1)<<2)&0xfc | (bool2int(o.FCtl.PriorityEnable)<<1)&0x2 | ((int(o.FCtl.TODO2))>>16)&0x1)
bs[1] = byte(0 | ((int(o.FCtl.TODO2))>>8)&0xff)
bs[2] = byte(0 | (int(o.FCtl.TODO2))&0xff)
_io.Write(bs[:])
}
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.SeqID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.DFCtl)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.SeqCount)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.OXID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.RXID)
if _io.Error != nil {
return _io.Pos, _io.Error
}
_io.WriteObject(o.Parameters)
if _io.Error != nil {
return _io.Pos, _io.Error
}
switch i := o.Payload.(type) {
case *els.Frame:
if n, err := i.WriteTo(&_io); err != nil {
return n, err
}
default:
return _io.Pos, fmt.Errorf("Unsupported type %v", i)
}
if _io.Error != nil {
return _io.Pos, _io.Error
}
return _io.Pos, nil
}
func (o *Prio) ReadFrom(r io.Reader) (int64, error) {
_io := encoding.Reader{R: r}
fixup := []func() (int64, error){}
_io.ReadObject(&o.Data)
if _io.Error != nil {
return _io.Pos, _io.Error
}
for _, f := range fixup {
if _, err := f(); err != nil {
return _io.Pos, err
}
}
return _io.Pos, nil
}
func (o *Prio) WriteTo(w io.Writer) (int64, error) {
_io := encoding.Writer{W: w}
_io.WriteObject(o.Data)
if _io.Error != nil {
return _io.Pos, _io.Error
}
return _io.Pos, nil
}
func (o *SOF) String() string {
switch *o {
case 0x1:
return "SOFf <0x1> (TODO)"
case 0x2:
return "SOFi4 <0x2> (TODO)"
case 0x3:
return "SOFi2 <0x3> (TODO)"
case 0x4:
return "SOFi3 <0x4> (TODO)"
case 0x5:
return "SOFn4 <0x5> (TODO)"
case 0x6:
return "SOFn2 <0x6> (TODO)"
case 0x7:
return "SOFn3 <0x7> (TODO)"
case 0x8:
return "SOFc4 <0x8> (TODO)"
default:
return fmt.Sprintf("--Invalid Enum Value-- <0x%x>", *o)
}
}
func (o *Type) String() string {
switch *o {
case 0x0:
return "TypeBLS <0x0> (TODO)"
case 0x1:
return "TypeELS <0x1> (TODO)"
case 0x4:
return "TypeLLCSNAP <0x4> (TODO)"
case 0x5:
return "TypeIP <0x5> (TODO)"
case 0x8:
return "TypeFCP <0x8> (TODO)"
case 0x9:
return "TypeGPP <0x9> (TODO)"
case 0x1b:
return "TypeSBToCU <0x1b> (FICON / FC-SB-3: Control Unit -> Channel)"
case 0x1c:
return "TypeSBFromCU <0x1c> (FICON / FC-SB-3: Channel -> Control Unit)"
case 0x20:
return "TypeFCCT <0x20> (TODO)"
case 0x22:
return "TypeSWILS <0x22> (TODO)"
case 0x23:
return "TypeAL <0x23> (TODO)"
case 0x24:
return "TypeSNMP <0x24> (TODO)"
case 0x28:
return "TypeNVME <0x28> (TODO)"
case 0xee:
return "TypeSPINFAB <0xee> (TODO)"
case 0xef:
return "TypeDIAG <0xef> (TODO)"
default:
return fmt.Sprintf("--Invalid Enum Value-- <0x%x>", *o)
}
}