aboutsummaryrefslogtreecommitdiffstats
path: root/thirdparty/prime/mac/mac_1_3/include/prime.h
blob: 3934fb58a40a1b7ab73cb82dce6935094ee8dd43 (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
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
/**
 * \file
 *
 * \brief PRIME Header
 *
 * Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.
 *
 * \asf_license_start
 *
 * \page License
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. The name of Atmel may not be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * 4. This software may only be redistributed and used in connection with an
 *    Atmel microcontroller product.
 *
 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * \asf_license_stop
 *
 */

#ifndef PRIME_H_INCLUDE
#define PRIME_H_INCLUDE

#include "compiler.h"

/* @cond 0 */
/**INDENT-OFF**/
#ifdef __cplusplus
extern "C" {
#endif
/**INDENT-ON**/
/* @endcond */

/**
 * \defgroup prime_group PRIME
 *
 * This module provides configuration and utils for PRIME.
 */

/**
 * \ingroup prime_group
 * \defgroup mac_prime_group PRIME MAC Layer
 *
 * This module provides configuration and utils for the
 * MAC layer in PRIME.
 *
 * @{
 */

enum MacLnidValues {
	PRIME_BROADCAST_LNID = 0x3FFF,
	PRIME_MULTICAST_LNID = 0x3FFE,
};

/* \name Length in bytes of EUI48 identifier of a Node */
/* @{ */
#define PRIME_MAC_LENGTH                         6
/* @} */

/* \name Length in bytes of max pdu */
/* @{ */
#define MAX_PDU_SIZE                             364
/* @} */

/* \name Time interval [msec] to check unexpected PLC chip resets */
/* @{ */
#define PRIME_CHECK_PLC_CFG_TIMER                5000
/* @} */

/* \name PRIME main control interface */
/* @{ */
void prime_init(void);
void prime_start(void);
void prime_process(void);
void prime_upd1ms(void);

/* @} */

/* \name PLME Result values */
/* @{ */
#define PRIME_PLME_RESULT_DONE                   0
#define PRIME_PLME_RESULT_SUCCESS                0
#define PRIME_PLME_RESULT_FAILED                 1
#define PRIME_PLME_RESULT_REJECTED               2
#define PRIME_PLME_RESULT_BADATTR                3
#define PRIME_PLME_RESULT_OUTOFRANGE             4
#define PRIME_PLME_RESULT_READONLY               5
/* @} */

/* \name PLME Commands for callback messages */
/* @{ */
#define PRIME_PLME_RESET_CONFIRM                 1
#define PRIME_PLME_SLEEP_CONFIRM                 2
#define PRIME_PLME_RESUME_CONFIRM                3
#define PRIME_PLME_TESTMODE_CONFIRM              4
#define PRIME_PLME_GET_CONFIRM                   5
#define PRIME_PLME_SET_CONFIRM                   6
/* @} */

/* \name PLME Commands for request messages */
/* @{ */
#define PRIME_PLME_RESET_REQUEST                 20
#define PRIME_PLME_SLEEP_REQUEST                 21
#define PRIME_PLME_RESUME_REQUEST                22
#define PRIME_PLME_TESTMODE_REQUEST              23
#define PRIME_PLME_GET_REQUEST                   24
#define PRIME_PLME_SET_REQUEST                   25
/* @} */

/* Types for PLME information access */

/* Extract PLME command */
typedef struct {
	uint8_t cmd;
} PlmeCommand;

/* Extract PLME result of operation */
typedef struct {
	uint8_t cmd;
	uint8_t result;
} PlmeResult;

/* Extract PLME numeric value */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint32_t pibValue;
} PlmeGetValue;

/* Extract PLME array value */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t buf[1];
} PlmeGetArray;

/* Extract PLME SET result */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
} PlmeSetResult;

/* \name Buffer size needed to receive PLME data */
/* @{ */
#define PRIME_PLME_DATA_SIZE                     364
/* @} */

/* \name PLME Functions interface */
/* @{ */
int prime_PLME_RESET_request(void);
int prime_PLME_SLEEP_request(void);
int prime_PLME_RESUME_request(void);
int prime_PLME_TESTMODE_request(uint8_t enable, uint8_t mode, uint8_t modulation, uint8_t pwr_level);
int prime_PLME_GET_request(uint16_t pibAttribute);
int prime_PLME_SET_request(uint16_t pibAttribute, uint32_t pibAttributeValue);
int prime_PLME_SET_BUF_request(uint16_t pibAttribute, uint8_t *pibBuf, uint16_t pibLen);
int prime_PLME_callback(uint8_t *buf);

