]> git.enpas.org Git - revag-bap.git/blob - vw-bap-frame.c
vw-bap.h: Fix payload length commend
[revag-bap.git] / vw-bap-frame.c
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "vw-bap.h"
7
8
9
10 struct BAP_Frame* vw_bap_frame_alloc(void)
11 {
12         struct BAP_Frame* bap_frame;
13
14         bap_frame = calloc(1, sizeof(struct BAP_Frame));
15
16         return bap_frame;
17 }
18
19
20 void vw_bap_frame_free(struct BAP_Frame *bap_frame)
21 {
22         free(bap_frame);
23 }
24
25
26 int vw_bap_frame_is_valid(struct BAP_Frame *bap_frame)
27 {
28         if ( 0
29                 || (bap_frame->opcode > 7)
30                 || (bap_frame->node > 63)
31                 || (bap_frame->function > 63)
32                 || (bap_frame->len > 4095)
33                 || (!bap_frame->is_multiframe && bap_frame->len > 6)
34                 ) {
35                 return 0;
36         }
37
38         return 1;
39 }
40
41
42 void vw_bap_frame_dump(struct BAP_Frame *bap_frame)
43 {
44         unsigned i;
45
46         printf("%u. %2i/%-2i .%02i --",
47                 bap_frame->opcode,
48                 bap_frame->node,
49                 bap_frame->function,
50                 bap_frame->len);
51
52         for (i = 0; i < bap_frame->len; i++) {
53                 if (!(i % 4)) {
54                         printf(" ");
55                 }
56                 printf("%02x", (unsigned char)(bap_frame->data[i]));
57         }
58
59         printf("\n        '");
60         for (i = 0; i < bap_frame->len; i++) {
61                 unsigned char c = bap_frame->data[i];
62                 if (!isprint(c) || c == '\n' || c == '\r') {
63                         c = '.';
64                 }
65                 printf("%c", c);
66         }
67         printf("'");
68
69         printf("\n");
70
71         fflush(stdout);
72 }