Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdlib.h>
#include <string.h>
#include <atomic.h>

#define BT_DBG_ENABLED IS_ENABLED(CONFIG_NBLE_DEBUG_RPC)
#include <bluetooth/log.h>
#include <bluetooth/gatt.h>
/* for bt_security_t */
#include <bluetooth/conn.h>

#ifdef CONFIG_PRINTK
#include <misc/printk.h>
#define PRINTK(...) printk(__VA_ARGS__)
#else
#define PRINTK(...)
#endif /* CONFIG_PRINTK */

#include "rpc.h"
#include "gap_internal.h"
#include "gatt_internal.h"

#include "rpc_functions_to_quark.h"

/* Build the list of prototypes and check that list are made only of matching
 * signatures
 */
#define FN_SIG_NONE(__fn)	void __fn(void);
LIST_FN_SIG_NONE
#undef FN_SIG_NONE

#define FN_SIG_S(__fn, __s)	void __fn(__s p_s);
LIST_FN_SIG_S
#undef FN_SIG_S

#define FN_SIG_P(__fn, __type)	void __fn(__type priv);
LIST_FN_SIG_P
#undef FN_SIG_P

#define FN_SIG_S_B(__fn, __s, __type, __length)				\
	void __fn(__s p_s, __type buf, __length length);
LIST_FN_SIG_S_B
#undef FN_SIG_S_B

#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2,	\
		     __type3)						\
	void __fn(__type1 p_buf1, __length1 length1, __type2 p_buf2,	\
		  __length2 length2, __type3 priv);
LIST_FN_SIG_B_B_P
#undef FN_SIG_B_B_P

#define FN_SIG_S_P(__fn, __s, __type)	void __fn(__s p_s, __type priv);
LIST_FN_SIG_S_P
#undef FN_SIG_S_P

#define FN_SIG_S_B_P(__fn, __s,  __type, __length, __type_ptr)		\
	void __fn(__s p_s, __type buf, __length length, __type_ptr priv);
LIST_FN_SIG_S_B_P
#undef FN_SIG_S_B_P

#define FN_SIG_S_B_B_P(__fn, __s,  __type1, __length1, __type2,		\
		       __length2, __type_ptr)				\
	void __fn(__s p_s, __type1 p_buf1, __length1 length1,		\
		  __type2 p_buf2, __length2 length2, __type_ptr priv);
LIST_FN_SIG_S_B_B_P
#undef FN_SIG_S_B_B_P

/* 1 - define the size check arrays */
#define FN_SIG_NONE(__fn)

#define FN_SIG_S(__fn, __s)				sizeof(*((__s)0)),

#define FN_SIG_P(__fn, __type)

#define FN_SIG_S_B(__fn, __s, __type, __length)		sizeof(*((__s)0)),

#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2,	\
		     __type3)				sizeof(*((__s)0)),

#define FN_SIG_S_P(__fn, __s, __type)			sizeof(*((__s)0)),

#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr)		\
							sizeof(*((__s)0)),

#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2,		\
		       __length2, __type3)		sizeof(*((__s)0)),

static uint8_t m_size_s[] = { LIST_FN_SIG_S };
static uint8_t m_size_s_b[] = { LIST_FN_SIG_S_B };
static uint8_t m_size_s_p[] = { LIST_FN_SIG_S_P };
static uint8_t m_size_s_b_p[] = { LIST_FN_SIG_S_B_P };
static uint8_t m_size_s_b_b_p[] = { LIST_FN_SIG_S_B_B_P };

#undef FN_SIG_NONE
#undef FN_SIG_S
#undef FN_SIG_P
#undef FN_SIG_S_B
#undef FN_SIG_B_B_P
#undef FN_SIG_S_P
#undef FN_SIG_S_B_P
#undef FN_SIG_S_B_B_P

/* 2- build the enumerations list */
#define FN_SIG_NONE(__fn)				fn_index_##__fn,
#define FN_SIG_S(__fn, __s)				FN_SIG_NONE(__fn)
#define FN_SIG_P(__fn, __type)				FN_SIG_NONE(__fn)
#define FN_SIG_S_B(__fn, __s, __type, __length)		FN_SIG_NONE(__fn)
#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2,	\
		     __type3)				FN_SIG_NONE(__fn)
#define FN_SIG_S_P(__fn, __s, __type)			FN_SIG_NONE(__fn)
#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr)		\
							FN_SIG_NONE(__fn)
