xref: /btstack/src/classic/obex_srm_client.c (revision 5fe900187d6325880f9c42e3d83d3ccf899c0906)
1*5fe90018SMatthias Ringwald /*
2*5fe90018SMatthias Ringwald  * Copyright (C) 2024 BlueKitchen GmbH
3*5fe90018SMatthias Ringwald  *
4*5fe90018SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5*5fe90018SMatthias Ringwald  * modification, are permitted provided that the following conditions
6*5fe90018SMatthias Ringwald  * are met:
7*5fe90018SMatthias Ringwald  *
8*5fe90018SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9*5fe90018SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10*5fe90018SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11*5fe90018SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12*5fe90018SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13*5fe90018SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14*5fe90018SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15*5fe90018SMatthias Ringwald  *    from this software without specific prior written permission.
16*5fe90018SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17*5fe90018SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18*5fe90018SMatthias Ringwald  *    monetary gain.
19*5fe90018SMatthias Ringwald  *
20*5fe90018SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21*5fe90018SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*5fe90018SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*5fe90018SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24*5fe90018SMatthias Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*5fe90018SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*5fe90018SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27*5fe90018SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*5fe90018SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*5fe90018SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30*5fe90018SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*5fe90018SMatthias Ringwald  * SUCH DAMAGE.
32*5fe90018SMatthias Ringwald  *
33*5fe90018SMatthias Ringwald  * Please inquire about commercial licensing options at
34*5fe90018SMatthias Ringwald  * [email protected]
35*5fe90018SMatthias Ringwald  *
36*5fe90018SMatthias Ringwald  */
37*5fe90018SMatthias Ringwald 
38*5fe90018SMatthias Ringwald #define BTSTACK_FILE__ "opp_srm_client.c"
39*5fe90018SMatthias Ringwald 
40*5fe90018SMatthias Ringwald #include "btstack_debug.h"
41*5fe90018SMatthias Ringwald 
42*5fe90018SMatthias Ringwald #include "classic/goep_client.h"
43*5fe90018SMatthias Ringwald #include "classic/obex.h"
44*5fe90018SMatthias Ringwald #include "classic/obex_srm_client.h"
45*5fe90018SMatthias Ringwald 
46*5fe90018SMatthias Ringwald void obex_srm_client_init(obex_srm_client_t * obex_srm){
47*5fe90018SMatthias Ringwald     obex_srm->srm_state = OBEX_SRM_CLIENT_STATE_DISABLED;
48*5fe90018SMatthias Ringwald     obex_srm->srm_value = OBEX_SRM_DISABLE;
49*5fe90018SMatthias Ringwald     obex_srm->srmp_value = OBEX_SRMP_NEXT;
50*5fe90018SMatthias Ringwald }
51*5fe90018SMatthias Ringwald 
52*5fe90018SMatthias Ringwald void obex_srm_client_handle_headers(obex_srm_client_t *obex_srm) {
53*5fe90018SMatthias Ringwald     // Update SRM state based on SRM headers
54*5fe90018SMatthias Ringwald     switch (obex_srm->srm_state){
55*5fe90018SMatthias Ringwald         case OBEX_SRM_CLIENT_STATE_W4_CONFIRM:
56*5fe90018SMatthias Ringwald             switch (obex_srm->srm_value){
57*5fe90018SMatthias Ringwald                 case OBEX_SRM_ENABLE:
58*5fe90018SMatthias Ringwald                     switch (obex_srm->srmp_value){
59*5fe90018SMatthias Ringwald                         case OBEX_SRMP_WAIT:
60*5fe90018SMatthias Ringwald                             obex_srm->srm_state = OBEX_SRM_CLIENT_STATE_ENABLED_BUT_WAITING;
61*5fe90018SMatthias Ringwald                             break;
62*5fe90018SMatthias Ringwald                         default:
63*5fe90018SMatthias Ringwald                             obex_srm->srm_state = OBEX_SRM_CLIENT_STATE_ENABLED;
64*5fe90018SMatthias Ringwald                             break;
65*5fe90018SMatthias Ringwald                     }
66*5fe90018SMatthias Ringwald                     break;
67*5fe90018SMatthias Ringwald                 default:
68*5fe90018SMatthias Ringwald                     obex_srm->srm_state = OBEX_SRM_CLIENT_STATE_DISABLED;
69*5fe90018SMatthias Ringwald                     break;
70*5fe90018SMatthias Ringwald             }
71*5fe90018SMatthias Ringwald             break;
72*5fe90018SMatthias Ringwald         case OBEX_SRM_CLIENT_STATE_ENABLED_BUT_WAITING:
73*5fe90018SMatthias Ringwald             switch (obex_srm->srmp_value){
74*5fe90018SMatthias Ringwald                 case OBEX_SRMP_WAIT:
75*5fe90018SMatthias Ringwald                     obex_srm->srm_state =OBEX_SRM_CLIENT_STATE_ENABLED_BUT_WAITING;
76*5fe90018SMatthias Ringwald                     break;
77*5fe90018SMatthias Ringwald                 default:
78*5fe90018SMatthias Ringwald                     obex_srm->srm_state = OBEX_SRM_CLIENT_STATE_ENABLED;
79*5fe90018SMatthias Ringwald                     break;
80*5fe90018SMatthias Ringwald             }
81*5fe90018SMatthias Ringwald             break;
82*5fe90018SMatthias Ringwald         default:
83*5fe90018SMatthias Ringwald             break;
84*5fe90018SMatthias Ringwald     }
85*5fe90018SMatthias Ringwald     log_info("SRM state %u", obex_srm->srm_state);
86*5fe90018SMatthias Ringwald }
87*5fe90018SMatthias Ringwald 
88*5fe90018SMatthias Ringwald void obex_srm_client_prepare_header(obex_srm_client_t *obex_srm, uint16_t goep_cid){
89*5fe90018SMatthias Ringwald     if (goep_client_version_20_or_higher(goep_cid)){
90*5fe90018SMatthias Ringwald         goep_client_header_add_srm_enable(goep_cid);
91*5fe90018SMatthias Ringwald         obex_srm->srm_state = OBEX_SRM_CLIENT_STATE_W4_CONFIRM;
92*5fe90018SMatthias Ringwald     }
93*5fe90018SMatthias Ringwald }
94