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 5291a1f2a1SMatthias Ringwald void obex_srm_server_init (obex_srm_server_t *obex_srm){ 5391a1f2a1SMatthias Ringwald obex_srm->srm_state = OBEX_SRM_STATE_DISABLED; 54e001955aSMatthias Ringwald obex_srm->srm_value = OBEX_SRM_DISABLE; 55e001955aSMatthias Ringwald obex_srm->srmp_value = OBEX_SRMP_NEXT; 56e001955aSMatthias Ringwald } 57e001955aSMatthias Ringwald 580173416cSMatthias Ringwald void obex_srm_server_header_store (obex_srm_server_t *obex_srm, 59e001955aSMatthias Ringwald uint8_t header_id, 60e001955aSMatthias Ringwald uint16_t total_len, 61e001955aSMatthias Ringwald uint16_t data_offset, 62e001955aSMatthias Ringwald const uint8_t *data_buffer, 63*653ef60cSMatthias Ringwald uint16_t data_len){ 64e001955aSMatthias Ringwald switch (header_id) { 65e001955aSMatthias Ringwald case OBEX_HEADER_SINGLE_RESPONSE_MODE: 66e001955aSMatthias Ringwald obex_parser_header_store(&obex_srm->srm_value, 1, total_len, data_offset, data_buffer, data_len); 67e001955aSMatthias Ringwald break; 68e001955aSMatthias Ringwald case OBEX_HEADER_SINGLE_RESPONSE_MODE_PARAMETER: 69e001955aSMatthias Ringwald obex_parser_header_store(&obex_srm->srmp_value, 1, total_len, data_offset, data_buffer, data_len); 70e001955aSMatthias Ringwald break; 71e001955aSMatthias Ringwald default: 72e001955aSMatthias Ringwald break; 73e001955aSMatthias Ringwald } 74e001955aSMatthias Ringwald } 75e001955aSMatthias Ringwald 76*653ef60cSMatthias Ringwald void obex_srm_server_handle_headers (obex_srm_server_t *obex_srm){ 77e001955aSMatthias Ringwald switch (obex_srm->srm_state) { 78e001955aSMatthias Ringwald case OBEX_SRM_STATE_DISABLED: 79e001955aSMatthias Ringwald if (obex_srm->srm_value == OBEX_SRM_ENABLE) { 80e001955aSMatthias Ringwald if (obex_srm->srmp_value == OBEX_SRMP_WAIT) { 81e001955aSMatthias Ringwald obex_srm->srm_state = OBEX_SRM_STATE_SEND_CONFIRM_WAIT; 82e001955aSMatthias Ringwald } else { 83e001955aSMatthias Ringwald obex_srm->srm_state = OBEX_SRM_STATE_SEND_CONFIRM; 84e001955aSMatthias Ringwald } 85e001955aSMatthias Ringwald } 86e001955aSMatthias Ringwald break; 87e001955aSMatthias Ringwald case OBEX_SRM_STATE_ENABLED_WAIT: 88e001955aSMatthias Ringwald if (obex_srm->srmp_value == OBEX_SRMP_NEXT) { 89e001955aSMatthias Ringwald obex_srm->srm_state = OBEX_SRM_STATE_ENABLED; 90e001955aSMatthias Ringwald } 91e001955aSMatthias Ringwald break; 92e001955aSMatthias Ringwald default: 93e001955aSMatthias Ringwald break; 94e001955aSMatthias Ringwald } 95e001955aSMatthias Ringwald } 96e001955aSMatthias Ringwald 970173416cSMatthias Ringwald void obex_srm_server_add_srm_headers (obex_srm_server_t *obex_srm, 98*653ef60cSMatthias Ringwald uint16_t goep_cid){ 99e001955aSMatthias Ringwald switch (obex_srm->srm_state) { 100e001955aSMatthias Ringwald case OBEX_SRM_STATE_SEND_CONFIRM: 101e001955aSMatthias Ringwald goep_server_header_add_srm_enable (goep_cid); 102e001955aSMatthias Ringwald obex_srm->srm_state = OBEX_SRM_STATE_ENABLED; 103e001955aSMatthias Ringwald break; 104e001955aSMatthias Ringwald case OBEX_SRM_STATE_SEND_CONFIRM_WAIT: 105e001955aSMatthias Ringwald goep_server_header_add_srm_enable (goep_cid); 106e001955aSMatthias Ringwald obex_srm->srm_state = OBEX_SRM_STATE_ENABLED_WAIT; 107e001955aSMatthias Ringwald break; 108e001955aSMatthias Ringwald default: 109e001955aSMatthias Ringwald break; 110e001955aSMatthias Ringwald } 111e001955aSMatthias Ringwald } 112e001955aSMatthias Ringwald 113*653ef60cSMatthias Ringwald bool obex_srm_server_is_enabled (obex_srm_server_t *obex_srm){ 114e001955aSMatthias Ringwald return obex_srm->srm_state == OBEX_SRM_STATE_ENABLED; 115e001955aSMatthias Ringwald } 116e001955aSMatthias Ringwald 117