#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2,		\
		       __length2, __type3)		FN_SIG_NONE(__fn)

/* Build the list of function indexes in the deserialization array */
enum { LIST_FN_SIG_NONE fn_none_index_max };
enum { LIST_FN_SIG_S fn_s_index_max };
enum { LIST_FN_SIG_P fn_p_index_max };
enum { LIST_FN_SIG_S_B fn_s_b_index_max };
enum { LIST_FN_SIG_B_B_P fn_b_b_p_index_max };
enum { LIST_FN_SIG_S_P fn_s_p_index_max };
enum { LIST_FN_SIG_S_B_P fn_s_b_p_index_max };
enum { LIST_FN_SIG_S_B_B_P fn_s_b_b_p_index_max };

#undef FN_SIG_NONE
#undef FN_SIG_S
#undef FN_SIG_P
#undef FN_SIG_S_B
#undef FN_SIG_B_B_P
#undef FN_SIG_S_P
#undef FN_SIG_S_B_P
#undef FN_SIG_S_B_B_P

/* 3- build the array */
#define FN_SIG_NONE(__fn)			[fn_index_##__fn] =	\
								(void *)__fn,
#define FN_SIG_S(__fn, __s)			FN_SIG_NONE(__fn)
#define FN_SIG_P(__fn, __type)			FN_SIG_NONE(__fn)
#define FN_SIG_S_B(__fn, __s, __type, __length)				\
						FN_SIG_NONE(__fn)
#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2,	\
		     __type3)			FN_SIG_NONE(__fn)
#define FN_SIG_S_P(__fn, __s, __type)		FN_SIG_NONE(__fn)
#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr)		\
						FN_SIG_NONE(__fn)
#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2,		\
		       __length2, __type3)	FN_SIG_NONE(__fn)

static void (*m_fct_none[])(void) = { LIST_FN_SIG_NONE };
static void (*m_fct_s[])(void *structure) = { LIST_FN_SIG_S };
static void (*m_fct_p[])(void *pointer) = { LIST_FN_SIG_P };
static void (*m_fct_s_b[])(void *structure, void *buffer,
			   uint8_t length) = { LIST_FN_SIG_S_B };
static void (*m_fct_b_b_p[])(void *buffer1, uint8_t length1,
			     void *buffer2, uint8_t length2,
			     void *pointer) = { LIST_FN_SIG_B_B_P };
static void (*m_fct_s_p[])(void *structure,
			   void *pointer) = { LIST_FN_SIG_S_P };
static void (*m_fct_s_b_p[])(void *structure, void *buffer, uint8_t length,
			     void *pointer) = { LIST_FN_SIG_S_B_P };
static void (*m_fct_s_b_b_p[])(void *structure, void *buffer1, uint8_t length1,
			       void *buffer2, uint8_t length2,
			       void *pointer) = { LIST_FN_SIG_S_B_B_P };

/* Build debug table to help development with this "robust" macro stuff */

#if defined(CONFIG_NBLE_DEBUG_RPC)

#undef FN_SIG_NONE
#undef FN_SIG_S
#undef FN_SIG_P
#undef FN_SIG_S_B
#undef FN_SIG_B_B_P
#undef FN_SIG_S_P
#undef FN_SIG_S_B_P
#undef FN_SIG_S_B_B_P

#define FN_SIG_NONE(__fn)			#__fn,
#define FN_SIG_S(__fn, __s)			FN_SIG_NONE(__fn)
#define FN_SIG_P(__fn, __type)			FN_SIG_NONE(__fn)
#define FN_SIG_S_B(__fn, __s, __type, __length)				\
						FN_SIG_NONE(__fn)
#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2,	\
		     __type3)			FN_SIG_NONE(__fn)
#define FN_SIG_S_P(__fn, __s, __type)		FN_SIG_NONE(__fn)
#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr)		\
						FN_SIG_NONE(__fn)
#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2,		\
		       __length2, __type3)	FN_SIG_NONE(__fn)

static char *debug_func_none[] = { LIST_FN_SIG_NONE };
static char *debug_func_s[] = { LIST_FN_SIG_S };
static char *debug_func_p[] = { LIST_FN_SIG_P };
static char *debug_func_s_b[] = { LIST_FN_SIG_S_B };
static char *debug_func_b_b_p[] = { LIST_FN_SIG_B_B_P };
static char *debug_func_s_p[] = { LIST_FN_SIG_S_P };
static char *debug_func_s_b_p[] = { LIST_FN_SIG_S_B_P };
static char *debug_func_s_b_b_p[] = { LIST_FN_SIG_S_B_B_P};

