5 AVL_TREE(rings
, udebug_id_cmp
, true, NULL
);
7 struct client_ring
*client_ring_get_by_id(struct client
*cl
, uint32_t id
)
11 list_for_each_entry(r
, &cl
->bufs
, list
)
18 static uint32_t gen_ring_id(void)
22 if (!urandom
&& (urandom
= fopen("/dev/urandom", "r")) == NULL
)
25 if (fread(&val
, sizeof(val
), 1, urandom
) != 1)
31 struct client_ring
*client_ring_alloc(struct client
*cl
)
38 static const struct blobmsg_policy policy
[__RING_ATTR_MAX
] = {
39 [RING_ATTR_NAME
] = { "name", BLOBMSG_TYPE_STRING
},
40 [RING_ATTR_FLAGS
] = { "flags", BLOBMSG_TYPE_ARRAY
},
42 struct udebug_client_msg
*msg
= &cl
->rx_buf
.msg
;
43 struct blob_attr
*tb
[__RING_ATTR_MAX
], *meta
;
44 struct client_ring
*r
;
48 DC(2, cl
, "missing file descriptor");
52 meta_len
= blob_pad_len(&cl
->rx_buf
.data
);
53 r
= calloc_a(sizeof(*r
), &meta
, meta_len
);
54 memcpy(meta
, cl
->rx_buf
.buf
, meta_len
);
56 blobmsg_parse_attr(policy
, __RING_ATTR_MAX
, tb
, meta
);
57 if (!tb
[RING_ATTR_NAME
]) {
58 DC(2, cl
, "missing ring name");
64 r
->name
= blobmsg_get_string(tb
[RING_ATTR_NAME
]);
65 r
->flags
= tb
[RING_ATTR_FLAGS
];
71 r
->ring_size
= msg
->ring_size
;
72 r
->data_size
= msg
->data_size
;
73 list_add_tail(&r
->list
, &cl
->bufs
);
75 r
->node
.key
= (void *)(uintptr_t)gen_ring_id();
76 avl_insert(&rings
, &r
->node
);
77 udebug_ubus_ring_notify(r
, true);
78 DC(2, cl
, "add ring %d [%x] ring_size=%x data_size=%x", r
->id
, ring_id(r
), r
->ring_size
, r
->data_size
);
83 void client_ring_free(struct client_ring
*r
)
85 DC(2, r
->cl
, "free ring %d [%x]", r
->id
, ring_id(r
));
86 udebug_ubus_ring_notify(r
, false);
87 avl_delete(&rings
, &r
->node
);