/* @} */

/* \name MLME Result values */
/* @{ */
#define PRIME_MLME_RESULT_DONE                   0
#define PRIME_MLME_RESULT_SUCCESS                0
#define PRIME_MLME_RESULT_FAILED                 1
#define PRIME_MLME_RESULT_REJECTED               1
#define PRIME_MLME_RESULT_TIMEOUT                2
#define PRIME_MLME_RESULT_NOSNA                  8
#define PRIME_MLME_RESULT_NOSWITCH               9
#define PRIME_MLME_RESULT_REDUNDANT              10
#define PRIME_MLME_RESULT_BADATTR                11
#define PRIME_MLME_RESULT_OUTOFRANGE             12
#define PRIME_MLME_RESULT_READONLY               13
/* @} */

/* \name MLME Commands for callback messages */
/* @{ */
#define PRIME_MLME_REGISTER_CONFIRM              1
#define PRIME_MLME_REGISTER_INDICATION           2
#define PRIME_MLME_UNREGISTER_CONFIRM            3
#define PRIME_MLME_UNREGISTER_INDICATION         4
#define PRIME_MLME_PROMOTE_CONFIRM               5
#define PRIME_MLME_PROMOTE_INDICATION            6
#define PRIME_MLME_DEMOTE_CONFIRM                7
#define PRIME_MLME_DEMOTE_INDICATION             8
#define PRIME_MLME_RESET_CONFIRM                 9
#define PRIME_MLME_GET_CONFIRM                   10
#define PRIME_MLME_LIST_GET_CONFIRM              11
#define PRIME_MLME_SET_CONFIRM                   12
/* @} */

/* \name MLME Commands for request messages */
/* @{ */
#define PRIME_MLME_REGISTER_REQUEST              20
#define PRIME_MLME_UNREGISTER_REQUEST_SERVICE    21
#define PRIME_MLME_PROMOTE_REQUEST_SERVICE       22
#define PRIME_MLME_DEMOTE_REQUEST_SERVICE        23
#define PRIME_MLME_RESET_REQUEST                 24
#define PRIME_MLME_GET_REQUEST                   25
#define PRIME_MLME_LIST_GET_REQUEST              26
#define PRIME_MLME_SET_REQUEST                   27
#define PRIME_MLME_UNREGISTER_REQUEST_BASE       29
#define PRIME_MLME_PROMOTE_REQUEST_BASE          30
#define PRIME_MLME_DEMOTE_REQUEST_BASE           31
/* @} */

/* \name MLME definitions */
/* @{ */
/* Buffer size needed to receive MLME data */
#define MLME_DATA_SIZE                           364

/* Number of registered devices per message */
#define MLME_LIST_REGDEVNUM                      15

/* Number of active connections per message */
#define MLME_LIST_ACTCONNUM                      22

/* Number of multicast entries per message */
#define MLME_LIST_MCASTNUM                       83

/* Number of Switch Nodes entries per message */
#define MLME_LIST_SWNODENUM                      64

/* Number of direct connections per message */
#define MLME_LIST_DIRCONNUM                      8

/* Number of direct connections per message */
#define MLME_LIST_DIRSWNODENUM                   15

/* Number of Available Switch Nodes entries per message */
#define MLME_LIST_AVAILSWNODENUM                 22

/* Number of Switch Nodes entries per message */
#define MLME_LIST_PHYCOMMNUM                     17

/* Number of active connections per message */
#define MLME_LIST_ACTCONNUM_EX                   20

/* Number of 432 Nodes per message */
#define MLME_LIST_432_NODES                      7

/* Maximum number of extended SNR elements per message */
#define MLME_LIST_EXSNR_DEVNUM                   80

/* Number of FU Nodes per message */
#define MLME_LIST_FU_NODES                       20
/* @} */

/* PLC states */
enum MacPlcStateValues {
	MAC_PLC_STATE_DISCONNECTED           = 0,
	MAC_PLC_STATE_DETECTION              = 1,
	MAC_PLC_STATE_REGISTERING            = 2,
	MAC_PLC_STATE_OPERATIVE              = 3,
	MAC_PLC_STATE_BASE                   = 4,
};