#define DBG_FUNC(name) BT_DBG("%s", name)
#else
#define DBG_FUNC(name)
#endif

#undef FN_SIG_NONE
#undef FN_SIG_S
#undef FN_SIG_P
#undef FN_SIG_S_B
#undef FN_SIG_B_B_P
#undef FN_SIG_S_P
#undef FN_SIG_S_B_P
#undef FN_SIG_S_B_B_P

#define DJB2_HASH(__h, __v) ((((__h) << 5) + (__h)) + (__v))

#define FN_SIG_NONE(__fn)						\
		hash = DJB2_HASH(hash, 1);

#define FN_SIG_S(__fn, __s)						\
	do {								\
		hash = DJB2_HASH(hash, 2);				\
		hash = DJB2_HASH(hash, sizeof(*((__s)0)));		\
	} while (0);

#define FN_SIG_P(__fn, __type)						\
		hash = DJB2_HASH(hash, 3);

#define FN_SIG_S_B(__fn, __s, __type, __length)				\
	do {								\
		hash = DJB2_HASH(hash, 4);				\
		hash = DJB2_HASH(hash, sizeof(*((__s)0)));		\
	} while (0);

#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2,	\
		     __type3)						\
	do {								\
		hash = DJB2_HASH(hash, 5);				\
		hash = DJB2_HASH(hash, sizeof(*((__s)0)));		\
	} while (0);

#define FN_SIG_S_P(__fn, __s, __type)					\
	do {								\
		hash = DJB2_HASH(hash, 6);				\
		hash = DJB2_HASH(hash, sizeof(*((__s)0)));		\
	} while (0);

#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr)		\
	do {								\
		hash = DJB2_HASH(hash, 7);				\
		hash = DJB2_HASH(hash, sizeof(*((__s)0)));		\
	} while (0);

#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2,		\
		       __length2, __type3)				\
	do {								\
		hash = DJB2_HASH(hash, 8);				\
		hash = DJB2_HASH(hash, sizeof(*((__s)0)));		\
	} while (0);

uint32_t rpc_deserialize_hash(void)
{
	uint32_t hash = 5381;

	LIST_FN_SIG_NONE;
	LIST_FN_SIG_S;
	LIST_FN_SIG_P;
	LIST_FN_SIG_S_B;
	LIST_FN_SIG_B_B_P;
	LIST_FN_SIG_S_P;
	LIST_FN_SIG_S_B_P;
	LIST_FN_SIG_S_B_B_P;

	return hash;
}

static void panic(int err)
{
	PRINTK("panic: errcode %d", err);

	while (true) {
	}
}

static void deserialize_struct(struct net_buf *buf, const uint8_t **struct_ptr,
			       uint8_t *struct_length)
{
	*struct_length = net_buf_pull_u8(buf);
	*struct_ptr = buf->data;
	net_buf_pull(buf, *struct_length);
}

static void deserialize_buf(struct net_buf *buf, const uint8_t **buf_ptr,
			    uint16_t *buf_len)
{
	uint8_t b;

	/* Get the current byte */
	b = net_buf_pull_u8(buf);
	*buf_len = b & 0x7F;
	if (b & 0x80) {
		/* Get the current byte */
		b = net_buf_pull_u8(buf);
		*buf_len += (uint16_t)b << 7;
	}

	/* Return the values */
	*buf_ptr = buf->data;

	net_buf_pull(buf, *buf_len);
}

static void deserialize_ptr(struct net_buf *buf, uintptr_t *priv)
{
	memcpy(priv, buf->data, sizeof(*priv));
	net_buf_pull(buf, sizeof(*priv));
}

static void deserialize_none(uint8_t fn_index, struct net_buf *buf)
{
	(void)buf;

	if (buf->len != 0) {
		panic(-1);
	}

	m_fct_none[fn_index]();
}

