-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusbctrl_descriptors.c
More file actions
1556 lines (1350 loc) · 64.6 KB
/
usbctrl_descriptors.c
File metadata and controls
1556 lines (1350 loc) · 64.6 KB
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
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "libc/string.h"
#include "libc/nostd.h"
#include "api/libusbctrl.h"
#include "usbctrl_descriptors.h"
#include "usbctrl.h"
#define MAX_DESC_STRING_SIZE 32 /* max unicode string size supported (to define properly) */
/*
* USB configuration descriptor. Global to the device, specify the
* device configuration (number of interfaces, power, ...)
*/
typedef struct __packed usb_configuration_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
struct {
uint8_t reserved:5;
uint8_t remote_wakeup:1;
uint8_t self_powered:1;
uint8_t reserved7:1;
} bmAttributes;
uint8_t bMaxPower;
} usb_configuration_descriptor_t;
/**
* Interface descriptor set,
*/
/**
* Endpoint descriptor set for run-time mode (only?).
*/
/* old
typedef struct __packed usb_ctrl_full_configuration_descriptor {
usb_configuration_descriptor_t config;
union {
usb_ctr_full_endpoint_descriptor_t ep;
usb_functional_descriptor_t functional_desc;
};
} usb_ctrl_configuration_descriptor_t;
*/
/**
* \brief String descriptor.
*/
/*********************************************************************************
* configuration descriptor related fonctions
*
* handling configuration descriptor is the harder part of this file, which requires
* successive steps that are, in this implementation, separated in methods.
*
*/
/*
* Check that the required size to build the overall configuration descriptor is
* short enough for the given buffer.
*/
/*@
@ requires \separated(&SIZE_DESC_FIXED, &FLAG, buf+(..),desc_size+(..),ctx+(..),total_size);
@ requires \separated(&ctx_list + (0..(GHOST_num_ctx-1)),&GHOST_num_ctx);
@ ensures \result == MBED_ERROR_NONE || \result == MBED_ERROR_UNKNOWN || \result == MBED_ERROR_INVPARAM || \result == MBED_ERROR_UNSUPORTED_CMD ;
@ ensures 0 <= *total_size <= MAX_DESCRIPTOR_LEN ;
@ assigns *total_size, *desc_size, SIZE_DESC_FIXED, FLAG ;
*/
/*
TODO : be more precise with invparam behavior (but dead code with total_size == null and impossible to reach usbctrl_get_handler(ctx, &handler) != MBED_ERROR_NONE )
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_handle_configuration_size(__out uint8_t *buf,
__out uint32_t *desc_size,
__in usbctrl_context_t * ctx,
__out uint32_t *total_size)
{
mbed_error_t errcode = MBED_ERROR_NONE;
uint8_t class_desc_size = 0;
uint8_t iad_size = 0;
uint8_t curr_cfg = ctx->curr_cfg;
uint8_t iface_num = ctx->cfg[curr_cfg].interface_num;
uint32_t handler;
if (total_size == NULL) {
/*INFO: this should be dead code */
errcode = MBED_ERROR_INVPARAM;
goto err;
}
/*
* Calculate and generate the complete configuration descriptor
*/
/* then calculate the overall descriptor size */
uint32_t descriptor_size = sizeof(usbctrl_configuration_descriptor_t);
if (usbctrl_get_handler(ctx, &handler) != MBED_ERROR_NONE) {
log_printf("[LIBCTRL] didn't get back handler from ctx\n");
errcode = MBED_ERROR_INVPARAM;
goto err;
}
bool composite = false;
uint8_t curr_composite = 0;
/*@
@ loop invariant 0 <= i <= iface_num ;
@ loop invariant \valid_read(ctx->cfg[curr_cfg].interfaces + (0..(iface_num-1)));
@ loop assigns i, descriptor_size, FLAG, errcode, class_desc_size, composite, curr_composite, iad_size ;
@ loop variant (iface_num -i);
*/
for (uint8_t i = 0; i < iface_num; ++i) {
uint32_t local_iface_desc_size = 0;
/* first calculating class descriptor size */
if (ctx->cfg[curr_cfg].interfaces[i].composite_function == true) {
composite = true;
if (curr_composite != ctx->cfg[curr_cfg].interfaces[i].composite_function_id) {
/* new composite function */
curr_composite = ctx->cfg[curr_cfg].interfaces[i].composite_function_id;
iad_size = sizeof(usbctrl_iad_descriptor_t);
} else {
/* continuing composite */
iad_size = 0;
}
} else {
iad_size = 0;
composite = false;
}
if (ctx->cfg[curr_cfg].interfaces[i].class_desc_handler != NULL) {
uint8_t max_buf_size = 255 ; /* max for uint8_t, still smaller than current MAX_BUF_SIZE */
#ifndef __FRAMAC__
if (handler_sanity_check_with_panic((physaddr_t)ctx->cfg[curr_cfg].interfaces[i].class_desc_handler)) {
errcode = MBED_ERROR_INVSTATE;
goto err;
}
#endif
#if defined(__FRAMAC__)
FLAG = false ;
#endif/*__FRAMAC__*/
/*@ assert ctx->cfg[curr_cfg].interfaces[i].class_desc_handler ∈ {&class_get_descriptor}; */
/*@ calls class_get_descriptor; */
errcode = ctx->cfg[curr_cfg].interfaces[i].class_desc_handler(i, buf, &max_buf_size, handler);
if (errcode != MBED_ERROR_NONE) {
log_printf("[LIBCTRL] failure while getting class desc: %d\n", errcode);
errcode = MBED_ERROR_UNKNOWN;
goto err;
}
log_printf("[LIBCTRL] found one class level descriptor of size %d\n", max_buf_size);
if (max_buf_size > (255 - class_desc_size)) {
/* uint8_t overflow check */
log_printf("[LIBCTRL] class descriptor len too long!\n");
errcode = MBED_ERROR_UNSUPORTED_CMD;
goto err;
}
/*@ assert max_buf_size <= (255 - class_desc_size); */
class_desc_size += (uint8_t)(max_buf_size & 0xff); // CDE in order to calculate size of all class descriptor
} else {
class_desc_size += 0;
}
/* now we can add the potential class descriptor size to the current amount of bytes of the global
* configuration descriptor */
//local_iface_desc_size += class_desc_size;
/* for endpoint, we must not declare CONTROL eps in interface descriptor */
uint8_t num_ep = 0;
/*@
@ loop invariant 0 <= ep <= ctx->cfg[curr_cfg].interfaces[i].usb_ep_number ;
@ loop assigns num_ep, ep ;
@ loop variant (ctx->cfg[curr_cfg].interfaces[i].usb_ep_number - ep);
*/
for (uint8_t ep = 0; ep < ctx->cfg[curr_cfg].interfaces[i].usb_ep_number; ++ep) {
if (ctx->cfg[curr_cfg].interfaces[i].eps[ep].type == USB_EP_TYPE_CONTROL) {
/* Control EP is out of scope */
continue;
}
/* a full-duplex endpoint consume 2 descriptors */
if (ctx->cfg[curr_cfg].interfaces[i].eps[ep].dir == USB_EP_DIR_BOTH) {
++num_ep;
}
++num_ep;
}
/* here we should assert that current size (local_iface_desc_size) is smaller than:
* sizeof(usbctrl_interface_descriptor_t) + 16*(usbctrl_endpoint_descriptor_t)
* because num_ep is <= 8 (case EP_DIR=BOTH) */
local_iface_desc_size += sizeof(usbctrl_interface_descriptor_t) + num_ep * sizeof(usbctrl_endpoint_descriptor_t);
descriptor_size += local_iface_desc_size; // CDE : descriptor size without class size
descriptor_size += iad_size;
}
/* TODO: here we should assert that local_iface_desc_size * num_iface + usbctrl_configuration_descriptor_t is smaller than
* uint32_t size (4G) to avoid any u32 overflow*/
/* we add potential class descriptors found above ... From now on, the global descriptor size is
* complete, and can be sanitized properly in comparison with the passed buffer size */
/* now, we have calculated the total amount of bytes required:
* - configuration descriptor
* - for each iface:
* * iface descriptor
* * class descriptor (if exists)
* * for each endpoint other than control:
* x endpoint descriptor
*
* the overall descriptor size in bytes must be smaller or equal to the given buffer size (MAX_DESCRIPTOR_LEN).
*/
//@ split descriptor_size ;
if((descriptor_size + class_desc_size) >= MAX_DESCRIPTOR_LEN) {
log_printf("[USBCTRL] not enough space for config descriptor !!!\n");
errcode = MBED_ERROR_UNSUPORTED_CMD;
*desc_size = 0;
/*@ assert ((class_desc_size + descriptor_size) >= MAX_DESCRIPTOR_LEN); */
goto err;
}
/*@ assert class_desc_size + descriptor_size <= MAX_DESCRIPTOR_LEN; */
*total_size = descriptor_size + class_desc_size ;
#if defined(__FRAMAC__)
SIZE_DESC_FIXED = class_desc_size ;
#endif/*__FRAMAC__*/
err:
return errcode;
}
/******************************************************************************************
* Setting descriptors in input buffer
*
* Input buffer is a generic uint8_t[] buffer. Usual C code would cast and set a descriptor
* offset to the corresponding descriptor type, although FramaC in Typed+Ref mode doesn't allow
* a signe memory cell to be multi-typed, making such method unprovable.
*
* The way we handle it here is based on static inline functions that byte-copy each descriptor
* element into the buffer, as they can be considered as a sequence of bytes, respecting the output
* buffer type, whatever the input structured type is.
* This allows FramaC to automatically prove loops termination, detect any array overflows, etc.
* This copy is made using static inline functions that will be optimized at compile time, few impacting
* the overall performance. Moreover, this part of the code is not constraints in term of performances as
* it handle the standard requests descriptors.
*
*/
/*@
@ requires \separated(cfg + (0 .. sizeof(usbctrl_device_descriptor_t)-1), buf + (0 .. sizeof(usbctrl_device_descriptor_t)-1));
@ requires \valid_read(cfg) && \valid(buf + (0 .. sizeof(usbctrl_device_descriptor_t)-1)) ;
@ assigns buf[0 .. sizeof(usbctrl_device_descriptor_t)-1] ;
//@ ensures \forall integer i; 0 <= i < sizeof(usbctrl_device_descriptor_t) ==> \at(buf[i],Post) == \at(((uint8_t*)cfg)[i],Pre);
*/
#ifndef __FRAMAC__
static inline
#endif
void usbctrl_device_desc_to_buff(__in const usbctrl_device_descriptor_t *cfg, __out uint8_t *buf)
{
buf[0] = cfg->bLength;
buf[1] = cfg->bDescriptorType;
buf[2] = (uint8_t)(cfg->bcdUSB & 0xff);
buf[3] = (uint8_t)(cfg->bcdUSB >> 8) & 0xff;
buf[4] = cfg->bDeviceClass;
buf[5] = cfg->bDeviceSubClass;
buf[6] = cfg->bDeviceProtocol;
buf[7] = cfg->bMaxPacketSize;
buf[8] = (uint8_t)(cfg->idVendor & 0xff);
buf[9] = (uint8_t)(cfg->idVendor >> 8) & 0xff;
buf[10] = (uint8_t)(cfg->idProduct & 0xff);
buf[11] = (uint8_t)(cfg->idProduct >> 8) & 0xff;
buf[12] = (uint8_t)(cfg->bcdDevice & 0xff);
buf[13] = (uint8_t)(cfg->bcdDevice >> 8) & 0xff;
buf[14] = cfg->iManufacturer;
buf[15] = cfg->iProduct;
buf[16] = cfg->iSerialNumber;
buf[17] = cfg->bNumConfigurations;
return;
}
/*@
@ requires \separated(cfg, buf + (0 .. sizeof(usbctrl_configuration_descriptor_t)-1));
@ requires \valid_read(cfg) && \valid(buf + (0 .. sizeof(usbctrl_configuration_descriptor_t)-1)) ;
@ assigns buf[0 .. sizeof(usbctrl_configuration_descriptor_t)-1] ;
//@ ensures \forall integer i; 0 <= i < sizeof(usbctrl_configuration_descriptor_t) ==> \at(buf[i],Post) == \at(((uint8_t*)cfg)[i],Pre);
*/
#ifndef __FRAMAC__
static inline
#endif
void usbctrl_configuration_desc_to_buff(__in const usbctrl_configuration_descriptor_t *cfg, __out uint8_t *buf)
{
buf[0] = cfg->bLength;
buf[1] = cfg->bDescriptorType;
buf[2] = (uint8_t)(cfg->wTotalLength & 0xff);
buf[3] = (uint8_t)((cfg->wTotalLength >> 8) & 0xff);
buf[4] = cfg->bNumInterfaces;
buf[5] = cfg->bConfigurationValue;
buf[6] = cfg->iConfiguration;
uint8_t bmap = (cfg->bmAttributes.reserved) | (cfg->bmAttributes.remote_wakeup << 5) | (cfg->bmAttributes.self_powered << 6) | (cfg->bmAttributes.reserved7 << 7);
buf[7] = bmap;
buf[8] = cfg->bMaxPower;
return;
}
/*@
@ requires \separated(cfg + (0 .. sizeof(usbctrl_iad_descriptor_t)-1), buf + (0 .. sizeof(usbctrl_iad_descriptor_t)-1));
@ requires \valid_read(cfg) && \valid(buf + (0 .. sizeof(usbctrl_iad_descriptor_t)-1)) ;
@ assigns buf[0 .. sizeof(usbctrl_iad_descriptor_t)-1] ;
@ ensures \forall integer i; 0 <= i < sizeof(usbctrl_iad_descriptor_t) ==> \at(buf[i],Post) == \at(((uint8_t*)cfg)[i],Pre);
*/
#ifndef __FRAMAC__
static inline
#endif
void usbctrl_iad_desc_to_buff(__in const usbctrl_iad_descriptor_t *cfg, __out uint8_t *buf)
{
buf[0] = cfg->bLength;
buf[1] = cfg->bDescriptorType;
buf[2] = cfg->bFirstInterface;
buf[3] = cfg->bInterfaceCount;
buf[4] = cfg->bFunctionClass;
buf[5] = cfg->bFunctionSubClass;
buf[6] = cfg->bFunctionProtocol;
buf[7] = cfg->iFunction;
return;
}
/*@
@ requires \separated(cfg + (0 .. sizeof(usbctrl_endpoint_descriptor_t)-1), buf + (0 .. sizeof(usbctrl_endpoint_descriptor_t)-1));
@ requires \valid_read(cfg) && \valid(buf + (0 .. sizeof(usbctrl_endpoint_descriptor_t)-1)) ;
@ assigns buf[0 .. sizeof(usbctrl_endpoint_descriptor_t)-1] ;
//@ ensures \forall integer i; 0 <= i < sizeof(usbctrl_endpoint_descriptor_t) ==> \at(buf[i],Post) == \at(((uint8_t*)cfg)[i],Pre);
*/
#ifndef __FRAMAC__
static inline
#endif
void usbctrl_ep_desc_to_buff(__in const usbctrl_endpoint_descriptor_t *cfg, __out uint8_t *buf)
{
buf[0] = cfg->bLength;
buf[1] = cfg->bDescriptorType;
buf[2] = cfg->bEndpointAddress;
buf[3] = cfg->bmAttributes;
buf[4] = (uint8_t)(cfg->wMaxPacketSize & 0xff);
buf[5] = (uint8_t)(cfg->wMaxPacketSize >> 8) & 0xff;
buf[6] = cfg->bInterval;
return;
}
/*@
@ requires \separated(cfg, buf + (0 .. sizeof(usbctrl_interface_descriptor_t)-1));
@ requires \valid_read(cfg) && \valid(buf + (0 .. sizeof(usbctrl_interface_descriptor_t)-1)) ;
@ assigns buf[0 .. sizeof(usbctrl_interface_descriptor_t)-1] ;
@ ensures \forall integer i; 0 <= i < sizeof(usbctrl_interface_descriptor_t) ==> \at(buf[i],Post) == \at(((uint8_t*)cfg)[i],Pre);
*/
#ifndef __FRAMAC__
static inline
#endif
void usbctrl_interface_desc_to_buff(__in const usbctrl_interface_descriptor_t *cfg, __out uint8_t *buf)
{
buf[0] = cfg->bLength;
buf[1] = cfg->bDescriptorType;
buf[2] = cfg->bInterfaceNumber;
buf[3] = cfg->bAlternateSetting;
buf[4] = cfg->bNumEndpoints;
buf[5] = cfg->bInterfaceClass;
buf[6] = cfg->bInterfaceSubClass;
buf[7] = cfg->bInterfaceProtocol;
buf[8] = cfg->iInterface;
return;
}
/*@
@ requires \separated(cfg + (0 .. sizeof(usbctrl_string_descriptor_t)-1), buf + (0 .. sizeof(usbctrl_string_descriptor_t)-1));
@ requires \valid_read(cfg) && \valid(buf + (0 .. sizeof(usbctrl_string_descriptor_t)-1)) ;
@ assigns buf[0 .. sizeof(usbctrl_string_descriptor_t)-1] ;
//@ ensures \forall integer i; 0 <= i < sizeof(usbctrl_string_descriptor_t) ==> \at(buf[i],Post) == \at(((uint8_t*)cfg)[i],Pre);
*/
#ifndef __FRAMAC__
static inline
#endif
void usbctrl_string_desc_to_buff(__in const usbctrl_string_descriptor_t *cfg, __out uint8_t *buf)
{
buf[0] = cfg->bLength;
buf[1] = cfg->bDescriptorType;
#ifdef __FRAMAC__
/* XXX: PTH: the copy is not exalty (functionaly) the same as the memcpy (which is operational) and must be reviewed */
/*@
@ loop invariant 0 <= i <= MAX_DESC_STRING_SIZE ;
@ loop assigns i, buf[2 .. (2 + (2*(MAX_DESC_STRING_SIZE-1)))] ;
@ loop variant MAX_DESC_STRING_SIZE - i ;
*/
for(uint32_t i = 0; i < MAX_DESC_STRING_SIZE; i++){
buf[2 + i] = (uint8_t)(cfg->wString[i] & 0xff);
buf[2 + i + 1] = (uint8_t)(cfg->wString[i] >> 8) & 0xff;
}
#else
memcpy(&buf[2], &cfg->wString[0], 2*(MAX_DESC_STRING_SIZE));
#endif
return;
}
/*
* End of the local descriptor to/from buffer assignation functions.
*
*********************************************************************************************************/
/*@
@ requires \separated(&SIZE_DESC_FIXED, &FLAG, buf+(..),curr_offset);
@ assigns buf[0 .. MAX_DESCRIPTOR_LEN-1] ;
@ assigns *curr_offset ;
@ behavior INVPARAM:
@ assumes (curr_offset == \null || buf == \null) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ assigns \nothing ;
@ behavior NOSTORAGE:
@ assumes !(curr_offset == \null || buf == \null) ;
@ assumes (*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_configuration_descriptor_t))) ;
@ ensures \result == MBED_ERROR_NOSTORAGE ;
@ assigns \nothing ;
@ behavior OK:
@ assumes !(curr_offset == \null || buf == \null) ;
@ assumes !(*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_configuration_descriptor_t))) ;
@ ensures \result == MBED_ERROR_NONE ;
@ ensures *curr_offset == \old(*curr_offset) + (uint32_t)sizeof(usbctrl_configuration_descriptor_t) ;
@ complete behaviors ;
@ disjoint behaviors ;
*/
/*
CDE : not possible to validate assigns clause because of cast : (usbctrl_configuration_descriptor_t *)&(buf[*curr_offset]) (WP memory model)
RBE : fix attempt
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_handle_configuration_write_config_desc(uint8_t *buf,
uint32_t descriptor_size,
uint8_t iface_num,
uint32_t *curr_offset)
{
mbed_error_t errcode = MBED_ERROR_NONE;
/* DEFENSIVE POGRAMMING:
* these sanitation functions should not be needed when the execution flow
* is preserved. Thus, in case of execution corruption, this code is keeped */
if (curr_offset == NULL || buf == NULL) {
errcode = MBED_ERROR_INVPARAM;
goto err;
}
if (*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_configuration_descriptor_t))) {
errcode = MBED_ERROR_NOSTORAGE;
goto err;
}
//usbctrl_configuration_descriptor_t *cfg = (usbctrl_configuration_descriptor_t *)&(buf[*curr_offset]);
usbctrl_configuration_descriptor_t _cfg;
usbctrl_configuration_descriptor_t *cfg = &_cfg;
cfg->bLength = sizeof(usbctrl_configuration_descriptor_t);
if (descriptor_size > 65535) {
/* This should never happen */
errcode = MBED_ERROR_INVPARAM;
goto err;
}
cfg->wTotalLength = descriptor_size & 0xffff;
cfg->bDescriptorType = USB_DESC_CONFIGURATION;
cfg->bNumInterfaces = iface_num;
cfg->bConfigurationValue = 1;
cfg->iConfiguration = 0;
cfg->bmAttributes.reserved7 = 1;
cfg->bmAttributes.self_powered = 1;
cfg->bmAttributes.remote_wakeup = 0;
cfg->bmAttributes.reserved = 0;
cfg->bMaxPower = 0;
usbctrl_configuration_desc_to_buff(cfg, (uint8_t*)&(buf[*curr_offset]));
*curr_offset += sizeof(usbctrl_configuration_descriptor_t);
/*@ assert *curr_offset == \at(*curr_offset,Pre) + sizeof(usbctrl_configuration_descriptor_t) ; */
err:
return errcode;
}
/*@
@ requires \separated(&SIZE_DESC_FIXED, &FLAG, composite, buf+(0 .. MAX_DESCRIPTOR_LEN-1),curr_offset, ctx + (..));
@ requires \valid(composite);
@ requires iface_id < ctx->cfg[ctx->curr_cfg].interface_num;
@ requires \valid(buf + (0 .. MAX_DESCRIPTOR_LEN-1));
@ assigns *composite;
@ assigns buf[0 .. MAX_DESCRIPTOR_LEN-1 ];
@ assigns *curr_offset;
@ behavior INVPARAM:
@ assumes (curr_offset == \null || buf == \null || ctx == \null) ;
@ ensures *composite == \old(*composite);
@ ensures \result == MBED_ERROR_INVPARAM ;
@ behavior notcomposite:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes (ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function == \false);
@ assigns *composite;
@ ensures \result == MBED_ERROR_NONE ;
@ ensures *composite == \false;
@ behavior alreadycomposite:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes (ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function == \true);
@ assumes (*composite == \true);
@ assumes (composite_id == ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function_id) ;
@ ensures \result == MBED_ERROR_NONE ;
@ behavior newcomposite_NOSTORAGE:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes (ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function == \true);
@ assumes (*composite == \false);
@ assumes (*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_endpoint_descriptor_t))) ;
@ ensures *composite == \old(*composite);
@ ensures \result == MBED_ERROR_NOSTORAGE ;
@ behavior newcomposite_OK:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes (ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function == \true);
@ assumes (*composite == \false);
@ assumes (*curr_offset <= (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_endpoint_descriptor_t))) ;
@ ensures \result == MBED_ERROR_NONE ;
@ behavior curcomposite_NOSTORAGE:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes (ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function == \true);
@ assumes (*composite == \true);
@ assumes (composite_id != ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function_id) ;
@ assumes (*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_endpoint_descriptor_t))) ;
@ ensures \result == MBED_ERROR_NOSTORAGE ;
@ behavior curcomposite_OK:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes (ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function == \true);
@ assumes (*composite == \true);
@ assumes (composite_id != ctx->cfg[ctx->curr_cfg].interfaces[iface_id].composite_function_id) ;
@ assumes (*curr_offset <= (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_endpoint_descriptor_t))) ;
@ ensures \result == MBED_ERROR_NONE ;
@ complete behaviors ;
@ disjoint behaviors ;
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_handle_configuration_write_iad_desc(uint8_t *buf,
usbctrl_context_t const * const ctx,
bool *composite,
uint8_t composite_id,
uint8_t iface_id,
uint32_t * curr_offset)
{
mbed_error_t errcode = MBED_ERROR_NONE;
uint8_t curr_cfg = ctx->curr_cfg;
if (curr_offset == NULL || buf == NULL || ctx == NULL) {
errcode = MBED_ERROR_INVPARAM;
goto err;
}
/* current iface is a part of a composite function */
if (ctx->cfg[curr_cfg].interfaces[iface_id].composite_function == true) {
/* the composite function associated to current iface already has its header... */
if (*composite == true && composite_id == ctx->cfg[curr_cfg].interfaces[iface_id].composite_function_id) {
goto err;
}
/* overflow check */
if (*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_iad_descriptor_t))) {
errcode = MBED_ERROR_NOSTORAGE;
goto err;
}
/* new function: new IAD */
/* composite ifaces start with 0 */
/*@ assert *curr_offset < (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_iad_descriptor_t));*/
//usbctrl_iad_descriptor_t *cfg = (usbctrl_iad_descriptor_t*)&(buf[*curr_offset]);
usbctrl_iad_descriptor_t _cfg;
usbctrl_iad_descriptor_t *cfg = &_cfg;
cfg->bLength = sizeof(usbctrl_iad_descriptor_t);
cfg->bDescriptorType = USB_DESC_IAD;
cfg->bFirstInterface = iface_id;
/* specify number of interfaces of this composite function */
cfg->bInterfaceCount = 0;
uint8_t count = 0;
/*@
@ loop invariant iface_id <= i <= ctx->cfg[curr_cfg].interface_num;
@ loop assigns i, count;
@ loop variant ctx->cfg[curr_cfg].interface_num - i;
*/
for (uint8_t i = iface_id; i < ctx->cfg[curr_cfg].interface_num; ++i) {
if (ctx->cfg[curr_cfg].interfaces[i].composite_function && ctx->cfg[curr_cfg].interfaces[i].composite_function_id == composite_id) {
count++;
}
}
cfg->bInterfaceCount = count;
/* composite parent class, subclass and protocol is the one of the master interface of the composite device */
cfg->bFunctionClass = ctx->cfg[curr_cfg].interfaces[iface_id].usb_class;
cfg->bFunctionSubClass = ctx->cfg[curr_cfg].interfaces[iface_id].usb_subclass;
cfg->bFunctionProtocol = ctx->cfg[curr_cfg].interfaces[iface_id].usb_protocol;
cfg->iFunction = 0x04;
usbctrl_iad_desc_to_buff(cfg, (uint8_t*)&(buf[*curr_offset]));
*curr_offset += sizeof(usbctrl_iad_descriptor_t);
/*@ assert *curr_offset == \at(*curr_offset,Pre) + sizeof(usbctrl_iad_descriptor_t) ; */
} else {
/* current iface is not composite ? */
*composite = false;
}
err:
return errcode;
}
/*@
@ requires \separated(&SIZE_DESC_FIXED, &FLAG, buf+(..),curr_offset, ctx + (..));
@ assigns buf[0 .. MAX_DESCRIPTOR_LEN-1 ];
@ assigns *curr_offset;
@ behavior INVPARAM:
@ assumes (curr_offset == \null || buf == \null || ctx == \null) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ ensures *curr_offset == \old(*curr_offset);
@ behavior NOSTORAGE:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes (*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_configuration_descriptor_t))) ;
@ ensures \result == MBED_ERROR_NOSTORAGE ;
@ ensures *curr_offset == \old(*curr_offset);
@ behavior bad_iface:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes !(*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_configuration_descriptor_t))) ;
@ assumes iface_id >= MAX_INTERFACES_PER_DEVICE ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ ensures *curr_offset == \old(*curr_offset);
@ behavior OK:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes !(*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_configuration_descriptor_t))) ;
@ assumes iface_id < MAX_INTERFACES_PER_DEVICE ;
@ ensures \result == MBED_ERROR_NONE ;
@ ensures *curr_offset == \old(*curr_offset) + sizeof(usbctrl_interface_descriptor_t) ;
@ complete behaviors ;
@ disjoint behaviors ;
*/
/*
CDE : not possible to validate assigns clause for behavior OK because of cast : (usbctrl_interface_descriptor_t*)&(buf[*curr_offset]) (WP memory model)
RBE : fix attempt
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_handle_configuration_write_iface_desc(uint8_t *buf,
usbctrl_context_t const * const ctx,
uint8_t iface_id,
uint32_t * curr_offset)
{
mbed_error_t errcode = MBED_ERROR_NONE;
uint8_t num_ep = 0;
uint8_t curr_cfg = ctx->curr_cfg;
if (buf == NULL || curr_offset == NULL || ctx == NULL) {
errcode = MBED_ERROR_INVPARAM;
goto err;
}
if (*curr_offset > (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_interface_descriptor_t))) {
errcode = MBED_ERROR_NOSTORAGE;
goto err;
}
//if (iface_id == 255) { // cyril : rte here, if iface_id >= MAX_INTERFACES_PER_DEVICE
if (iface_id >= MAX_INTERFACES_PER_DEVICE) {
/* DEFENSIVE PROGRAMMING:
* the expected number of interfaces is limited to a small number, thus, to avoid an u8
* overflow below, we check its value here */
errcode = MBED_ERROR_INVPARAM;
goto err;
}
/* pointing to next field: interface descriptor */
//usbctrl_interface_descriptor_t *cfg = (usbctrl_interface_descriptor_t*)&(buf[*curr_offset]);
usbctrl_interface_descriptor_t _cfg;
usbctrl_interface_descriptor_t *cfg = &_cfg;
cfg->bLength = sizeof(usbctrl_interface_descriptor_t);
cfg->bDescriptorType = USB_DESC_INTERFACE;
cfg->bInterfaceNumber = iface_id;
cfg->bAlternateSetting = 0;
/*@
@ loop invariant 0 <= ep <= ctx->cfg[curr_cfg].interfaces[iface_id].usb_ep_number ;
@ loop invariant \valid_read(ctx->cfg[curr_cfg].interfaces[iface_id].eps + (0..(ctx->cfg[curr_cfg].interfaces[iface_id].usb_ep_number -1))) ;
@ loop assigns num_ep, ep ;
@ loop variant (ctx->cfg[curr_cfg].interfaces[iface_id].usb_ep_number - ep);
*/
for (uint8_t ep = 0; ep < ctx->cfg[curr_cfg].interfaces[iface_id].usb_ep_number; ++ep) {
if (ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep].type != USB_EP_TYPE_CONTROL) {
++num_ep;
}
if (ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep].dir == USB_EP_DIR_BOTH) {
++num_ep;
}
}
cfg->bNumEndpoints = num_ep;
cfg->bInterfaceClass = (uint8_t)ctx->cfg[curr_cfg].interfaces[iface_id].usb_class;
cfg->bInterfaceSubClass = ctx->cfg[curr_cfg].interfaces[iface_id].usb_subclass;
cfg->bInterfaceProtocol = ctx->cfg[curr_cfg].interfaces[iface_id].usb_protocol;
cfg->iInterface = iface_id;
usbctrl_interface_desc_to_buff(cfg, (uint8_t*)&(buf[*curr_offset]));
*curr_offset += sizeof(usbctrl_interface_descriptor_t);
/*@ assert *curr_offset == \at(*curr_offset,Pre) + sizeof(usbctrl_interface_descriptor_t) ; */
err:
return errcode;
}
/*@
@ requires \separated(&SIZE_DESC_FIXED, &FLAG, buf+(..),curr_offset, ctx + (..));
@ assigns buf[0 .. MAX_DESCRIPTOR_LEN-1 ];
@ assigns *curr_offset, FLAG;
@ behavior INVPARAM:
@ assumes (curr_offset == \null || buf == \null || ctx == \null) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ ensures *curr_offset == \old(*curr_offset);
@ ensures FLAG == \old(FLAG);
@ behavior bad_iface:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes iface_id == 255 ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ ensures *curr_offset == \old(*curr_offset);
@ ensures FLAG == \old(FLAG);
@ behavior OTHER:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes iface_id != 255 ;
@ ensures \result == MBED_ERROR_NONE ||
(\result == MBED_ERROR_NOBACKEND && (*curr_offset == \old(*curr_offset))) ||
(\result == MBED_ERROR_INVPARAM && (*curr_offset == \old(*curr_offset))) ;
@ complete behaviors ;
@ disjoint behaviors ;
*/
/*
TODO : be more precise with OTHER behavior (pb is with get_handler errcode and class_desc_handler errcode : not possible to try errcode != MBED_ERROR_NONE )
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_handle_configuration_write_class_desc(usbctrl_context_t * ctx,
uint8_t * buf,
uint8_t iface_id,
uint32_t * curr_offset)
{
mbed_error_t errcode = MBED_ERROR_NONE;
uint8_t curr_cfg = ctx->curr_cfg;
uint32_t handler;
uint32_t max_buf_size = 0;
uint8_t class_desc_max_size = 0;
if (buf == NULL || curr_offset == NULL || ctx == NULL) {
errcode = MBED_ERROR_INVPARAM;
goto err;
}
if (iface_id == 255) {
/* DEFENSIVE PROGRAMMING:
* the expected number of interfaces is limited to a small number, thus, to avoid an u8
* overflow below, we check its value here */
errcode = MBED_ERROR_INVPARAM;
goto err;
}
max_buf_size = MAX_DESCRIPTOR_LEN - *curr_offset;
// class level descriptor of current interface
if (ctx->cfg[curr_cfg].interfaces[iface_id].class_desc_handler) {
/* get back the buffer address to pass to the upper handler, so that the upper
* handler directly forge its descriptor into the buffer */
uint8_t *cfg = &(buf[*curr_offset]);
if (usbctrl_get_handler(ctx, &handler) != MBED_ERROR_NONE) {
log_printf("[LIBCTRL] Unable to get back handler from ctx\n");
errcode = MBED_ERROR_NOBACKEND;
goto err;
}
/* FIXME: there is a RTE here, to check if the semantic of __FRAMAC__ version is okay, using a noRTE statement globaly */
/* we need to get back class level descriptor from upper layer. Although, we have already consumed a part of the target buffer and
* thus we reduce the max allowed size for class descriptor.
* normally we can assert cur_offset >= MAX_DESCRIPTOR_LEN */
if (max_buf_size > 256) {
class_desc_max_size = 255;
} else {
/* reducing buffer to effective max buf size if shorter than uint8_t size */
class_desc_max_size = (uint8_t)(max_buf_size & 0xff);
}
#ifndef __FRAMAC__
if (handler_sanity_check_with_panic((physaddr_t)ctx->cfg[curr_cfg].interfaces[iface_id].class_desc_handler)) {
goto err;
}
#endif
#if defined(__FRAMAC__)
FLAG = true ;
#endif/*__FRAMAC__*/
/*@ assert ctx->cfg[curr_cfg].interfaces[iface_id].class_desc_handler ∈ {&class_get_descriptor}; */
/*@ calls class_get_descriptor; */
errcode = ctx->cfg[curr_cfg].interfaces[iface_id].class_desc_handler(iface_id, cfg, &class_desc_max_size, handler);
if (errcode != MBED_ERROR_NONE) {
goto err;
}
*curr_offset += class_desc_max_size;
}
err:
return errcode;
}
/*@
@ requires \separated(&SIZE_DESC_FIXED, &FLAG, buf+(0 .. MAX_DESCRIPTOR_LEN-1),curr_offset, ctx + (..));
@ requires iface_id < ctx->cfg[ctx->curr_cfg].interface_num;
@ requires \valid(buf + (0 .. MAX_DESCRIPTOR_LEN-1));
@ assigns buf[0 .. MAX_DESCRIPTOR_LEN-1 ];
@ assigns *curr_offset;
@ behavior INVPARAM:
@ assumes (curr_offset == \null || buf == \null || ctx == \null) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ ensures *curr_offset == \old(*curr_offset) ;
@ behavior NOSTORAGE:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes (*curr_offset >= (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_endpoint_descriptor_t))) ;
@ ensures \result == MBED_ERROR_NOSTORAGE ;
@ ensures *curr_offset == \old(*curr_offset) ;
@ behavior OK:
@ assumes !(curr_offset == \null || buf == \null || ctx == \null) ;
@ assumes !(*curr_offset >= (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_endpoint_descriptor_t))) ;
@ ensures \result == MBED_ERROR_NONE ;
@ ensures *curr_offset == \old(*curr_offset) + sizeof(usbctrl_endpoint_descriptor_t) ;
@ complete behaviors ;
@ disjoint behaviors ;
*/
/*
CDE : not possible to validate assigns clause because of cast : (usbctrl_endpoint_descriptor_t*)&(buf[*curr_offset]) (WP memory model)
RBE : fix attempt
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_handle_configuration_write_ep_desc(usbctrl_context_t const * const ctx,
uint8_t * buf,
uint8_t ep_number,
usb_ep_dir_t ep_dir,
uint8_t iface_id,
uint8_t curr_cfg,
uint32_t * curr_offset)
{
mbed_error_t errcode = MBED_ERROR_NONE;
uint8_t poll = 0;
if (buf == NULL || curr_offset == NULL || ctx == NULL) {
errcode = MBED_ERROR_INVPARAM;
goto err;
}
if (*curr_offset >= (MAX_DESCRIPTOR_LEN - sizeof(usbctrl_endpoint_descriptor_t))) {
errcode = MBED_ERROR_NOSTORAGE;
goto err;
}
//usbctrl_endpoint_descriptor_t *cfg = (usbctrl_endpoint_descriptor_t*)&(buf[*curr_offset]);
usbctrl_endpoint_descriptor_t _cfg;
usbctrl_endpoint_descriptor_t *cfg = &_cfg;
cfg->bLength = sizeof(usbctrl_endpoint_descriptor_t);
cfg->bDescriptorType = USB_DESC_ENDPOINT;
cfg->bEndpointAddress = ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep_number].ep_num;
if (ep_dir == USB_EP_DIR_IN) {
cfg->bEndpointAddress |= 0x80; /* set bit 7 to 1 for IN EPs */
}
cfg->bmAttributes = (uint8_t)
(ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep_number].type |
ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep_number].attr << 2 |
ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep_number].usage << 4);
cfg->wMaxPacketSize = ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep_number].pkt_maxsize;
/* See table 9.3: microframe interval: bInterval specification */
if (ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep_number].type == USB_EP_TYPE_INTERRUPT) {
/* in case of HS driver, bInterval == 2^(interval-1), where interval is the
* uframe length. In FS, the interval is free between 1 and 255. To simplify
* the handling of bInterval, knowing that drivers both set uFrame interval to 3
* we use the same 2^(interval-1) calculation for HS and FS */
/* TODO: here, we consider that the usb backend driver set the uFrame interval to 3,
* it would be better to get back the uFrame interval from the driver and calculate
* the bInterval value */
/* calculating interval depending on backend driver, to get
* back the same polling interval (i.e. 64 ms, hardcoded by now */
poll = ctx->cfg[curr_cfg].interfaces[iface_id].eps[ep_number].poll_interval;
/* falling back to 1ms polling, if not set */
if (poll == 0) {
log_printf("[USBCTRL] invalid poll interval %d\n", poll);
poll = 1;
}
if (usb_backend_drv_get_speed() == USB_BACKEND_DRV_PORT_HIGHSPEED) {
/* value in poll is set in ms, in HS, value is 2^(interval-1)*125us
* here, we get the position of the first bit at 1 in poll value, and add 2 to this
* value, to get the same result as the above */
uint8_t i = 0;
/* get back the position of the first '1' bit */
uint8_t compteur_poll = 9;
/*@
@ loop invariant i >= 0 ;
@ loop invariant poll >= 0 ;
@ loop invariant 0 <= compteur_poll <= 9 ;
@ loop assigns poll, i, compteur_poll;
@ loop variant compteur_poll;
*/
while (!(poll & 0x1) && compteur_poll > 0) {
poll >>= 1;
i++;
compteur_poll -- ;
}
/* binary shift left by 2, to handle (interval-1)*125us from a value in milisecond */
i+=2;
poll = i;
} else {
/* in Fullspeed, the bInterval field is directly set in ms, between 1 and 255 */
}
} else {
/* for BULK EP, we set bInterval to 0 */
poll = 0;
}
cfg->bInterval = poll;
usbctrl_ep_desc_to_buff(cfg, (uint8_t*)&(buf[*curr_offset]));
*curr_offset += sizeof(usbctrl_endpoint_descriptor_t);
/*@ assert *curr_offset == \at(*curr_offset,Pre) + sizeof(usbctrl_endpoint_descriptor_t) ; */
err:
return errcode;
}
/*********************************************************************************
* device descriptor handling fonction
*/
/*
* It is considered here that the buffer is large enough to hold the
* requested descriptor. The buffer size is under the control of the