aoe.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <ip.h>
  12. #include "dat.h"
  13. #include "protos.h"
  14. typedef struct{
  15. uint8_t verflags;
  16. uint8_t error;
  17. uint8_t major[2];
  18. uint8_t minor;
  19. uint8_t cmd;
  20. uint8_t tag[4];
  21. }Hdr;
  22. enum{
  23. Hsize = 10,
  24. };
  25. enum{
  26. Omajor,
  27. Ominor,
  28. Ocmd,
  29. };
  30. static Mux p_mux[] = {
  31. {"aoeata", 0},
  32. {"aoecmd", 1},
  33. {"aoemask", 2},
  34. {"aoerr", 3},
  35. {0},
  36. };
  37. static Field p_fields[] =
  38. {
  39. {"shelf", Fnum, Ominor, "shelf", },
  40. {"slot", Fnum, Omajor, "slot", },
  41. {"cmd", Fnum, Ocmd, "cmd", },
  42. {0}
  43. };
  44. static void
  45. p_compile(Filter *f)
  46. {
  47. Mux *m;
  48. if(f->op == '='){
  49. compile_cmp(aoe.name, f, p_fields);
  50. return;
  51. }
  52. for(m = p_mux; m->name; m++)
  53. if(strcmp(f->s, m->name) == 0){
  54. f->pr = m->pr;
  55. f->ulv = m->val;
  56. f->subop = Ocmd;
  57. return;
  58. }
  59. sysfatal("unknown aoe field: %s", f->s);
  60. }
  61. static int
  62. p_filter(Filter *f, Msg *m)
  63. {
  64. Hdr *h;
  65. if(m->pe - m->ps < Hsize)
  66. return 0;
  67. h = (Hdr*)m->ps;
  68. m->ps += Hsize;
  69. switch(f->subop){
  70. case Omajor:
  71. return NetS(h->major) == f->ulv;
  72. case Ominor:
  73. return h->minor == f->ulv;
  74. case Ocmd:
  75. return h->cmd == f->ulv;
  76. }
  77. return 0;
  78. }
  79. static int
  80. p_seprint(Msg *m)
  81. {
  82. Hdr *h;
  83. if(m->pe - m->ps < Hsize)
  84. return 0;
  85. h = (Hdr*)m->ps;
  86. m->ps += Hsize;
  87. demux(p_mux, h->cmd, h->cmd, m, &dump);
  88. m->p = seprint(m->p, m->e, "ver=%d flag=%4b err=%d %d.%d cmd=%x tag=%x",
  89. h->verflags >> 4, h->verflags & 0xf, h->error, NetS(h->major),
  90. h->minor, h->cmd, NetL(h->tag));
  91. return 0;
  92. }
  93. Proto aoe =
  94. {
  95. "aoe",
  96. p_compile,
  97. p_filter,
  98. p_seprint,
  99. p_mux,
  100. "%lu",
  101. p_fields,
  102. defaultframer,
  103. };