static void deserialize_s(uint8_t fn_index, struct net_buf *buf)
{
	const uint8_t *struct_ptr;
	uint8_t struct_length;

	deserialize_struct(buf, &struct_ptr, &struct_length);

	if (struct_length != m_size_s[fn_index]) {
		panic(-1);
	} else {
		/* Always align structures on word boundary */
		uintptr_t struct_data[(struct_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];

		memcpy(struct_data, struct_ptr, struct_length);

		m_fct_s[fn_index](struct_data);
	}
}

static void deserialize_p(uint8_t fn_index, struct net_buf *buf)
{
	uintptr_t priv;

	if (buf->len != sizeof(priv)) {
		panic(-1);
	}

	deserialize_ptr(buf, &priv);

	m_fct_p[fn_index]((void *)priv);
}

static void deserialize_s_b(uint8_t fn_index, struct net_buf *buf)
{
	const uint8_t *p_struct_data;
	uint8_t struct_length;
	const uint8_t *p_vbuf;
	uint16_t vbuf_length;

	deserialize_struct(buf, &p_struct_data, &struct_length);
	deserialize_buf(buf, &p_vbuf, &vbuf_length);

	if (struct_length != m_size_s_b[fn_index]) {
		panic(-1);
	} else {
		/* Always align structures on word boundary */
		uintptr_t struct_data[(struct_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		uintptr_t vbuf[(vbuf_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		void *buf = NULL;

		memcpy(struct_data, p_struct_data, struct_length);

		if (vbuf_length) {
			memcpy(vbuf, p_vbuf, vbuf_length);
			buf = vbuf;
		}

		m_fct_s_b[fn_index](struct_data, buf, vbuf_length);
	}
}

static void deserialize_b_b_p(uint8_t fn_index, struct net_buf *buf)
{
	const uint8_t *p_vbuf1;
	uint16_t vbuf1_length;
	const uint8_t *p_vbuf2;
	uint16_t vbuf2_length;
	uintptr_t priv;

	deserialize_buf(buf, &p_vbuf1, &vbuf1_length);
	deserialize_buf(buf, &p_vbuf2, &vbuf2_length);
	deserialize_ptr(buf, &priv);

	{
		/* Always align structures on word boundary */
		uintptr_t vbuf1[(vbuf1_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		uintptr_t vbuf2[(vbuf2_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		void *buf1 = NULL;
		void *buf2 = NULL;

		if (vbuf1_length) {
			memcpy(vbuf1, p_vbuf1, vbuf1_length);
			buf1 = vbuf1;
		}

		if (vbuf2_length) {
			memcpy(vbuf2, p_vbuf2, vbuf2_length);
			buf2 = vbuf2;
		}

		m_fct_b_b_p[fn_index](buf1, vbuf1_length, buf2, vbuf2_length,
				      (void *)priv);
	}
}

static void deserialize_s_p(uint8_t fn_index, struct net_buf *buf)
{
	const uint8_t *p_struct_data;
	uint8_t struct_length;
	uintptr_t priv;

	deserialize_struct(buf, &p_struct_data, &struct_length);
	deserialize_ptr(buf, &priv);

	if (struct_length != m_size_s_p[fn_index]) {
		panic(-1);
	} else {
		/* Always align structures on word boundary */
		uintptr_t struct_data[(struct_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];

		memcpy(struct_data, p_struct_data, struct_length);

		m_fct_s_p[fn_index](struct_data, (void *)priv);
	}
}

static void deserialize_s_b_p(uint8_t fn_index, struct net_buf *buf)
{
	const uint8_t *p_struct_data;
	uint8_t struct_length;
	const uint8_t *p_vbuf;
	uint16_t vbuf_length;
	uintptr_t priv;

	deserialize_struct(buf, &p_struct_data, &struct_length);
	deserialize_buf(buf, &p_vbuf, &vbuf_length);
	deserialize_ptr(buf, &priv);

	if (struct_length != m_size_s_b_p[fn_index]) {
		panic(-1);
	} else {
		/* Always align structures on word boundary */
		uintptr_t struct_data[(struct_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		uintptr_t vbuf[(vbuf_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		void *buf = NULL;

		memcpy(struct_data, p_struct_data, struct_length);

		if (vbuf_length) {
			memcpy(vbuf, p_vbuf, vbuf_length);
			buf = vbuf;
		}

		m_fct_s_b_p[fn_index](struct_data, buf, vbuf_length,
				      (void *)priv);
	}
}

static void deserialize_s_b_b_p(uint8_t fn_index, struct net_buf *buf)
{
	const uint8_t *p_struct_data;
	uint8_t struct_length;
	const uint8_t *p_vbuf1;
	uint16_t vbuf1_length;
	const uint8_t *p_vbuf2;
	uint16_t vbuf2_length;
	uintptr_t priv;

	deserialize_struct(buf, &p_struct_data, &struct_length);
	deserialize_buf(buf, &p_vbuf1, &vbuf1_length);
	deserialize_buf(buf, &p_vbuf2, &vbuf2_length);
	deserialize_ptr(buf, &priv);

	if (struct_length != m_size_s_b_b_p[fn_index]) {
		panic(-1);
	} else {
		/* Always align structures on word boundary */
		uintptr_t struct_data[(struct_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		uintptr_t vbuf1[(vbuf1_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		uintptr_t vbuf2[(vbuf2_length +
				(sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))];
		void *buf1 = NULL;
		void *buf2 = NULL;

		memcpy(struct_data, p_struct_data, struct_length);

		if (vbuf1_length) {
			memcpy(vbuf1, p_vbuf1, vbuf1_length);
			buf1 = vbuf1;
		}

		if (vbuf2_length) {
			memcpy(vbuf2, p_vbuf2, vbuf2_length);
			buf2 = vbuf2;
		}

		m_fct_s_b_b_p[fn_index](struct_data, buf1, vbuf1_length, buf2,
					vbuf2_length, (void *)priv);
	}
}

static void deserialize_control(uint8_t fn_index, struct net_buf *buf)
{
	const uint8_t *p_struct_data;
	uint8_t struct_length;
	struct {
		uint32_t version;
		uint32_t ser_hash;
		uint32_t des_hash;
	} struct_data;

	switch (fn_index) {
	case 0:
		deserialize_struct(buf, &p_struct_data, &struct_length);

		if (struct_length != sizeof(struct_data))
			panic(-1);
		memcpy(&struct_data, p_struct_data, struct_length);
		if (struct_data.ser_hash != rpc_deserialize_hash() ||
		    struct_data.des_hash != rpc_serialize_hash()) {
			rpc_init_cb(struct_data.version, false);
		} else {
			rpc_init_cb(struct_data.version, true);
		}
		break;
	default:
		panic(-1);
		break;
	}
}

void rpc_deserialize(struct net_buf *buf)
{

	uint8_t fn_index;
	uint8_t sig_type;

	sig_type = buf->data[0];
	fn_index = buf->data[1];

	net_buf_pull(buf, 2);

	switch (sig_type) {
	case SIG_TYPE_NONE:
		if (fn_index < ARRAY_SIZE(m_fct_none)) {
			DBG_FUNC(debug_func_none[fn_index]);
			deserialize_none(fn_index, buf);
		}
		break;
	case SIG_TYPE_S:
		if (fn_index < ARRAY_SIZE(m_fct_s)) {
			DBG_FUNC(debug_func_s[fn_index]);
			deserialize_s(fn_index, buf);
		}
		break;
	case SIG_TYPE_P:
		if (fn_index < ARRAY_SIZE(m_fct_p)) {
			DBG_FUNC(debug_func_p[fn_index]);
			deserialize_p(fn_index, buf);
		}
		break;
	case SIG_TYPE_S_B:
		if (fn_index < ARRAY_SIZE(m_fct_s_b)) {
			DBG_FUNC(debug_func_s_b[fn_index]);
			deserialize_s_b(fn_index, buf);
		}
		break;
	case SIG_TYPE_B_B_P:
		if (fn_index < ARRAY_SIZE(m_fct_b_b_p)) {
			DBG_FUNC(debug_func_b_b_p[fn_index]);
			deserialize_b_b_p(fn_index, buf);
		}
		break;
	case SIG_TYPE_S_P:
		if (fn_index < ARRAY_SIZE(m_fct_s_p)) {
			DBG_FUNC(debug_func_s_p[fn_index]);
			deserialize_s_p(fn_index, buf);
		}
		break;
	case SIG_TYPE_S_B_P:
		if (fn_index < ARRAY_SIZE(m_fct_s_b_p)) {
			DBG_FUNC(debug_func_s_b_p[fn_index]);
			deserialize_s_b_p(fn_index, buf);
		}
		break;
	case SIG_TYPE_S_B_B_P:
		if (fn_index < ARRAY_SIZE(m_fct_s_b_b_p)) {
			DBG_FUNC(debug_func_s_b_b_p[fn_index]);
			deserialize_s_b_b_p(fn_index, buf);
		}
		break;
	case SIG_TYPE_CONTROL:
		deserialize_control(fn_index, buf);
		break;
	default:
		panic(-1);
		break;
	}
}

__weak
void rpc_init_cb(uint32_t version, bool compatible)
{
}