/* Types for MLME information access */

/* Extract MLME command */
typedef struct {
	uint8_t cmd;
} MlmeCommand;

/* Extract MLME result of operation */
typedef struct {
	uint8_t cmd;
	uint8_t result;
} MlmeResult;

/* Extract MLME numeric value */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint32_t pibValue;
} MlmeGetValue;

/* Extract MLME array value */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t buf[1];
} MlmeGetArray;

/* Extract MLME SET result */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
} MlmeSetResult;

/* Extract MLME results */
typedef struct {
	uint8_t headerType;
	uint8_t ctrlPktFlag;
	uint16_t lcid;
	uint8_t type;
} MlmeParam;

/* Value for MLME Register Confirm command */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint8_t sna[PRIME_MAC_LENGTH];
	uint8_t mac[PRIME_MAC_LENGTH];
} MlmeRegisterConfirm;

/* Value for MLME Register Indication command */
typedef struct {
	uint8_t cmd;
	uint8_t sna[PRIME_MAC_LENGTH];
	uint8_t mac[PRIME_MAC_LENGTH];
} MlmeRegisterIndication;

/* Header for MLME ListGet commands */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
} MlmeListGetHeader;

/* Information of Registered Device */
typedef struct {
	uint8_t mac[PRIME_MAC_LENGTH];
	uint8_t state;
	uint8_t level;
	uint8_t tCap;
	uint8_t swCap;
	uint16_t lnid;
	uint16_t lsid;
	uint16_t sid;
} MlmeRegDevice;

/* ListGet for Registered	Devices */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmeRegDevice dev[MLME_LIST_REGDEVNUM];
} MlmeListGetRegDevices;

/* Information of Active Connections */
typedef struct {
	uint8_t mac[PRIME_MAC_LENGTH];
	uint16_t sid;
	uint16_t lnid;
	uint8_t lcid;
} MlmeActiveConn;

/* ListGet for Active Connections */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmeActiveConn conn[MLME_LIST_ACTCONNUM];
} MlmeListGetActiveConn;

/* Information of Active Connections (Extended List) */
typedef struct {
	uint8_t mac[PRIME_MAC_LENGTH];
	uint16_t sid;
	uint16_t lnid;
	uint16_t lcid;
	uint8_t type;
} MlmeActiveConnEx;

/* ListGet for Active Connections  (Extended List) */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmeActiveConnEx conn[MLME_LIST_ACTCONNUM_EX];
} MlmeListGetActiveConnEx;

/* Information of Multicast Entries */
typedef struct {
	uint16_t member;
	uint8_t lcid;
} MlmeMcastEntrie;

/* ListGet for Multicast Entries */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmeMcastEntrie ent[MLME_LIST_MCASTNUM];
} MlmeListGetMcastEntries;

/* Information of Switch Table */
typedef struct {
	uint16_t sid;
} MlmeSwitchNode;

/* ListGet for Switch Table */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmeSwitchNode nod[MLME_LIST_SWNODENUM];
} MlmeListGetSwitchTable;

/* Information of Direct Connections */
typedef struct {
	uint8_t srcmac[PRIME_MAC_LENGTH];
	uint16_t srcsid;
	uint16_t srclnid;
	uint8_t srclcid;
	uint8_t dstmac[PRIME_MAC_LENGTH];
	uint16_t dstsid;
	uint16_t dstlnid;
	uint8_t dstlcid;
	uint8_t dmac[PRIME_MAC_LENGTH];
	uint16_t dsid;
} MlmeDirectConn;

/* ListGet for Direct Connections */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmeDirectConn conn[MLME_LIST_DIRCONNUM];
} MlmeListGetDirectConn;

/* Information of Direct Switch Table */
typedef struct {
	uint8_t dsmac[PRIME_MAC_LENGTH];
	uint16_t srcsid;
	uint16_t srclnid;
	uint8_t srclcid;
	uint16_t dstsid;
	uint16_t dstlnid;
	uint8_t dstlcid;
} MlmeDirectSwitchNode;

/* ListGet for Direct Switch Table */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmeDirectSwitchNode nod[MLME_LIST_DIRSWNODENUM];
} MlmeListGetDirectSwitchTable;

/* Information of Available Switch Table */
typedef struct {
	uint8_t sna[PRIME_MAC_LENGTH];
	uint16_t sid;
	uint8_t level;
	uint8_t rxLevel;
	uint8_t rxSNR;
} MlmeAvailableSwitchNode;

