summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ip/snoopy/aoeata.c
blob: 5631182ab3ee7fd7be1356e0791b74d44eb7ba85 (plain)
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
#include <u.h>
#include <libc.h>
#include <ip.h>
#include "dat.h"
#include "protos.h"

typedef struct{
	uchar	aflag;
	uchar	feat;
	uchar	sectors;
	uchar	cmd;
	uchar	lba[6];
}Hdr;

enum{
	Hsize	= 10,
};

enum{
	Oaflag,
	Ocmd,
	Ofeat,
	Osectors,
	Olba,

	Ostat,
	Oerr,
};

static Field p_fields[] =
{
	{"aflag",	Fnum,	Oaflag,		"aflag",		},
	{"cmd",		Fnum,	Ocmd,		"command register",	},
	{"feat",	Fnum,	Ofeat,		"features",		},
	{"sectors",	Fnum,	Osectors,	"number of sectors",	},
	{"lba",		Fnum,	Olba,		"lba",			},
	{"stat",	Fnum,	Ostat,		"status",		},
	{"err",		Fnum,	Oerr,		"error",		},
	{0}
};

static void
p_compile(Filter *f)
{
	if(f->op == '='){
		compile_cmp(aoeata.name, f, p_fields);
		return;
	}
	sysfatal("unknown aoeata field: %s", f->s);
}

uvlong
llba(uchar *c)
{
	uvlong l;

	l = c[0];
	l |= c[1]<<8;
	l |= c[2]<<16;
	l |= c[3]<<24;
	l |= (uvlong)c[4]<<32;
	l |= (uvlong)c[5]<<40;
	return l;
}

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 Oaflag:
		return h->aflag == f->ulv;
	case Ocmd:
		return h->cmd == f->ulv;
	case Ofeat:
		return h->feat == f->ulv;
	case Osectors:
		return h->sectors == f->ulv;
	case Olba:
		return llba(h->lba) == f->vlv;

	/* this is wrong, but we don't have access to the direction here */
	case Ostat:
		return h->cmd == f->ulv;
	case Oerr:
		return h->feat == 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 = nil;

	m->p = seprint(m->p, m->e, "aflag=%ux errfeat=%ux sectors=%ux cmdstat=%ux lba=%lld",
		h->aflag, h->feat, h->sectors, h->cmd, llba(h->lba));
	return 0;
}

Proto aoeata =
{
	"aoeata",
	p_compile,
	p_filter,
	p_seprint,
	nil,
	nil,
	p_fields,
	defaultframer,
};