xref: /btstack/src/classic/obex_srm_server.c (revision 50c752545e4437ff5ececf03019a5eaedabe1b28)
1e001955aSMatthias Ringwald /*
2e001955aSMatthias Ringwald  * Copyright (C) 2023 BlueKitchen GmbH
3e001955aSMatthias Ringwald  *
4e001955aSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5e001955aSMatthias Ringwald  * modification, are permitted provided that the following conditions
6e001955aSMatthias Ringwald  * are met:
7e001955aSMatthias Ringwald  *
8e001955aSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9e001955aSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10e001955aSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11e001955aSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12e001955aSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13e001955aSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14e001955aSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15e001955aSMatthias Ringwald  *    from this software without specific prior written permission.
16e001955aSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17e001955aSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18e001955aSMatthias Ringwald  *    monetary gain.
19e001955aSMatthias Ringwald  *
20e001955aSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21e001955aSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22e001955aSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23e001955aSMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24e001955aSMatthias Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25e001955aSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26e001955aSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27e001955aSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28e001955aSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29e001955aSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30e001955aSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31e001955aSMatthias Ringwald  * SUCH DAMAGE.
32e001955aSMatthias Ringwald  *
33e001955aSMatthias Ringwald  * Please inquire about commercial licensing options at
34e001955aSMatthias Ringwald  * [email protected]
35e001955aSMatthias Ringwald  *
36e001955aSMatthias Ringwald  */
37e001955aSMatthias Ringwald 
38e001955aSMatthias Ringwald #define BTSTACK_FILE__ "opp_srm.c"
39e001955aSMatthias Ringwald 
40e001955aSMatthias Ringwald #include "btstack_config.h"
41e001955aSMatthias Ringwald 
42e001955aSMatthias Ringwald #include <stdint.h>
43e001955aSMatthias Ringwald 
44e001955aSMatthias Ringwald #include "btstack_event.h"
45e001955aSMatthias Ringwald 
46e001955aSMatthias Ringwald #include "classic/obex.h"
47e001955aSMatthias Ringwald #include "classic/obex_parser.h"
48e001955aSMatthias Ringwald #include "classic/goep_server.h"
49e001955aSMatthias Ringwald 
50e001955aSMatthias Ringwald #include "classic/obex_srm_server.h"
51e001955aSMatthias Ringwald 
obex_srm_server_init(obex_srm_server_t * obex_srm)5291a1f2a1SMatthias Ringwald void obex_srm_server_init (obex_srm_server_t *obex_srm){
5391a1f2a1SMatthias Ringwald     obex_srm->srm_state = OBEX_SRM_STATE_DISABLED;
54*50c75254SMatthias Ringwald     obex_srm_server_reset_fields(obex_srm);
55*50c75254SMatthias Ringwald }
56*50c75254SMatthias Ringwald 
obex_srm_server_reset_fields(obex_srm_server_t * obex_srm)57*50c75254SMatthias Ringwald void obex_srm_server_reset_fields (obex_srm_server_t *obex_srm){
58e001955aSMatthias Ringwald     obex_srm->srm_value = OBEX_SRM_DISABLE;
59e001955aSMatthias Ringwald     obex_srm->srmp_value = OBEX_SRMP_NEXT;
60e001955aSMatthias Ringwald }
61e001955aSMatthias Ringwald 
obex_srm_server_header_store(obex_srm_server_t * obex_srm,uint8_t header_id,uint16_t total_len,uint16_t data_offset,const uint8_t * data_buffer,uint16_t data_len)620173416cSMatthias Ringwald void obex_srm_server_header_store (obex_srm_server_t    *obex_srm,
63e001955aSMatthias Ringwald                                    uint8_t        header_id,
64e001955aSMatthias Ringwald                                    uint16_t       total_len,
65e001955aSMatthias Ringwald                                    uint16_t       data_offset,
66e001955aSMatthias Ringwald                                    const uint8_t *data_buffer,
67653ef60cSMatthias Ringwald                                    uint16_t       data_len){
68e001955aSMatthias Ringwald     switch (header_id) {
69e001955aSMatthias Ringwald         case OBEX_HEADER_SINGLE_RESPONSE_MODE:
70e001955aSMatthias Ringwald             obex_parser_header_store(&obex_srm->srm_value, 1, total_len, data_offset, data_buffer, data_len);
71e001955aSMatthias Ringwald             break;
72e001955aSMatthias Ringwald         case OBEX_HEADER_SINGLE_RESPONSE_MODE_PARAMETER:
73e001955aSMatthias Ringwald             obex_parser_header_store(&obex_srm->srmp_value, 1, total_len, data_offset, data_buffer, data_len);
74e001955aSMatthias Ringwald             break;
75e001955aSMatthias Ringwald         default:
76e001955aSMatthias Ringwald             break;
77e001955aSMatthias Ringwald     }
78e001955aSMatthias Ringwald }
79e001955aSMatthias Ringwald 
obex_srm_server_handle_headers(obex_srm_server_t * obex_srm)80653ef60cSMatthias Ringwald void obex_srm_server_handle_headers (obex_srm_server_t *obex_srm){
81e001955aSMatthias Ringwald     switch (obex_srm->srm_state) {
82e001955aSMatthias Ringwald         case OBEX_SRM_STATE_DISABLED:
83e001955aSMatthias Ringwald             if (obex_srm->srm_value == OBEX_SRM_ENABLE) {
84e001955aSMatthias Ringwald                 if (obex_srm->srmp_value == OBEX_SRMP_WAIT) {
85e001955aSMatthias Ringwald                     obex_srm->srm_state = OBEX_SRM_STATE_SEND_CONFIRM_WAIT;
86e001955aSMatthias Ringwald                 } else {
87e001955aSMatthias Ringwald                     obex_srm->srm_state = OBEX_SRM_STATE_SEND_CONFIRM;
88e001955aSMatthias Ringwald                 }
89e001955aSMatthias Ringwald             }
90e001955aSMatthias Ringwald             break;
91e001955aSMatthias Ringwald         case OBEX_SRM_STATE_ENABLED_WAIT:
92e001955aSMatthias Ringwald             if (obex_srm->srmp_value == OBEX_SRMP_NEXT) {
93e001955aSMatthias Ringwald                 obex_srm->srm_state = OBEX_SRM_STATE_ENABLED;
94e001955aSMatthias Ringwald             }
95e001955aSMatthias Ringwald             break;
96e001955aSMatthias Ringwald         default:
97e001955aSMatthias Ringwald             break;
98e001955aSMatthias Ringwald     }
99e001955aSMatthias Ringwald }
100e001955aSMatthias Ringwald 
obex_srm_server_add_srm_headers(obex_srm_server_t * obex_srm,uint16_t goep_cid)1010173416cSMatthias Ringwald void obex_srm_server_add_srm_headers (obex_srm_server_t *obex_srm,
102653ef60cSMatthias Ringwald                                       uint16_t    goep_cid){
103e001955aSMatthias Ringwald     switch (obex_srm->srm_state) {
104e001955aSMatthias Ringwald         case OBEX_SRM_STATE_SEND_CONFIRM:
105e001955aSMatthias Ringwald             goep_server_header_add_srm_enable (goep_cid);
106e001955aSMatthias Ringwald             obex_srm->srm_state = OBEX_SRM_STATE_ENABLED;
107e001955aSMatthias Ringwald             break;
108e001955aSMatthias Ringwald         case OBEX_SRM_STATE_SEND_CONFIRM_WAIT:
109e001955aSMatthias Ringwald             goep_server_header_add_srm_enable (goep_cid);
110e001955aSMatthias Ringwald             obex_srm->srm_state = OBEX_SRM_STATE_ENABLED_WAIT;
111e001955aSMatthias Ringwald             break;
112e001955aSMatthias Ringwald         default:
113e001955aSMatthias Ringwald             break;
114e001955aSMatthias Ringwald     }
115e001955aSMatthias Ringwald }
116e001955aSMatthias Ringwald 
obex_srm_server_is_srm_active(obex_srm_server_t * obex_srm)117*50c75254SMatthias Ringwald bool obex_srm_server_is_srm_active (obex_srm_server_t *obex_srm){
118e001955aSMatthias Ringwald     return obex_srm->srm_state == OBEX_SRM_STATE_ENABLED;
119e001955aSMatthias Ringwald }
120e001955aSMatthias Ringwald 
121