/* ListGet for Available Switch Table */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmeAvailableSwitchNode nod[MLME_LIST_AVAILSWNODENUM];
} MlmeListGetAvailableSwitchTable;

/* Information of Phy Communication Parameters Table */
typedef struct {
	uint8_t eui48[PRIME_MAC_LENGTH];
	uint8_t txPower;
	uint8_t txCoding;
	uint8_t rxCoding;
	uint8_t rxLevel;
	uint8_t snr;
	uint8_t txPowerMod;
	uint8_t txCodingMod;
	uint8_t rxCodingMod;
} MlmePhyCommDevice;

/* ListGet for Phy Communication Parameters Table */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	MlmePhyCommDevice dev[MLME_LIST_PHYCOMMNUM];
} MlmeListGetPhyCommTable;

/* List of extended SNR (PIB 0x8150) */
typedef struct {
	uint8_t sid;
	uint16_t lnid;
	uint8_t exSnr;
} ExSNRElementType;

/* ListGet for Phy Communication Parameters Table */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	ExSNRElementType exSnrDev[MLME_LIST_EXSNR_DEVNUM];
} MlmeListGetExSnrTable;

/* Equal to LEN_432_SERIAL_NUMBER defined in 432 layer */
#define SERIAL_NUMBER_432_MAC                    16

/* List of 432 Information Nodes if exists 432 (PIB 0x8250) */
typedef struct {
	uint16_t address;
	int8_t serialNumber[SERIAL_NUMBER_432_MAC];
	uint8_t lenSerial;
	uint8_t mac[PRIME_MAC_LENGTH];
	uint8_t arq;
} Node432Type;

/* ListGet for Phy Communication Parameters Table */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	Node432Type dev[MLME_LIST_432_NODES];
} MlmeListGetNode432Table;

/* List of Nodes in the FU target list (PIB 0x8350) */
typedef struct {
	uint8_t fuState;
	uint32_t pagesReceived;
	uint8_t mac[PRIME_MAC_LENGTH];
} FuNodeTargetType;

/* ListGet for FU target list */
typedef struct {
	uint8_t cmd;
	uint8_t result;
	uint16_t pibAttrib;
	uint8_t isLast;
	uint8_t numItems;
	FuNodeTargetType dev[MLME_LIST_FU_NODES];
} MlmeListFUTable;

/* \name MLME Functions interface */
/* @{ */
int prime_MLME_REGISTER_request(uint8_t *sna, uint8_t *mac);
int prime_MLME_UNREGISTER_request_base(uint8_t *mac);
int prime_MLME_UNREGISTER_request_service(void);
int prime_MLME_PROMOTE_request_base(uint8_t *mac);
int prime_MLME_PROMOTE_request_service(void);
int prime_MLME_DEMOTE_request_base(uint8_t *mac);
int prime_MLME_DEMOTE_request_service(void);
int prime_MLME_RESET_request(void);
int prime_MLME_GET_request(uint16_t pibAttribute);
int prime_MLME_LIST_GET_request(uint16_t pibListAttribute);
int prime_MLME_SET_request(uint16_t pibAttribute, uint32_t pibAttributeValue);
int prime_MLME_SET_BUF_request(uint16_t pibAttribute, uint8_t *pibBuf, uint8_t pibLen);
int prime_MLME_callback(uint8_t *buf);

/* @} */

/* \name MAC_SAP Result values */
/* @{ */
#define PRIME_MACSAP_RESULT_SUCCESS              0
#define PRIME_MACSAP_RESULT_ACCEPT               0
#define PRIME_MACSAP_RESULT_ERROR                1
#define PRIME_MACSAP_RESULT_REJECT               1
#define PRIME_MACSAP_RESULT_TIMEOUT              2
#define PRIME_MACSAP_RESULT_NO_BANDWITH          3
#define PRIME_MACSAP_RESULT_NO_SUCH_DEVICE       4
#define PRIME_MACSAP_RESULT_REDIRECT_FAILED      5
#define PRIME_MACSAP_RESULT_NOT_REGISTERED       6
#define PRIME_MACSAP_RESULT_NO_MORE_LCIDS        7
/* @} */

