-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusbctrl_requests.c
More file actions
2692 lines (2386 loc) · 111 KB
/
usbctrl_requests.c
File metadata and controls
2692 lines (2386 loc) · 111 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/sync.h"
#include "api/libusbctrl.h"
#include "usbctrl_state.h"
#include "usbctrl.h"
#include "usbctrl_descriptors.h"
/**********************************************************************
* About utility functions
* Here, we handle the bmRequestType field, which is a bitmap. We return the requested
* field independently
*********************************************************************/
#if defined(__FRAMAC__)
static bool conf_set = false;
/*@
@ assigns conf_set;
*/
void usbctrl_configuration_set(void)
{
set_bool_with_membarrier(&conf_set, true);
}
#endif/*__FRAMAC__*/
/*
* USB request type is set on 2 bits, the enumerate is complete, no other value is
* possible
*/
typedef enum {
USB_REQ_TYPE_STD = 0,
USB_REQ_TYPE_CLASS = 1,
USB_REQ_TYPE_VENDOR = 2,
USB_REQ_TYPE_RESERVED = 3
} usbctrl_req_type_t;
/*
* USB request direction is set on 1 bit. Enumerate complete
*/
typedef enum {
USB_REQ_DIR_H2D = 0,
USB_REQ_DIR_D2H = 1,
} usbctrl_req_dir_t;
/*
* USB request recipient, set on 5 bits (0..4). Value 4 to 31 are reserved
*/
typedef enum {
USB_REQ_RECIPIENT_DEVICE = 0,
USB_REQ_RECIPIENT_INTERFACE = 1,
USB_REQ_RECIPIENT_ENDPOINT = 2,
USB_REQ_RECIPIENT_OTHER = 3,
} usbctrl_req_recipient_t;
/*@
@ requires \valid_read(pkt);
@ assigns \nothing ;
@ ensures \result == ((pkt->bmRequestType >> 5) & 0x3) ;
*/
#ifndef __FRAMAC__
static inline
#endif
usbctrl_req_type_t usbctrl_std_req_get_type(usbctrl_setup_pkt_t const * const pkt)
{
/* bits 6..5 */
return ((pkt->bmRequestType >> 5) & 0x3);
}
/*@
@ requires \valid_read(pkt);
@ assigns \nothing ;
@ ensures \result == ((pkt->bmRequestType) & 0x1F);
*/
#ifndef __FRAMAC__
static inline
#endif
usbctrl_req_recipient_t usbctrl_std_req_get_recipient(usbctrl_setup_pkt_t const * const pkt)
{
/* bits 4..0 */
return ((pkt->bmRequestType) & 0x1F);
}
typedef enum {
USB_REQ_DESCRIPTOR_DEVICE = 1,
USB_REQ_DESCRIPTOR_CONFIGURATION = 2,
USB_REQ_DESCRIPTOR_STRING = 3,
USB_REQ_DESCRIPTOR_INTERFACE = 4,
USB_REQ_DESCRIPTOR_ENDPOINT = 5,
USB_REQ_DESCRIPTOR_DEVICE_QUALIFIER = 6,
USB_REQ_DESCRIPTOR_OTHER_SPEED_CFG = 7,
USB_REQ_DESCRIPTOR_INTERFACE_POWER = 8,
} usbctrl_req_descriptor_type_t;
/*@
@ requires \valid_read(pkt);
@ assigns \nothing ;
@ ensures (\result == pkt->wValue >> 8) ;
*/
#ifndef __FRAMAC__
static inline
#endif
usbctrl_req_descriptor_type_t usbctrl_std_req_get_descriptor_type(usbctrl_setup_pkt_t const * const pkt)
{
/* explicit cast of the high byte of wValue */
usbctrl_req_descriptor_type_t val = (usbctrl_req_descriptor_type_t)(pkt->wValue >> 8);
return val;
}
/****************************************************
* About state check
*
* All requests must be sent in one of the following states:
* DEFAUT, ADDRESS, CONFIGURED.
* The check must be done before handling any requests
***************************************************/
/*@
@ requires \valid_read(ctx);
@ assigns \nothing ;
@ behavior true :
@ assumes (ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED) ;
@ ensures \result == \true ;
@ behavior false :
@ assumes !((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ ensures \result == \false ;
@ complete behaviors;
@ disjoint behaviors ;
*/
#ifndef __FRAMAC__
static inline
#endif
bool is_std_requests_allowed(usbctrl_context_t const * const ctx)
{
if (usbctrl_get_state(ctx) == USB_DEVICE_STATE_DEFAULT ||
usbctrl_get_state(ctx) == USB_DEVICE_STATE_ADDRESS ||
usbctrl_get_state(ctx) == USB_DEVICE_STATE_CONFIGURED)
{
return true;
}
return false;
}
/*@
@ requires \valid_read(ctx);
@ assigns \nothing ;
@ behavior true :
@ assumes (ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED) ;
@ ensures \result == \true ;
@ behavior false :
@ assumes !((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ ensures \result == \false ;
@ complete behaviors;
@ disjoint behaviors ;
*/
#ifndef __FRAMAC__
static inline
#endif
bool is_vendor_requests_allowed(usbctrl_context_t const * const ctx)
{
if (usbctrl_get_state(ctx) == USB_DEVICE_STATE_DEFAULT ||
usbctrl_get_state(ctx) == USB_DEVICE_STATE_ADDRESS ||
usbctrl_get_state(ctx) == USB_DEVICE_STATE_CONFIGURED)
{
return true;
}
return false;
}
/***********************************
* About configuration set/unset utilities (used by set_configuration function)
*/
/*
* Deactivate currently configured endpoints
*/
/*@
@ requires \separated(ctx,&GHOST_opaque_drv_privates);
@ assigns *ctx , GHOST_opaque_drv_privates;
@ ensures \result == MBED_ERROR_INVPARAM || \result == MBED_ERROR_NONE ;
*/
mbed_error_t usbctrl_unset_active_endpoints(usbctrl_context_t *ctx)
{
mbed_error_t errcode = MBED_ERROR_NONE;
if (ctx == NULL) {
errcode = MBED_ERROR_INVPARAM;
goto err;
}
uint8_t curr_cfg = ctx->curr_cfg;
uint8_t max_iface = ctx->cfg[curr_cfg].interface_num ;
/*@
@ loop invariant 0 <= iface <= max_iface ;
@ loop invariant \valid(ctx->cfg[curr_cfg].interfaces +(0..(max_iface-1)));
@ loop invariant \separated(ctx->cfg[curr_cfg].interfaces +(0..(max_iface-1)));
@ loop assigns iface, errcode, *ctx, GHOST_opaque_drv_privates;
@ loop variant (max_iface - iface);
*/
for (uint8_t iface = 0; iface < max_iface; ++iface) {
uint8_t max_ep = ctx->cfg[curr_cfg].interfaces[iface].usb_ep_number ;
/*@
@ loop invariant 0 <= i <= max_ep ;
@ loop invariant \valid(ctx->cfg[curr_cfg].interfaces +(0..(max_iface-1)));
@ loop invariant \valid(ctx->cfg[curr_cfg].interfaces[iface].eps + (0..(max_ep-1))) ;
@ loop invariant \separated(ctx);
@ loop assigns i, errcode, *ctx, GHOST_opaque_drv_privates;
@ loop variant (max_ep - i) ;
*/
for (uint8_t i = 0; i < max_ep; ++i) {
if (ctx->cfg[curr_cfg].interfaces[iface].eps[i].configured == true) {
errcode = usb_backend_drv_deconfigure_endpoint(ctx->cfg[curr_cfg].interfaces[iface].eps[i].ep_num);
if (errcode != MBED_ERROR_NONE) {
log_printf("[USBCTRL] failure while deconfiguring EP %x\n",
usb_backend_drv_deconfigure_endpoint(ctx->cfg[curr_cfg].interfaces[iface].eps[i].ep_num));
}
set_bool_with_membarrier(&ctx->cfg[curr_cfg].interfaces[iface].eps[i].configured, false);
}
}
}
err:
return errcode;
}
/*@
@ requires \separated(ctx);
@ assigns *ctx ;
@ assigns GHOST_in_eps[0 .. USB_BACKEND_DRV_MAX_IN_EP-1].state;
@ assigns GHOST_out_eps[0 .. USB_BACKEND_DRV_MAX_OUT_EP-1].state;
@ ensures \result == MBED_ERROR_NONE || \result == MBED_ERROR_INVPARAM || \result ≡ MBED_ERROR_NOSTORAGE ;
*/
/*
* Active endpoint for current configuration
*/
#ifndef __FRAMAC__
static inline
#endif
mbed_error_t usbctrl_set_active_endpoints(usbctrl_context_t *ctx)
{
mbed_error_t errcode = MBED_ERROR_NONE;
if (ctx == NULL) {
errcode = MBED_ERROR_INVPARAM;
goto err;
}
uint8_t curr_cfg = ctx->curr_cfg;
uint8_t max_iface = ctx->cfg[curr_cfg].interface_num ;
/*@
@ loop invariant 0 <= iface <= max_iface ;
@ loop invariant \valid(ctx->cfg[curr_cfg].interfaces +(0..(max_iface-1)));
@ loop invariant \separated(ctx->cfg[curr_cfg].interfaces +(0..(max_iface-1)));
@ loop assigns iface, errcode, *ctx, GHOST_in_eps[0 .. 6 - 1].state, GHOST_out_eps[0 .. 6 - 1].state;
@ loop variant (max_iface - iface);
*/
for (uint8_t iface = 0; iface < max_iface; ++iface) {
uint8_t max_ep = ctx->cfg[curr_cfg].interfaces[iface].usb_ep_number ;
/*@
@ loop invariant 0 <= i <= max_ep ;
@ loop invariant \valid(ctx->cfg[curr_cfg].interfaces +(0..(max_iface-1)));
@ loop invariant \valid(ctx->cfg[curr_cfg].interfaces[iface].eps + (0..(max_ep-1))) ;
@ loop invariant \separated(ctx);
@ loop assigns i, errcode, *ctx, GHOST_in_eps[0 .. 6 - 1].state, GHOST_out_eps[0 .. 6 - 1].state;
@ loop variant (max_ep - i) ;
*/
for (uint8_t i = 0; i < max_ep; ++i) {
usb_backend_drv_ep_dir_t dir;
usb_backend_drv_ep_type_t type;
switch (ctx->cfg[curr_cfg].interfaces[iface].eps[i].dir) {
case USB_EP_DIR_OUT:
dir = USB_BACKEND_DRV_EP_DIR_OUT;
break;
case USB_EP_DIR_IN:
dir = USB_BACKEND_DRV_EP_DIR_IN;
break;
case USB_EP_DIR_BOTH:
dir = USB_BACKEND_DRV_EP_DIR_BOTH;
break;
default:
log_printf("[USBCTRL] invalid EP dir !\n");
errcode = MBED_ERROR_INVPARAM;
goto err;
break;
}
switch (ctx->cfg[curr_cfg].interfaces[iface].eps[i].type) {
case USB_EP_TYPE_CONTROL:
type = USB_BACKEND_DRV_EP_TYPE_CONTROL;
break;
case USB_EP_TYPE_ISOCHRONOUS:
type = USB_BACKEND_DRV_EP_TYPE_ISOCHRONOUS;
break;
case USB_EP_TYPE_BULK:
type = USB_BACKEND_DRV_EP_TYPE_BULK;
break;
case USB_EP_TYPE_INTERRUPT:
type = USB_BACKEND_DRV_EP_TYPE_INT;
break;
default:
log_printf("[USBCTRL] invalid EP type !\n");
errcode = MBED_ERROR_INVPARAM;
goto err;
break;
}
log_printf("[LIBCTRL] configure EP %d (dir %d)\n", ctx->cfg[curr_cfg].interfaces[iface].eps[i].ep_num, dir);
if (ctx->cfg[curr_cfg].interfaces[iface].eps[i].type != USB_EP_TYPE_CONTROL) {
errcode = usb_backend_drv_configure_endpoint(ctx->cfg[curr_cfg].interfaces[iface].eps[i].ep_num,
type,
dir,
ctx->cfg[curr_cfg].interfaces[iface].eps[i].pkt_maxsize,
USB_BACKEND_EP_ODDFRAME,
ctx->cfg[curr_cfg].interfaces[iface].eps[i].handler);
/*@ assert errcode == MBED_ERROR_INVSTATE || errcode == MBED_ERROR_NONE || errcode == MBED_ERROR_NOSTORAGE ; */
if (errcode != MBED_ERROR_NONE) {
log_printf("[LIBCTRL] unable to configure EP %d (dir %d): err %d\n", ctx->cfg[curr_cfg].interfaces[iface].eps[i].ep_num, dir, errcode);
goto err;
}
}
set_bool_with_membarrier(&ctx->cfg[curr_cfg].interfaces[iface].eps[i].configured, true);
}
}
err:
return errcode;
}
/*
* About standard requests handling.
*
* All standard requests are not handled in any state. Current state automaton must
* be checked.
* The following functions handle one dedicated standard request.
*/
/*@
@ requires \valid(ctx) ;
@ requires \separated(ctx,pkt);
@ assigns *pkt, *ctx ;
@ behavior std_requests_not_allowed:
@ assumes !((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ ensures \result == MBED_ERROR_INVSTATE ;
@ behavior std_requests_allowed:
@ assumes ((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ ensures \result == MBED_ERROR_NONE ;
@ ensures ctx->ctrl_req_processing == \false;
@ complete behaviors ;
@ disjoint behaviors ;
*/
/*
* Device-wide clear feature handling (not interface or endpoint). Per-interface clear_feature request
* are handled by rqst_handler of each interface.
* device-wide features are USB test and remote wakeup features.
* By now, they are not supported.
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_std_req_handle_clear_feature(usbctrl_setup_pkt_t const * const pkt __attribute__((unused)),
usbctrl_context_t *ctx)
{
mbed_error_t errcode = MBED_ERROR_NONE;
log_printf("[USBCTRL] Std req: clear feature\n");
if (!is_std_requests_allowed(ctx)) {
/* error handling, invalid state */
errcode = MBED_ERROR_INVSTATE;
goto err;
}
/* handling standard Request */
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
err:
return errcode;
}
/*@
@ requires \valid(ctx) && \valid_read(pkt) ;
@ requires \separated(ctx+(..),pkt,&GHOST_opaque_drv_privates);
@ assigns *ctx, GHOST_opaque_drv_privates, GHOST_in_eps[0].state ;
// Formal USB 2.0 conformity
// USB 2.0, chap. 9.4.5
@ behavior invalid_pkt_wvalue:
@ assumes pkt->wValue != 0;
@ ensures \result == MBED_ERROR_INVPARAM;
@ behavior invalid_pkt_wlength:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength != 2;
@ ensures \result == MBED_ERROR_INVPARAM;
@ behavior std_requests_not_allowed:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes !((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ ensures \result == MBED_ERROR_INVSTATE ;
// default state use case
@ behavior USB_DEVICE_STATE_DEFAULT:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_DEFAULT ;
@ ensures \result == MBED_ERROR_NONE ; // not forbidden, but undefined by USB 2.0
@ ensures ctx->ctrl_req_processing == \false;
// address state use cases
// --> initial checks (global to address state)
@ behavior USB_DEVICE_STATE_ADDRESS_bad_recipient_bad_index:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_ADDRESS ;
@ assumes ((((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_ENDPOINT && ((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_DEVICE) || ((pkt->wIndex & 0xf) != 0)) ;
@ ensures \result == MBED_ERROR_INVSTATE ;
@ ensures ctx->ctrl_req_processing == \false;
// --> endpoint: invalid endpoint, only EP0 allowed
@ behavior USB_DEVICE_STATE_ADDRESS_recipient_USB_REQ_RECIPIENT_ENDPOINT_endpoint_false:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_ADDRESS ;
@ assumes !((((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_ENDPOINT && ((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_DEVICE) || ((pkt->wIndex & 0xf) != 0)) ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_ENDPOINT) ;
@ assumes ((pkt->wIndex & 0xf) != EP0) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ ensures ctx->ctrl_req_processing == \false;
// --> endpoint: EP0 requested. For both valid and invalid direction (NAK or ACK)
@ behavior USB_DEVICE_STATE_ADDRESS_recipient_USB_REQ_RECIPIENT_ENDPOINT_endpoint_true:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_ADDRESS ;
@ assumes !((((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_ENDPOINT && ((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_DEVICE) || ((pkt->wIndex & 0xf) != 0)) ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_ENDPOINT) ;
@ assumes !((pkt->wIndex & 0xf) != EP0) ;
@ ensures \result == MBED_ERROR_NONE ;
// --> device: allowed in address state, if wIndex == 0
@ behavior USB_DEVICE_STATE_ADDRESS_recipient_USB_REQ_RECIPIENT_DEVICE_windex_valid:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_ADDRESS ;
@ assumes !((((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_ENDPOINT && ((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_DEVICE) || ((pkt->wIndex & 0xf) != 0)) ;
@ assumes !(pkt->wIndex != 0) ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_DEVICE) ;
@ ensures \result == MBED_ERROR_NONE ;
// --> device: invalid in address state, if wIndex != 0
@ behavior USB_DEVICE_STATE_ADDRESS_recipient_USB_REQ_RECIPIENT_DEVICE_windex_invalid:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_ADDRESS ;
@ assumes !((((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_ENDPOINT && ((pkt->bmRequestType) & 0x1F) != USB_REQ_RECIPIENT_DEVICE) || ((pkt->wIndex & 0xf) != 0)) ;
@ assumes (pkt->wIndex != 0) ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_DEVICE) ;
@ ensures \result == MBED_ERROR_NONE ;
// configured state use cases
// --> endpoint: target EP is not EP0 and it does not exists
@ behavior USB_DEVICE_STATE_CONFIGURED_recipient_USB_REQ_RECIPIENT_ENDPOINT_endpoint_false:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_ENDPOINT) ;
@ assumes ((pkt->wIndex & 0xf) != EP0) ;
@ assumes !(\exists integer i,j ; 0 <= i < ctx->cfg[ctx->curr_cfg].interface_num && 0 <= j < ctx->cfg[ctx->curr_cfg].interfaces[i].usb_ep_number &&
ctx->cfg[ctx->curr_cfg].interfaces[i].eps[j].ep_num == (pkt->wIndex & 0xf)) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ ensures ctx->ctrl_req_processing == \false;
// --> endpoint: target EP is not EP0 and it exists
@ behavior USB_DEVICE_STATE_CONFIGURED_recipient_USB_REQ_RECIPIENT_ENDPOINT_endpoint_true:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_ENDPOINT) ;
@ assumes ((pkt->wIndex & 0xf) != EP0) ;
@ assumes (\exists integer i,j ; 0 <= i < ctx->cfg[ctx->curr_cfg].interface_num && 0 <= j < ctx->cfg[ctx->curr_cfg].interfaces[i].usb_ep_number &&
ctx->cfg[ctx->curr_cfg].interfaces[i].eps[j].ep_num == (pkt->wIndex & 0xf)) ;
@ ensures \result == MBED_ERROR_NONE ;
// --> endpoint: target EP is EP0
@ behavior USB_DEVICE_STATE_CONFIGURED_recipient_USB_REQ_RECIPIENT_ENDPOINT_endpoint_0:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_ENDPOINT) ;
@ assumes ((pkt->wIndex & 0xf) == EP0) ;
@ ensures \result == MBED_ERROR_NONE ;
// --> interface: iface not found
@ behavior USB_DEVICE_STATE_CONFIGURED_recipient_USB_REQ_RECIPIENT_INTERFACE_false:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_INTERFACE) ;
@ assumes !(\exists integer i,j ; 0 <= i < ctx->cfg[ctx->curr_cfg].interface_num &&
ctx->cfg[ctx->curr_cfg].interfaces[i].id == (pkt->wIndex & 0xf)) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ ensures ctx->ctrl_req_processing == \false;
// --> interface: iface found
@ behavior USB_DEVICE_STATE_CONFIGURED_recipient_USB_REQ_RECIPIENT_INTERFACE_true:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_INTERFACE) ;
@ assumes (\exists integer i,j ; 0 <= i < ctx->cfg[ctx->curr_cfg].interface_num &&
ctx->cfg[ctx->curr_cfg].interfaces[i].id == (pkt->wIndex & 0xf)) ;
@ ensures \result == MBED_ERROR_NONE;
// --> device, wIndex != 0 (we stall, said as undefined)
@ behavior USB_DEVICE_STATE_CONFIGURED_recipient_USB_REQ_RECIPIENT_DEVICE_windex_invalid:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_DEVICE) ;
@ assumes (pkt->wIndex != 0) ;
@ ensures \result == MBED_ERROR_NONE ;
// --> device, wIndex == 0
@ behavior USB_DEVICE_STATE_CONFIGURED_recipient_USB_REQ_RECIPIENT_DEVICE_windex_valid:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ assumes (((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_DEVICE) ;
@ assumes !(pkt->wIndex != 0) ;
@ ensures \result == MBED_ERROR_NONE ;
// --> others
@ behavior USB_DEVICE_STATE_CONFIGURED_recipient_others:
@ assumes pkt->wValue == 0;
@ assumes pkt->wLength == 2;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ assumes !(((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_DEVICE ||
((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_INTERFACE ||
((pkt->bmRequestType) & 0x1F) == USB_REQ_RECIPIENT_ENDPOINT) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ complete behaviors ;
@ disjoint behaviors ;
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_std_req_handle_get_status(const usbctrl_setup_pkt_t *pkt,
usbctrl_context_t *ctx)
{
mbed_error_t errcode = MBED_ERROR_NONE;
log_printf("[USBCTRL] Std req: get status\n");
#ifdef CONFIG_USR_LIB_USBCTRL_STRICT_USB_CONFORMITY
/* USB 2.0 conformity:
* "if wValue and wLength are not specified as above, the behavior is undefined".
* Of course, undefined can't be tolerate. We stall here.
*/
if (pkt->wValue != 0) {
errcode = MBED_ERROR_INVPARAM;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
goto err;
}
if (pkt->wLength != 2) {
errcode = MBED_ERROR_INVPARAM;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
goto err;
}
#endif
if (!is_std_requests_allowed(ctx)) {
/* error handling, invalid state */
errcode = MBED_ERROR_INVSTATE;
goto err;
}
/* handling standard Request */
switch (usbctrl_get_state(ctx)) {
case USB_DEVICE_STATE_DEFAULT:
/* This case is not forbidden by USB2.0 standard, but the behavior is
* undefined. We can, for example, stall out. */
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
break;
case USB_DEVICE_STATE_ADDRESS:
if (usbctrl_std_req_get_recipient(pkt) != USB_REQ_RECIPIENT_ENDPOINT &&
usbctrl_std_req_get_recipient(pkt) != USB_REQ_RECIPIENT_DEVICE)
{
/* only interface or endpoint 0 allowed in ADDRESS state */
/* request error: sending STALL on status or data */
errcode = MBED_ERROR_INVSTATE;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
goto err;
}
if ((pkt->wIndex & 0xf) != 0) {
/* only device or endpoint 0 allowed in ADDRESS state */
/* request error: sending STALL on status or data */
errcode = MBED_ERROR_INVSTATE;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
goto err;
}
/* handling get_status() for other cases */
switch (usbctrl_std_req_get_recipient(pkt)) {
case USB_REQ_RECIPIENT_ENDPOINT: {
/*does requested EP exists ? */
uint8_t epnum = pkt->wIndex & 0xf;
if (epnum != EP0) {
errcode = MBED_ERROR_INVSTATE;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
goto err;
}
/* return the recipient (EP0) status (2 bytes, or wLength if smaller) */
uint8_t resp[2] = { 0 };
usb_backend_drv_send_data((uint8_t *)&resp, (pkt->wLength >= 2 ? 2 : pkt->wLength), EP0);
usb_backend_drv_ack(0, USB_BACKEND_DRV_EP_DIR_OUT);
/* std req finishes at the oepint rise */
break;
}
case USB_REQ_RECIPIENT_DEVICE: {
if (pkt->wIndex != 0) {
/* says as not specified. We stall. Yet this is not forbidden (errcode=NONE. */
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
}
/* return the recipient status (2 bytes, or wLength if smaller) */
uint8_t resp[2] = { 0 };
#if CONFIG_USR_LIB_USBCTRL_DEV_SELFPOWERED
/* INFO: self-power mode does not support dynamicity and can't be cleared by host through
* SetFeature() or ClearFeature() (allowed by USB standard, see chap. 9.4.5) */
resp[0] |= 1;
#endif
/* FIXME: add remoteWakeup field setting to resp */
usb_backend_drv_send_data((uint8_t *)&resp, (pkt->wLength >= 2 ? 2 : pkt->wLength), EP0);
usb_backend_drv_ack(0, USB_BACKEND_DRV_EP_DIR_OUT);
/* std req finishes at the oepint rise */
break;
}
default:
errcode = MBED_ERROR_INVSTATE;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
goto err;
}
break;
case USB_DEVICE_STATE_CONFIGURED:
/* check that the recipient exists */
/* return the recipient status */
switch (usbctrl_std_req_get_recipient(pkt)) {
case USB_REQ_RECIPIENT_ENDPOINT: {
/*does requested EP exists ? */
uint8_t epnum = pkt->wIndex & 0xf;
/* EP0 does exists, It's me... */
if (epnum != EP0 && !usbctrl_is_endpoint_exists(ctx, epnum)) {
errcode = MBED_ERROR_INVPARAM;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
goto err;
}
/* return the recipient status (2 bytes, or wLength if smaller) */
uint8_t resp[2] = { 0 };
/* setting the halt bit */
if (usbctrl_is_endpoint_halted(ctx, epnum)) {
/* EP halted */
resp[0] |= 1;
}
usb_backend_drv_send_data((uint8_t *)&resp, (pkt->wLength >= 2 ? 2 : pkt->wLength), EP0);
usb_backend_drv_ack(0, USB_BACKEND_DRV_EP_DIR_OUT);
/* std req finishes at the oepint rise */
break;
}
case USB_REQ_RECIPIENT_DEVICE: {
if (pkt->wIndex != 0) {
/* says as not specified. We stall. Yet this is not forbidden (errcode=NONE. */
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
}
/* return the recipient status (2 bytes, or wLength if smaller) */
uint8_t resp[2] = { 0 };
/* FIXME: add remoteWakeup and selfPowered field setting to resp */
usb_backend_drv_send_data((uint8_t *)&resp, (pkt->wLength >= 2 ? 2 : pkt->wLength), EP0);
usb_backend_drv_ack(0, USB_BACKEND_DRV_EP_DIR_OUT);
/* std req finishes at the oepint rise */
break;
}
case USB_REQ_RECIPIENT_INTERFACE: {
/*does requested Iface exists ? */
uint8_t ifaceid = pkt->wIndex & 0xf;
if (!usbctrl_is_interface_exists(ctx, ifaceid)) {
errcode = MBED_ERROR_INVPARAM;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
/*request finish here */
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
goto err;
}
/* return the recipient status (2 bytes, all reserved) */
uint8_t resp[2] = { 0 };
usb_backend_drv_send_data((uint8_t *)&resp, (pkt->wLength >= 2 ? 2 : pkt->wLength), EP0);
usb_backend_drv_ack(0, USB_BACKEND_DRV_EP_DIR_OUT);
/* std req finishes at the oepint rise */
break;
}
default:
errcode = MBED_ERROR_INVPARAM;
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
goto err;
}
break;
default:
/* this should never be reached with the is_std_requests_allowed() function */
/*request finish here */
errcode = MBED_ERROR_INVPARAM;
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
break;
}
err:
return errcode;
}
/*@
@ requires \valid(ctx) ;
@ requires \separated(ctx+ (..),pkt,&GHOST_opaque_drv_privates);
@ assigns *ctx, GHOST_opaque_drv_privates ;
@ ensures ctx->ctrl_req_processing == \false ;
@ behavior std_requests_not_allowed:
@ assumes !((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ ensures \result == MBED_ERROR_INVSTATE ;
@ behavior pktvalue_not_null:
@ assumes ((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ assumes (pkt->wValue != 0) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ behavior lenght_not_one:
@ assumes ((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ assumes !(pkt->wValue != 0) ;
@ assumes (pkt->wLength != 1) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ behavior no_interface:
@ assumes ((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ assumes !(pkt->wValue != 0) ;
@ assumes !(pkt->wLength != 1) ;
@ assumes !( (pkt->wIndex & 0x7f) < ctx->cfg[ctx->curr_cfg].interface_num) ;
@ ensures \result == MBED_ERROR_INVPARAM ;
@ behavior interface_ok_USB_DEVICE_STATE_DEFAULT:
@ assumes ((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ assumes !(pkt->wValue != 0) ;
@ assumes !(pkt->wLength != 1) ;
@ assumes ( (pkt->wIndex & 0x7f) < ctx->cfg[ctx->curr_cfg].interface_num) ;
@ assumes ctx->state == USB_DEVICE_STATE_DEFAULT ;
@ ensures \result == MBED_ERROR_NONE ;
@ behavior interface_ok_USB_DEVICE_STATE_ADDRESS:
@ assumes ((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ assumes !(pkt->wValue != 0) ;
@ assumes !(pkt->wLength != 1) ;
@ assumes ( (pkt->wIndex & 0x7f) < ctx->cfg[ctx->curr_cfg].interface_num) ;
@ assumes ctx->state == USB_DEVICE_STATE_ADDRESS ;
@ ensures \result == MBED_ERROR_NONE ;
@ behavior interface_ok_USB_DEVICE_STATE_CONFIGURED:
@ assumes ((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ assumes !(pkt->wValue != 0) ;
@ assumes !(pkt->wLength != 1) ;
@ assumes ( (pkt->wIndex & 0x7f) < ctx->cfg[ctx->curr_cfg].interface_num) ;
@ assumes ctx->state == USB_DEVICE_STATE_CONFIGURED ;
@ ensures \result == MBED_ERROR_NONE ;
@ complete behaviors ;
@ disjoint behaviors ;
*/
#ifndef __FRAMAC__
static
#endif
mbed_error_t usbctrl_std_req_handle_get_interface(usbctrl_setup_pkt_t const * const pkt,
usbctrl_context_t *ctx)
{
/* GET_INTERFACE request is used to request an alternate setting when using
* interfaces in a same configuration that use mutually exclusive settings.
* This is not yet implemented. By now, we stall.
* TODO: we should allows interfaces registration with altSettings information.
* In this very request, we should transmit the Get_interface to the corresponding
* interface target with the requested altSettings value and wait for its EP reconfiguration
* and results.
*/
mbed_error_t errcode = MBED_ERROR_NONE;
log_printf("[USBCTRL] Std req: get iface\n");
if (!is_std_requests_allowed(ctx)) {
/* error handling, invalid state */
errcode = MBED_ERROR_INVSTATE;
goto err;
}
/* handling standard Request, get back needed values */
uint8_t iface_id = (pkt->wIndex & 0x7f);
uint16_t length = pkt->wLength;
if (pkt->wValue != 0) {
/* this field must be set to 0 */
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
errcode = MBED_ERROR_INVPARAM;
}
if (length != 1) {
/* data length *must* be 1. When valid, the device returns the alternate
* setting */
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
errcode = MBED_ERROR_INVPARAM;
goto err;
}
if (usbctrl_is_interface_exists(ctx, iface_id) == false) {
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
errcode = MBED_ERROR_INVPARAM;
goto err;
}
/* let's respond to the request */
switch (usbctrl_get_state(ctx)) {
case USB_DEVICE_STATE_DEFAULT:
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
break;
case USB_DEVICE_STATE_ADDRESS:
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
break;
case USB_DEVICE_STATE_CONFIGURED:
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
break;
default:
/* this should never be reached with the is_std_requests_allowed() function */
usb_backend_drv_stall(EP0, USB_BACKEND_DRV_EP_DIR_IN);
break;
}
err:
set_bool_with_membarrier(&(ctx->ctrl_req_processing), false);
return errcode;
}
/*@
@ requires \valid(ctx) ;
@ requires \separated(ctx+(..),pkt,&GHOST_opaque_drv_privates);
@ assigns *ctx, GHOST_opaque_drv_privates;
// USB 2.0 conformity: chap. 9.4.6
//
@ behavior invalid_pkt_windex:
@ assumes pkt->wIndex != 0;
@ ensures ctx->address == \old(ctx->address);
@ ensures \result == MBED_ERROR_INVPARAM;
@ behavior invalid_pkt_wlength:
@ assumes pkt->wIndex == 0;
@ assumes pkt->wLength != 0;
@ ensures ctx->address == \old(ctx->address);
@ ensures \result == MBED_ERROR_INVPARAM;
@ behavior std_requests_not_allowed:
@ assumes pkt->wIndex == 0;
@ assumes pkt->wLength == 0;
@ assumes !((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ ensures ctx->address == \old(ctx->address);
@ ensures ctx->ctrl_req_processing == false ;
@ ensures \result == MBED_ERROR_INVSTATE ;
@ behavior invalid_addr:
@ assumes pkt->wIndex == 0;
@ assumes pkt->wLength == 0;
@ assumes ((ctx->state == USB_DEVICE_STATE_DEFAULT) ||
(ctx->state == USB_DEVICE_STATE_ADDRESS) ||
(ctx->state == USB_DEVICE_STATE_CONFIGURED)) ;
@ assumes (pkt->wValue & 0xff) > 127;
@ ensures ctx->address == \old(ctx->address);
@ ensures \result == MBED_ERROR_NONE; // not forbidden by USB2.0
@ behavior USB_DEVICE_STATE_DEFAULT_pktValue_not_null:
@ assumes pkt->wIndex == 0;
@ assumes pkt->wLength == 0;
@ assumes (pkt->wValue & 0xff) <= 127;
@ assumes (ctx->state == USB_DEVICE_STATE_DEFAULT) ;
@ assumes ((pkt->wValue & 0xff) != 0) ;
@ ensures ctx->ctrl_req_processing == false ;
@ ensures \result == MBED_ERROR_NONE ;
@ ensures ctx->state == USB_DEVICE_STATE_ADDRESS ;
@ behavior USB_DEVICE_STATE_DEFAULT_pktValue_null:
@ assumes pkt->wIndex == 0;
@ assumes pkt->wLength == 0;
@ assumes (pkt->wValue & 0xff) <= 127;
@ assumes (ctx->state == USB_DEVICE_STATE_DEFAULT) ;
@ assumes !((pkt->wValue & 0xff) != 0) ;
@ ensures ctx->ctrl_req_processing == false ;
@ ensures \result == MBED_ERROR_NONE ;
@ behavior USB_DEVICE_STATE_ADDRESS_pktValue_not_null:
@ assumes pkt->wIndex == 0;
@ assumes pkt->wLength == 0;
@ assumes (pkt->wValue & 0xff) <= 127;
@ assumes (ctx->state == USB_DEVICE_STATE_ADDRESS) ;
@ assumes ((pkt->wValue & 0xff) != 0) ;
@ ensures ctx->ctrl_req_processing == false ;
@ ensures \result == MBED_ERROR_NONE ;