-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaoecmd.c
96 lines (79 loc) · 1.51 KB
/
aoecmd.c
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
/*
* This file is part of the UCB release of Plan 9. It is subject to the license
* terms in the LICENSE file found in the top-level directory of this
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
* part of the UCB release of Plan 9, including this file, may be copied,
* modified, propagated, or distributed except according to the terms contained
* in the LICENSE file.
*/
#include "ip.h"
#include "dat.h"
#include "protos.h"
typedef struct{
uint8_t bc[2];
uint8_t fw[2];
uint8_t sc;
uint8_t ccmd;
uint8_t len[2];
}Hdr;
enum{
Hsize = 8,
};
enum{
Ocmd,
};
static Field p_fields[] =
{
{"cmd", Fnum, Ocmd, "cmd", },
{0}
};
static void
p_compile(Filter *f)
{
if(f->op == '='){
compile_cmp(aoecmd.name, f, p_fields);
return;
}
sysfatal( "unknown aoecmd field: %s", f->s);
}
static int
p_filter(Filter *f, Msg *m)
{
Hdr *h;
if(m->pe - m->ps < Hsize)
return 0;
h = (Hdr*)m->ps;
m->ps += Hsize;
switch(f->subop){
case Ocmd:
return (h->ccmd & 0xf) == f->ulv;
}
return 0;
}
static int
p_seprint(Msg *m)
{
Hdr *h;
if(m->pe - m->ps < Hsize)
return 0;
h = (Hdr*)m->ps;
m->ps += Hsize;
/* no next protocol */
m->pr = NULL;
m->p = seprint(m->p, m->e, "bc=%d fw=%.4x sc=%d ver=%d ccmd=%d len=%d cfg=",
NetS(h->bc), NetS(h->fw), h->sc, h->ccmd >> 4, h->ccmd & 0xf,
NetS(h->len));
m->p = seprint(m->p, m->e, "%.*s", NetS(h->len), (char*)m->ps);
return 0;
}
Proto aoecmd =
{
"aoecmd",
p_compile,
p_filter,
p_seprint,
NULL,
NULL,
p_fields,
defaultframer,
};