/* \name MAC_SAP Error Type values */
/* @{ */
#define PRIME_MACSAP_ERROR_NO_ERROR              0
#define PRIME_MACSAP_ERROR_REJECT                1
#define PRIME_MACSAP_ERROR_TIMEOUT               2
#define PRIME_MACSAP_ERROR_NO_SUCH_DEVICE        4
#define PRIME_MACSAP_ERROR_NOT_REGISTERED        6
#define PRIME_MACSAP_ERROR_INVALID_HANDLER       8
#define PRIME_MACSAP_ERROR_NO_RESOURCES          9
#define PRIME_MACSAP_ERROR_PROCESS_RUNNING       10
#define PRIME_MACSAP_ERROR_TOO_LONG              11
#define PRIME_MACSAP_ERROR_CON_NOT_OPEN          12
#define PRIME_MACSAP_ERROR_NO_ACKED              13
#define PRIME_MACSAP_ERROR_TX_BUSY               14
#define PRIME_MACSAP_ERROR_INVALID_BCAST         15
#define PRIME_MACSAP_ERROR_INVALID_DIRCON        16
#define PRIME_MACSAP_ERROR_INVALID_EUI48         17
/* @} */

/* \name MAC_SAP Commands for callback messages */
/* @{ */
#define PRIME_MACSAP_ESTABLISH_CONFIRM           1
#define PRIME_MACSAP_ESTABLISH_INDICATION        2
#define PRIME_MACSAP_RELEASE_CONFIRM             3
#define PRIME_MACSAP_RELEASE_INDICATION          4
#define PRIME_MACSAP_DATA_CONFIRM                5
#define PRIME_MACSAP_DATA_INDICATION             6
#define PRIME_MACSAP_JOIN_CONFIRM                8
#define PRIME_MACSAP_LEAVE_CONFIRM               9
#define PRIME_MACSAP_JOIN_INDICATION_BASE        10
#define PRIME_MACSAP_LEAVE_INDICATION_BASE       11
#define PRIME_MACSAP_JOIN_INDICATION_SERVICE     12
#define PRIME_MACSAP_LEAVE_INDICATION_SERVICE    13
/* @} */

/* \name MAC_SAP Commands for callback messages (Request & Response) */
/* @{ */
#define PRIME_MACSAP_ESTABLISH_REQUEST           20
#define PRIME_MACSAP_ESTABLISH_RESPONSE          21
#define PRIME_MACSAP_REDIRECT_RESPONSE           22
#define PRIME_MACSAP_RELEASE_REQUEST             23
#define PRIME_MACSAP_RELEASE_RESPONSE            24
#define PRIME_MACSAP_SEND_REQUEST                25
#define PRIME_MACSAP_DATA_REQUEST                26
#define PRIME_MACSAP_JOIN_REQUEST_BASE           27
#define PRIME_MACSAP_LEAVE_REQUEST_BASE          28
#define PRIME_MACSAP_JOIN_RESPONSE_BASE          29
#define PRIME_MACSAP_JOIN_REQUEST_SERVICE        30
#define PRIME_MACSAP_LEAVE_REQUEST_SERVICE       31
#define PRIME_MACSAP_JOIN_RESPONSE_SERVICE       32
/* @} */

/* \name MAX Buffer size to transmit or receive MAC data */
/* @{ */
#define PRIME_MACSAP_DATA_SIZE                   1024
/* @} */

/* \name Message Priorities */
/* @{ */
#define MAX_PRIO                                 0
#define PRIO_1                                   1
#define PRIO_2                                   2
#define PRIO_3                                   3
/* @} */

/* \name Default Priority for Data Messages */
/* @{ */
#define DATA_PRIO                                2
/* @} */

/* \name Type values defined for different CS defined in PRIME Spec v1.3 */
/* @{ */
#define TYPE_CL_IPv4_AR                          1
#define TYPE_CL_IPv4_UNICAST                     2
#define TYPE_CL_432                              3
#define TYPE_CL_MGMT                             4
#define TYPE_CL_APPEMU                           250
/* @} */

/* \name LCI values for broadcast connections defined in PRIME Spec v1.3 */
/* @{ */
#define LCI_CL_IPv4_BROADCAST                    1
#define LCI_CL_432_BROADCAST                     2
/* @} */

/* \name Generic Handler and Type values to use on MAC SAP Callback */
/* @{ */
#define GENERIC_CALLBACK_TYPE                    0
#define GENERIC_CALLBACK_HANDLER                 0xFFFF
/* @} */

