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