/* Type for callback information */
typedef struct {
	uint8_t command;
	uint8_t type;
	uint16_t handler;
	uint16_t answer;
	uint8_t errorType;
	uint16_t bufLength;
	uint16_t cfpBytes;
	uint16_t lcid;
	uint8_t arq;
	uint8_t priority;
	uint8_t broadcast;
	uint8_t macAddr[PRIME_MAC_LENGTH];
	uint8_t buf[PRIME_MACSAP_DATA_SIZE];
} MacSapCallBack;

/* \name MAC Functions Interface */
/* @{ */
int prime_MAC_ESTABLISH_request(uint8_t *macAddr, uint8_t type, uint8_t *buf, uint16_t dataLength, uint8_t arq, uint16_t cfpBytes);
int prime_MAC_ESTABLISH_response(uint16_t conHandle, uint8_t answer, uint8_t *buf, uint16_t dataLength);
int prime_MAC_RELEASE_request(uint16_t conHandle);
int prime_MAC_RELEASE_response(uint16_t conHandle, uint8_t answer);
int prime_MAC_JOIN_request_base(uint8_t broadcast, uint16_t handler, uint8_t *macAddr, uint8_t type, uint8_t *buf, uint16_t dataLength);
int prime_MAC_JOIN_request_service(uint8_t broadcast, uint8_t type, uint8_t *buf, uint16_t dataLength);
int prime_MAC_JOIN_response_base(uint16_t handler, uint8_t *macAddr, uint8_t answer);
int prime_MAC_JOIN_response_service(uint16_t handler, uint8_t answer);
int prime_MAC_LEAVE_request_base(uint16_t conHandle, uint8_t *macAddr);
int prime_MAC_LEAVE_request_service(uint16_t conHandle);
int prime_MAC_REDIRECT_response(uint16_t conHandle, uint8_t *macAddr, uint8_t *buf, uint16_t dataLength);
int prime_MAC_DATA_request(uint16_t conHandle, uint8_t *buf, uint16_t dataLength, uint8_t priority);
int prime_MAC_callback(MacSapCallBack *info, uint16_t handler, uint8_t type);

/* @} */

/* \name Number of different types */
/* @{ */
#define PRIME_TYPE_NUM                           255
/* @} */

/* \name Prime reserved Interface */
/* @{ */
int8_t mac_sap_reserve_type(uint8_t type);
int8_t mac_sap_free_type(uint8_t type);
int8_t mac_sap_get_reserve_type(uint8_t type);

int8_t mac_sap_reserve_handler(uint16_t handler, uint16_t iNID, uint8_t type);
int8_t mac_sap_free_handler(uint16_t connHandler);
int8_t mac_sap_get_reserve_handler(uint16_t handler);

int prime_MAC_callback_reserved(MacSapCallBack *info, uint16_t handler, uint8_t type);

/* @} */

/* \name Types for 432 information access */
/* @{ */
/* Extract 432 connections table */
typedef struct _Node432 {
	uint16_t handler;
	int8_t serialNumber[SERIAL_NUMBER_432_MAC];
	uint8_t lenSerial;
	uint8_t mac[PRIME_MAC_LENGTH];
	uint8_t arq;
	uint16_t next;
	uint16_t prev;
} Node432;
/* @} */

/* \name Macros */
/* @{ */
#define GET_INDEX_NODE_432(X)                    (X - 2)
#define GET_ADDRESS_NODE_432(X)                  (X + 2)
/* @} */

/* \name Embedded Sniffer Interface */
/* @{ */
#define MASK_SNIFFER_EMBEDDED                    0x80
/* @} */

/* \name Sniffer types */
/* @{ */
#define SNIFFER_ATPL210                          0x00
#define SNIFFER_ATPL240                          0x01
/* @} */

typedef enum {
	SNIFFER_RX = 0,
	SNIFFER_TX = 1,
	SNIFFER_TX_SERIAL = 2,
	SNIFFER_RX_SERIAL = 3
} SnifferType;

typedef struct {
	SnifferType type;
	uint8_t scheme;
	uint8_t level;
	uint8_t exSnr;
	uint32_t time;
} SnifferParam;

/* @} */

/* @cond 0 */
/**INDENT-OFF**/
#ifdef __cplusplus
}
#endif
/**INDENT-ON**/
/* @endcond */
#endif /* PRIME_H_INCLUDE */