diff options
author | Srikanth Uppala <suppala@broadcom.com> | 2012-06-17 21:44:48 -0700 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:23 -0700 |
commit | 1144d2b375fc67c9b48298e0ffd774d969cfd2cc (patch) | |
tree | 4d36d4f8be4942d769300c242caeb9b9096c6a35 /stack | |
parent | fed66f7b66d29da466e2e67befe3238e7ed8fc6a (diff) | |
download | external_bluetooth_bluedroid-1144d2b375fc67c9b48298e0ffd774d969cfd2cc.zip external_bluetooth_bluedroid-1144d2b375fc67c9b48298e0ffd774d969cfd2cc.tar.gz external_bluetooth_bluedroid-1144d2b375fc67c9b48298e0ffd774d969cfd2cc.tar.bz2 |
resubmit code-cleanup changes lost in gerrit merge
Change-Id: Iebc520d9b10ef220a83a16ff55efa46b4c5a0d27
Diffstat (limited to 'stack')
69 files changed, 1 insertions, 29690 deletions
diff --git a/stack/Android.mk b/stack/Android.mk index 0d7a17e..d2ccaff 100644 --- a/stack/Android.mk +++ b/stack/Android.mk @@ -13,16 +13,11 @@ LOCAL_C_INCLUDES:= . \ $(LOCAL_PATH)/avdt \ $(LOCAL_PATH)/gatt \ $(LOCAL_PATH)/gap \ - $(LOCAL_PATH)/bip \ $(LOCAL_PATH)/pan \ - $(LOCAL_PATH)/bpp \ $(LOCAL_PATH)/bnep \ $(LOCAL_PATH)/hid \ - $(LOCAL_PATH)/obx \ $(LOCAL_PATH)/sdp \ $(LOCAL_PATH)/smp \ - $(LOCAL_PATH)/amp \ - $(LOCAL_PATH)/amp/security \ $(LOCAL_PATH)/../include \ $(LOCAL_PATH)/../gki/common \ $(LOCAL_PATH)/../gki/ulinux \ @@ -41,25 +36,13 @@ endif LOCAL_PRELINK_MODULE:=false LOCAL_SRC_FILES:= \ - ./dun/dun_api.c \ ./a2dp/a2d_api.c \ - ./a2dp/a2d_m24.c \ - ./a2dp/a2d_m12.c \ ./a2dp/a2d_sbc.c \ - ./avrc/avrc_bld_tg.c \ ./avrc/avrc_api.c \ - ./avrc/avrc_utils.c \ - ./avrc/avrc_pars_ct.c \ ./avrc/avrc_sdp.c \ - ./avrc/avrc_pars_tg.c \ - ./avrc/avrc_bld_ct.c \ ./avrc/avrc_opt.c \ - ./hid/hidd_conn.c \ - ./hid/hidd_mgmt.c \ ./hid/hidh_api.c \ - ./hid/hidd_pm.c \ ./hid/hidh_conn.c \ - ./hid/hidd_api.c \ ./bnep/bnep_main.c \ ./bnep/bnep_utils.c \ ./bnep/bnep_api.c \ @@ -102,33 +85,6 @@ LOCAL_SRC_FILES:= \ ./gatt/att_protocol.c \ ./gatt/gatt_attr.c \ ./gatt/gatt_db.c \ - ./obx/hdrs/obx_dutf.c \ - ./obx/hdrs/obx_dwchar.c \ - ./obx/hdrs/obx_gen.c \ - ./obx/hdrs/obx_dunic.c \ - ./obx/hdrs/utfc.c \ - ./obx/hdrs/obx_dbtp.c \ - ./obx/hdrs/obx_dauth.c \ - ./obx/hdrs/obx_ebtp.c \ - ./obx/hdrs/obx_wchar.c \ - ./obx/hdrs/obx_eunic.c \ - ./obx/hdrs/obx_eopt.c \ - ./obx/hdrs/obx_dopt.c \ - ./obx/hdrs/obx_ewchar.c \ - ./obx/hdrs/obx_eutf.c \ - ./obx/obx_csm.c \ - ./obx/obx_ssm.c \ - ./obx/obx_cact.c \ - ./obx/obx_md5.c \ - ./obx/obx_rfc.c \ - ./obx/obx_main.c \ - ./obx/obx_sapi.c \ - ./obx/obx_l2c.c \ - ./obx/obx_sact.c \ - ./obx/obx_utils.c \ - ./obx/obx_capi.c \ - ./avct/avct_bcb_act.c \ - ./avct/avct_l2c_br.c \ ./avct/avct_api.c \ ./avct/avct_l2c.c \ ./avct/avct_lcb.c \ @@ -156,12 +112,6 @@ LOCAL_SRC_FILES:= \ ./sdp/sdp_utils.c \ ./sdp/sdp_api.c \ ./sdp/sdp_discovery.c \ - ./xml/xml_parse.c \ - ./xml/xml_vlist.c \ - ./xml/xml_erp.c \ - ./xml/xml_flp.c \ - ./xml/xml_mlp.c \ - ./xml/xml_bld.c \ ./pan/pan_main.c \ ./pan/pan_api.c \ ./pan/pan_utils.c \ @@ -175,10 +125,7 @@ LOCAL_SRC_FILES:= \ ./l2cap/l2c_utils.c \ ./l2cap/l2c_csm.c \ ./l2cap/l2c_link.c \ - ./l2cap/l2c_ble.c \ - ./goep/goep_fs.c \ - ./goep/goep_trace.c \ - ./goep/goep_util.c + ./l2cap/l2c_ble.c LOCAL_MODULE := libbt-brcm_stack LOCAL_MODULE_TAGS := optional diff --git a/stack/a2dp/a2d_m12.c b/stack/a2dp/a2d_m12.c deleted file mode 100644 index 3c9fb98..0000000 --- a/stack/a2dp/a2d_m12.c +++ /dev/null @@ -1,141 +0,0 @@ -/***************************************************************************** -** -** Name: a2d_m12.c -** -** Description:utility functions to help build and parse MPEG-1, 2 Audio -** Codec Information Element and Media Payload. -** Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" - -#if (A2D_M12_INCLUDED == TRUE) -#include "a2d_api.h" -#include "a2d_int.h" -#include "a2d_m12.h" - - -/****************************************************************************** -** -** Function A2D_BldM12Info -** -** Description This function is called by an application to build -** the MPEG-1, 2 Audio Media Codec Capabilities byte sequence -** beginning from the LOSC octet. -** media_type: Indicates Audio, or Multimedia. -** -** p_ie: The MPEG-1, 2 Audio Codec Information Element information. -** -** Output Parameters: -** p_result: the resulting codec info byte sequence. -** -** Returns A2D_SUCCESS if function execution succeeded. -** Error status code, otherwise. -******************************************************************************/ -tA2D_STATUS A2D_BldM12Info(UINT8 media_type, tA2D_M12_CIE *p_ie, UINT8 *p_result) -{ - tA2D_STATUS status; - UINT8 *p_vbr; - - if( p_ie == NULL || p_result == NULL || - (p_ie->layer & ~A2D_M12_IE_LAYER_MSK) || - (p_ie->ch_mode & ~A2D_M12_IE_CH_MD_MSK) || - (p_ie->samp_freq & ~A2D_M12_IE_SAMP_FREQ_MSK) || - (p_ie->bitrate & ~A2D_M12_IE_BITRATE_MSK)) - { - /* if any unused bit is set */ - status = A2D_INVALID_PARAMS; - } - else - { - status = A2D_SUCCESS; - *p_result++ = A2D_M12_INFO_LEN; - *p_result++ = media_type; - *p_result++ = A2D_MEDIA_CT_M12; - - /* Media Codec Specific Information Element */ - *p_result = p_ie->layer | p_ie->ch_mode; - if(p_ie->crc) - *p_result |= A2D_M12_IE_CRC_MSK; - p_result++; - - *p_result = p_ie->samp_freq; - if(p_ie->mpf) - *p_result |= A2D_M12_IE_MPF_MSK; - p_result++; - - p_vbr = p_result; - UINT16_TO_BE_STREAM(p_result, p_ie->bitrate); - if(p_ie->vbr) - *p_vbr |= A2D_M12_IE_VBR_MSK; - } - return status; -} - -/****************************************************************************** -** -** Function A2D_ParsM12Info -** -** Description This function is called by an application to parse -** the MPEG-1, 2 Audio Media Codec Capabilities byte sequence -** beginning from the LOSC octet. -** Input Parameters: -** p_info: the byte sequence to parse. -** -** for_caps: TRUE, if the byte sequence is for get capabilities response. -** -** Output Parameters: -** p_ie: The MPEG-1, 2 Audio Codec Information Element information. -** -** Returns A2D_SUCCESS if function execution succeeded. -** Error status code, otherwise. -******************************************************************************/ -tA2D_STATUS A2D_ParsM12Info(tA2D_M12_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps) -{ - tA2D_STATUS status; - UINT8 losc; - UINT8 mt; - - if( p_ie == NULL || p_info == NULL) - status = A2D_INVALID_PARAMS; - else - { - losc = *p_info++; - mt = *p_info++; - /* If the function is called for the wrong Media Type or Media Codec Type */ - if(losc != A2D_M12_INFO_LEN || *p_info != A2D_MEDIA_CT_M12) - status = A2D_WRONG_CODEC; - else - { - p_info++; - p_ie->layer = *p_info & A2D_M12_IE_LAYER_MSK; - p_ie->crc = (*p_info & A2D_M12_IE_CRC_MSK) >> 4; - p_ie->ch_mode = *p_info & A2D_M12_IE_CH_MD_MSK; - p_info++; - p_ie->mpf = (*p_info & A2D_M12_IE_MPF_MSK) >> 6; - p_ie->samp_freq = *p_info & A2D_M12_IE_SAMP_FREQ_MSK; - p_info++; - p_ie->vbr = (*p_info & A2D_M12_IE_VBR_MSK) >> 7; - BE_STREAM_TO_UINT16(p_ie->bitrate, p_info); - p_ie->bitrate &= A2D_M12_IE_BITRATE_MSK; - - status = A2D_SUCCESS; - if(for_caps == FALSE) - { - if(A2D_BitsSet(p_ie->layer) != A2D_SET_ONE_BIT) - status = A2D_BAD_LAYER; - if(A2D_BitsSet(p_ie->ch_mode) != A2D_SET_ONE_BIT) - status = A2D_BAD_CH_MODE; - if(A2D_BitsSet(p_ie->samp_freq) != A2D_SET_ONE_BIT) - status = A2D_BAD_SAMP_FREQ; - if((A2D_BitsSet((UINT8)(p_ie->bitrate&0xFF)) + - A2D_BitsSet((UINT8)((p_ie->bitrate&0xFF00)>>8)))!= A2D_SET_ONE_BIT) - status = A2D_BAD_BIT_RATE; - } - } - } - return status; -} - -#endif /* A2D_M12_INCLUDED == TRUE */ diff --git a/stack/a2dp/a2d_m24.c b/stack/a2dp/a2d_m24.c deleted file mode 100644 index d8df766..0000000 --- a/stack/a2dp/a2d_m24.c +++ /dev/null @@ -1,149 +0,0 @@ -/***************************************************************************** -** -** Name: a2d_m24.c -** -** Description:utility functions to help build and parse MPEG-2, 4 AAC -** Codec Information Element and Media Payload. -** Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include "bt_target.h" - -#if (A2D_M24_INCLUDED == TRUE) -#include "a2d_api.h" -#include "a2d_int.h" -#include "a2d_m24.h" - - -/****************************************************************************** -** -** Function A2D_BldM24Info -** -** Description This function is called by an application to build -** the MPEG-2, 4 AAC Media Codec Capabilities byte sequence -** beginning from the LOSC octet. -** Input Parameters: -** media_type: Indicates Audio, or Multimedia. -** -** p_ie: MPEG-2, 4 AAC Codec Information Element information. -** -** Output Parameters: -** p_result: the resulting codec info byte sequence. -** -** Returns A2D_SUCCESS if function execution succeeded. -** Error status code, otherwise. -******************************************************************************/ -tA2D_STATUS A2D_BldM24Info(UINT8 media_type, tA2D_M24_CIE *p_ie, UINT8 *p_result) -{ - tA2D_STATUS status; - UINT16 bitrate45; - - if( p_ie == NULL || p_result == NULL || - (p_ie->obj_type & ~A2D_M24_IE_OBJ_MSK) || - (p_ie->samp_freq & ~A2D_M24_IE_SAMP_FREQ_MSK) || - (p_ie->chnl & ~A2D_M24_IE_CHNL_MSK) || - (p_ie->bitrate & ~A2D_M24_IE_BITRATE_MSK)) - { - /* if any unused bit is set */ - status = A2D_INVALID_PARAMS; - } - else - { - status = A2D_SUCCESS; - *p_result++ = A2D_M24_INFO_LEN; - *p_result++ = media_type; - *p_result++ = A2D_MEDIA_CT_M24; - - /* Media Codec Specific Information Element */ - *p_result++ = p_ie->obj_type; - - UINT16_TO_BE_STREAM(p_result, p_ie->samp_freq); - p_result--; - *p_result++ |= p_ie->chnl; - - *p_result = (p_ie->bitrate & A2D_M24_IE_BITRATE3_MSK) >> 16; - if(p_ie->vbr) - *p_result |= A2D_M24_IE_VBR_MSK; - p_result++; - bitrate45 = (UINT16)(p_ie->bitrate & A2D_M24_IE_BITRATE45_MSK); - UINT16_TO_BE_STREAM(p_result, bitrate45); - } - return status; -} - -/****************************************************************************** -** -** Function A2D_ParsM24Info -** -** Description This function is called by an application to parse -** the MPEG-2, 4 AAC Media Codec Capabilities byte sequence -** beginning from the LOSC octet. -** Input Parameters: -** p_info: the byte sequence to parse. -** -** for_caps: TRUE, if the byte sequence is for get capabilities response. -** -** Output Parameters: -** p_ie: MPEG-2, 4 AAC Codec Information Element information. -** -** Returns A2D_SUCCESS if function execution succeeded. -** Error status code, otherwise. -******************************************************************************/ -tA2D_STATUS A2D_ParsM24Info(tA2D_M24_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps) -{ - tA2D_STATUS status; - UINT8 vbr; - UINT16 u16; - UINT8 losc; - UINT8 mt; - - if( p_ie == NULL || p_info == NULL) - status = A2D_INVALID_PARAMS; - else - { - losc = *p_info++; - mt = *p_info++; - /* If the function is called for the wrong Media Type or Media Codec Type */ - if(losc != A2D_M24_INFO_LEN || *p_info != A2D_MEDIA_CT_M24) - status = A2D_WRONG_CODEC; - else - { - p_info++; - p_ie->obj_type = *p_info++; - BE_STREAM_TO_UINT16(p_ie->samp_freq, p_info); - p_ie->chnl = p_ie->samp_freq & A2D_M24_IE_CHNL_MSK; - p_ie->samp_freq &= A2D_M24_IE_SAMP_FREQ_MSK; - vbr = *p_info++; - BE_STREAM_TO_UINT16(u16, p_info); /* u16 contains the octect4, 5 of bterate */ - - p_ie->vbr = (vbr & A2D_M24_IE_VBR_MSK) >> 7; - vbr &= ~A2D_M24_IE_VBR_MSK; /* vbr has become the octect3 of bitrate */ - p_ie->bitrate = vbr; - p_ie->bitrate <<= 16; - p_ie->bitrate += u16; - - status = A2D_SUCCESS; - if(for_caps == FALSE) - { - if(A2D_BitsSet(p_ie->obj_type) != A2D_SET_ONE_BIT) - status = A2D_BAD_OBJ_TYPE; - - if((A2D_BitsSet((UINT8)(p_ie->samp_freq&0xFF)) + - A2D_BitsSet((UINT8)((p_ie->samp_freq&0xFF00)>>8)))!= A2D_SET_ONE_BIT) - status = A2D_BAD_SAMP_FREQ; - - if(A2D_BitsSet(p_ie->chnl) != A2D_SET_ONE_BIT) - status = A2D_BAD_CHANNEL; - - /* BitRate must be greater than zero when specifying AAC configuration */ - if (p_ie->bitrate == 0) - status = A2D_BAD_BIT_RATE; - } - } - } - return status; -} -#endif /* (A2D_M24_INCLUDED == TRUE) */ - diff --git a/stack/avct/avct_bcb_act.c b/stack/avct/avct_bcb_act.c deleted file mode 100644 index ad6d651..0000000 --- a/stack/avct/avct_bcb_act.c +++ /dev/null @@ -1,749 +0,0 @@ -/***************************************************************************** -** -** Name: avct_bcb_act.c -** -** Description: This module contains action functions of the browsing control -** state machine. -** -** Copyright (c) 2003-2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> -#include "data_types.h" -#include "bt_target.h" -#include "avct_api.h" -#include "avct_int.h" -#include "gki.h" - - -#include "btm_api.h" - -#if (AVCT_BROWSE_INCLUDED == TRUE) -/* action function list */ -const tAVCT_BCB_ACTION avct_bcb_action[] = { - avct_bcb_chnl_open, /* AVCT_LCB_CHNL_OPEN */ - avct_bcb_chnl_disc, /* AVCT_LCB_CHNL_DISC */ - avct_bcb_send_msg, /* AVCT_LCB_SEND_MSG */ - avct_bcb_open_ind, /* AVCT_LCB_OPEN_IND */ - avct_bcb_open_fail, /* AVCT_LCB_OPEN_FAIL */ - avct_bcb_close_ind, /* AVCT_LCB_CLOSE_IND */ - avct_bcb_close_cfm, /* AVCT_LCB_CLOSE_CFM */ - avct_bcb_msg_ind, /* AVCT_LCB_MSG_IND */ - avct_bcb_cong_ind, /* AVCT_LCB_CONG_IND */ - avct_bcb_bind_conn, /* AVCT_LCB_BIND_CONN */ - avct_bcb_bind_fail, /* AVCT_LCB_BIND_FAIL */ - avct_bcb_unbind_disc, /* AVCT_LCB_UNBIND_DISC */ - avct_bcb_chk_disc, /* AVCT_LCB_CHK_DISC */ - avct_bcb_discard_msg, /* AVCT_LCB_DISCARD_MSG */ - avct_bcb_dealloc, /* AVCT_LCB_DEALLOC */ - avct_bcb_free_msg_ind /* AVCT_LCB_FREE_MSG_IND */ -}; - - -/******************************************************************************* -** -** Function avct_bcb_msg_asmbl -** -** Description Reassemble incoming message. -** -** -** Returns Pointer to reassembled message; NULL if no message -** available. -** -*******************************************************************************/ -static BT_HDR *avct_bcb_msg_asmbl(tAVCT_BCB *p_bcb, BT_HDR *p_buf) -{ - UINT8 *p; - UINT8 pkt_type; - BT_HDR *p_ret = NULL; - - /* parse the message header */ - p = (UINT8 *)(p_buf + 1) + p_buf->offset; - AVCT_PRS_PKT_TYPE(p, pkt_type); - - /* must be single packet - can not fragment */ - if (pkt_type == AVCT_PKT_TYPE_SINGLE) - { - p_ret = p_buf; - } - else - { - GKI_freebuf(p_buf); - AVCT_TRACE_WARNING1("Pkt type=%d - fragmentation not allowed. drop it", pkt_type); - } - return p_ret; -} - - -/******************************************************************************* -** -** Function avct_bcb_chnl_open -** -** Description Open L2CAP channel to peer -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_chnl_open(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - UINT16 result = AVCT_RESULT_FAIL; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - tL2CAP_ERTM_INFO ertm_info; - - BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP_BROWSE, 0); - - /* Set the FCR options: Browsing channel mandates ERTM */ - ertm_info.preferred_mode = avct_l2c_br_fcr_opts_def.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_pool_id = AVCT_BR_USER_RX_POOL_ID; - ertm_info.user_tx_pool_id = AVCT_BR_USER_TX_POOL_ID; - ertm_info.fcr_rx_pool_id = AVCT_BR_FCR_RX_POOL_ID; - ertm_info.fcr_tx_pool_id = AVCT_BR_FCR_TX_POOL_ID; - - /* call l2cap connect req */ - p_bcb->ch_state = AVCT_CH_CONN; - if ((p_bcb->ch_lcid = L2CA_ErtmConnectReq(AVCT_BR_PSM, p_lcb->peer_addr, &ertm_info)) == 0) - { - /* if connect req failed, send ourselves close event */ - avct_bcb_event(p_bcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } -} - -/******************************************************************************* -** -** Function avct_bcb_unbind_disc -** -** Description call callback with disconnect event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_unbind_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - p_data->p_ccb->p_bcb = NULL; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), AVCT_BROWSE_DISCONN_CFM_EVT, 0, NULL); -} - -/******************************************************************************* -** -** Function avct_bcb_open_ind -** -** Description Handle an LL_OPEN event. For each allocated ccb already -** bound to this lcb, send a connect event. For each -** unbound ccb with a new PID, bind that ccb to this lcb and -** send a connect event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_open_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - tAVCT_CCB *p_ccb_bind = NULL; - int i; - BOOLEAN bind = FALSE; - tAVCT_UL_MSG ul_msg; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - /* if ccb allocated and */ - if (p_ccb->allocated) - { - /* if bound to this lcb send connect confirm event */ - if (p_ccb->p_bcb == p_bcb) - { - bind = TRUE; - p_ccb_bind = p_ccb; - p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_CONN_CFM_EVT, - 0, p_ccb->p_lcb->peer_addr); - } - /* if unbound acceptor and lcb e */ - else if ((p_ccb->p_bcb == NULL) && (p_ccb->cc.role == AVCT_ACP) && - (p_ccb->p_lcb != NULL)) - { - /* bind ccb to lcb and send connect ind event */ - bind = TRUE; - p_ccb_bind = p_ccb; - p_ccb->p_bcb = p_bcb; - p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_CONN_IND_EVT, - 0, p_ccb->p_lcb->peer_addr); - } - } - } - - /* if no ccbs bound to this lcb, disconnect */ - if (bind == FALSE) - { - avct_bcb_event(p_bcb, AVCT_LCB_INT_CLOSE_EVT, p_data); - } - else if (p_bcb->p_tx_msg) - { - if (p_ccb_bind) - { - ul_msg.p_buf = p_bcb->p_tx_msg; - ul_msg.p_ccb = p_ccb_bind; - ul_msg.label = (UINT8)(p_bcb->p_tx_msg->layer_specific & 0xFF); - ul_msg.cr = (UINT8)((p_bcb->p_tx_msg->layer_specific & 0xFF00) >> 8); - p_bcb->p_tx_msg->layer_specific = AVCT_DATA_BROWSE; - p_bcb->p_tx_msg = NULL; - - /* send msg event to bcb */ - avct_bcb_event(p_bcb, AVCT_LCB_UL_MSG_EVT, (tAVCT_LCB_EVT *) &ul_msg); - } - else - { - GKI_freebuf (p_bcb->p_tx_msg); - p_bcb->p_tx_msg = NULL; - } - - } -} - -/******************************************************************************* -** -** Function avct_bcb_open_fail -** -** Description L2CAP channel open attempt failed. Mark the ccbs -** as NULL bcb. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_open_fail(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - p_ccb->p_bcb = NULL; - } - } -} - -/******************************************************************************* -** -** Function avct_bcb_close_ind -** -** Description L2CAP channel closed by peer. Deallocate any initiator -** ccbs on this lcb and send disconnect ind event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_close_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - int i; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - if (p_ccb->cc.role == AVCT_INT) - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_DISCONN_CFM_EVT, 0, p_lcb->peer_addr); - } - else - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_DISCONN_IND_EVT, 0, NULL); - } - p_ccb->p_bcb = NULL; - } - } -} - -/******************************************************************************* -** -** Function avct_bcb_close_cfm -** -** Description L2CAP channel closed by us. Deallocate any initiator -** ccbs on this lcb and send disconnect ind or cfm event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_close_cfm(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - UINT8 event = 0; - BOOLEAN ch_close = p_bcb->ch_close; /* Whether BCB initiated channel close */ - tAVCT_CTRL_CBACK *p_cback; - - p_bcb->ch_close = FALSE; - p_bcb->allocated = 0; - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - /* if this ccb initiated close send disconnect cfm otherwise ind */ - if (ch_close) - { - event = AVCT_BROWSE_DISCONN_CFM_EVT; - } - else - { - event = AVCT_BROWSE_DISCONN_IND_EVT; - } - - p_cback = p_ccb->cc.p_ctrl_cback; - p_ccb->p_bcb = NULL; - if (p_ccb->p_lcb == NULL) - avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); - (*p_cback)(avct_ccb_to_idx(p_ccb), event, - p_data->result, NULL); - } - } -} - -/******************************************************************************* -** -** Function avct_bcb_bind_conn -** -** Description Bind ccb to lcb and send connect cfm event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_bind_conn(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - p_data->p_ccb->p_bcb = p_bcb; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), - AVCT_BROWSE_CONN_CFM_EVT, 0, p_lcb->peer_addr); -} - -/******************************************************************************* -** -** Function avct_bcb_chk_disc -** -** Description A ccb wants to close; if it is the last ccb on this lcb, -** close channel. Otherwise just deallocate and call -** callback. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_chk_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - AVCT_TRACE_WARNING0("avct_bcb_chk_disc"); - p_bcb->ch_close = avct_bcb_last_ccb(p_bcb, p_data->p_ccb); - if (p_bcb->ch_close) - { - AVCT_TRACE_WARNING0("b closing"); - avct_bcb_event(p_bcb, AVCT_LCB_INT_CLOSE_EVT, p_data); - } - else - { - AVCT_TRACE_WARNING0("b unbind_disc"); - avct_bcb_unbind_disc(p_bcb, p_data); - } -} - -/******************************************************************************* -** -** Function avct_bcb_chnl_disc -** -** Description Disconnect L2CAP channel. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_chnl_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - L2CA_DisconnectReq(p_bcb->ch_lcid); -} - -/******************************************************************************* -** -** Function avct_bcb_bind_fail -** -** Description Deallocate ccb and call callback with connect event -** with failure result. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_bind_fail(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - p_data->p_ccb->p_bcb = NULL; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), AVCT_BROWSE_CONN_CFM_EVT, AVCT_RESULT_FAIL, NULL); -} - -/******************************************************************************* -** -** Function avct_bcb_cong_ind -** -** Description Handle congestion indication from L2CAP. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_cong_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - UINT8 event; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - - /* set event */ - event = (p_data->cong) ? AVCT_BROWSE_CONG_IND_EVT : AVCT_BROWSE_UNCONG_IND_EVT; - - /* send event to all ccbs on this lcb */ - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), event, 0, p_lcb->peer_addr); - } - } - -} - -/******************************************************************************* -** -** Function avct_bcb_discard_msg -** -** Description Discard a message sent in from the API. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_discard_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - AVCT_TRACE_WARNING0("save msg in control block"); - - if (p_bcb->p_tx_msg) - { - GKI_freebuf(p_bcb->p_tx_msg); - p_bcb->p_tx_msg = NULL; - } - - /* if control channel is up, save the message and open the browsing channel */ - if (p_data->ul_msg.p_ccb->p_lcb) - { - p_bcb->p_tx_msg = p_data->ul_msg.p_buf; - - if (p_bcb->p_tx_msg) - { - p_bcb->p_tx_msg->layer_specific = (p_data->ul_msg.cr << 8) + p_data->ul_msg.label; - - /* the channel is closed, opening or closing - open it again */ - AVCT_TRACE_DEBUG2("ch_state: %d, allocated:%d", p_bcb->ch_state, p_bcb->allocated); - p_bcb->allocated = p_data->ul_msg.p_ccb->p_lcb->allocated; - AVCT_TRACE_DEBUG2("ch_state: %d, allocated:%d", p_bcb->ch_state, p_bcb->allocated); - avct_bcb_event(p_bcb, AVCT_LCB_UL_BIND_EVT, (tAVCT_LCB_EVT *) p_data->ul_msg.p_ccb); - } - } - else - GKI_freebuf(p_data->ul_msg.p_buf); -} - -/******************************************************************************* -** -** Function avct_bcb_send_msg -** -** Description Build and send an AVCTP message. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_send_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - UINT16 curr_msg_len; - UINT8 pkt_type = AVCT_PKT_TYPE_SINGLE; - UINT8 hdr_len; - BT_HDR *p_buf; - UINT8 *p; - - /* store msg len */ - curr_msg_len = p_data->ul_msg.p_buf->len; - - /* initialize packet type and other stuff */ - if (curr_msg_len > (p_bcb->peer_mtu - AVCT_HDR_LEN_SINGLE)) - { - AVCT_TRACE_ERROR3 ("avct_bcb_send_msg msg len (%d) exceeds peer mtu(%d-%d)!!", curr_msg_len, p_bcb->peer_mtu, AVCT_HDR_LEN_SINGLE); - GKI_freebuf(p_data->ul_msg.p_buf); - return; - } - - /* set header len */ - hdr_len = avct_lcb_pkt_type_len[pkt_type]; - p_buf = p_data->ul_msg.p_buf; - - /* set up to build header */ - p_buf->len += hdr_len; - p_buf->offset -= hdr_len; - p = (UINT8 *)(p_buf + 1) + p_buf->offset; - - /* build header */ - AVCT_BLD_HDR(p, p_data->ul_msg.label, pkt_type, p_data->ul_msg.cr); - UINT16_TO_BE_STREAM(p, p_data->ul_msg.p_ccb->cc.pid); - - /* send message to L2CAP */ - L2CA_DataWrite(p_bcb->ch_lcid, p_buf); - return; -} - -/******************************************************************************* -** -** Function avct_bcb_free_msg_ind -** -** Description Discard an incoming AVCTP message. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_free_msg_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - if (p_data) - GKI_freebuf(p_data->p_buf); - return; -} - -/******************************************************************************* -** -** Function avct_bcb_msg_ind -** -** Description Handle an incoming AVCTP message. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_msg_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - UINT8 *p; - UINT8 label, type, cr_ipid; - UINT16 pid; - tAVCT_CCB *p_ccb; - BT_HDR *p_buf; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - - /* this p_buf is to be reported through p_msg_cback. The layer_specific - * needs to be set properly to indicate that it is received through - * broasing channel */ - p_data->p_buf->layer_specific = AVCT_DATA_BROWSE; - - /* reassemble message; if no message available (we received a fragment) return */ - if ((p_data->p_buf = avct_bcb_msg_asmbl(p_bcb, p_data->p_buf)) == NULL) - { - return; - } - - p = (UINT8 *)(p_data->p_buf + 1) + p_data->p_buf->offset; - - /* parse header byte */ - AVCT_PRS_HDR(p, label, type, cr_ipid); - - /* check for invalid cr_ipid */ - if (cr_ipid == AVCT_CR_IPID_INVALID) - { - AVCT_TRACE_WARNING1("Invalid cr_ipid", cr_ipid); - GKI_freebuf(p_data->p_buf); - return; - } - - /* parse and lookup PID */ - BE_STREAM_TO_UINT16(pid, p); - if ((p_ccb = avct_lcb_has_pid(p_lcb, pid)) != NULL) - { - /* PID found; send msg up, adjust bt hdr and call msg callback */ - p_data->p_buf->offset += AVCT_HDR_LEN_SINGLE; - p_data->p_buf->len -= AVCT_HDR_LEN_SINGLE; - (*p_ccb->cc.p_msg_cback)(avct_ccb_to_idx(p_ccb), label, cr_ipid, p_data->p_buf); - } - else - { - /* PID not found; drop message */ - AVCT_TRACE_WARNING1("No ccb for PID=%x", pid); - GKI_freebuf(p_data->p_buf); - - /* if command send reject */ - if (cr_ipid == AVCT_CMD) - { - if ((p_buf = (BT_HDR *) GKI_getpoolbuf(AVCT_CMD_POOL_ID)) != NULL) - { - p_buf->len = AVCT_HDR_LEN_SINGLE; - p_buf->offset = AVCT_MSG_OFFSET - AVCT_HDR_LEN_SINGLE; - p = (UINT8 *)(p_buf + 1) + p_buf->offset; - AVCT_BLD_HDR(p, label, AVCT_PKT_TYPE_SINGLE, AVCT_REJ); - UINT16_TO_BE_STREAM(p, pid); - L2CA_DataWrite(p_bcb->ch_lcid, p_buf); - } - } - } -} - -/******************************************************************************* -** -** Function avct_bcb_dealloc -** -** Description Deallocate a link control block. -** -** -** Returns void. -** -*******************************************************************************/ -void avct_bcb_dealloc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - tAVCT_CCB *p_ccb_found = NULL; - BOOLEAN found = FALSE; - int i; - - AVCT_TRACE_DEBUG1("avct_bcb_dealloc %d", p_bcb->allocated); - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - /* if ccb allocated and */ - if (p_ccb->allocated) - { - if (p_ccb->p_bcb == p_bcb) - { - p_ccb_found = p_ccb; - p_ccb->p_bcb = NULL; - AVCT_TRACE_DEBUG1("avct_bcb_dealloc used by ccb: %d", i); - found = TRUE; - break; - } - } - } - - /* the browsing channel is down. Check if we have pending messages */ - if (p_bcb->p_tx_msg != NULL) - { - GKI_freebuf(p_bcb->p_tx_msg); - } - memset(p_bcb, 0, sizeof(tAVCT_BCB)); -} - -/******************************************************************************* -** -** Function avct_close_bcb -** -** Description this function is called right before LCB disconnects. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_close_bcb(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_BCB *p_bcb = avct_bcb_by_lcb(p_lcb); - if (p_bcb->allocated) - { - avct_bcb_event(p_bcb, AVCT_LCB_UL_UNBIND_EVT, p_data); - } -} - - -/******************************************************************************* -** -** Function avct_lcb_by_bcb -** -** Description This lookup function finds the lcb for a bcb. -** -** Returns pointer to the lcb. -** -*******************************************************************************/ -tAVCT_LCB *avct_lcb_by_bcb(tAVCT_BCB *p_bcb) -{ - return &avct_cb.lcb[p_bcb->allocated - 1]; -} - -/******************************************************************************* -** -** Function avct_bcb_by_lcb -** -** Description This lookup function finds the bcb for a lcb. -** -** Returns pointer to the lcb. -** -*******************************************************************************/ -tAVCT_BCB *avct_bcb_by_lcb(tAVCT_LCB *p_lcb) -{ - return &avct_cb.bcb[p_lcb->allocated - 1]; -} - -/******************************************************************************* -** -** Function avct_bcb_last_ccb -** -** Description See if given ccb is only one on the bcb. -** -** -** Returns 0, if ccb is last, (ccb index + 1) otherwise. -** -*******************************************************************************/ -UINT8 avct_bcb_last_ccb(tAVCT_BCB *p_bcb, tAVCT_CCB *p_ccb_last) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - UINT8 idx = 0; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - if (p_ccb != p_ccb_last) - return 0; - idx = (UINT8)(i + 1); - } - } - return idx; -} - -/******************************************************************************* -** -** Function avct_bcb_by_lcid -** -** Description Find the BCB associated with the L2CAP LCID -** -** -** Returns pointer to the lcb, or NULL if none found. -** -*******************************************************************************/ -tAVCT_BCB *avct_bcb_by_lcid(UINT16 lcid) -{ - tAVCT_BCB *p_bcb = &avct_cb.bcb[0]; - int i; - - for (i = 0; i < AVCT_NUM_LINKS; i++, p_bcb++) - { - if (p_bcb->allocated && (p_bcb->ch_lcid == lcid)) - { - break; - } - } - - if (i == AVCT_NUM_LINKS) - { - p_bcb = NULL; - /* out of lcbs */ - AVCT_TRACE_WARNING1("No bcb for lcid %x", lcid); - } - - return p_bcb; -} -#endif /* (AVCT_BROWSE_INCLUDED == TRUE) */ diff --git a/stack/avct/avct_l2c_br.c b/stack/avct/avct_l2c_br.c deleted file mode 100644 index e333edf..0000000 --- a/stack/avct/avct_l2c_br.c +++ /dev/null @@ -1,397 +0,0 @@ -/***************************************************************************** -** -** Name: avct_l2c_br.c -** -** Description: This AVCTP module interfaces to L2CAP -** -** Copyright (c) 2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> -#include "data_types.h" -#include "bt_target.h" -#include "avct_api.h" -#include "avct_int.h" -#include "l2c_api.h" -#include "l2cdefs.h" - -/* Configuration flags. */ -#define AVCT_L2C_CFG_IND_DONE (1<<0) -#define AVCT_L2C_CFG_CFM_DONE (1<<1) - -#if (AVCT_BROWSE_INCLUDED == TRUE) -/* callback function declarations */ -void avct_l2c_br_connect_ind_cback(BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id); -void avct_l2c_br_connect_cfm_cback(UINT16 lcid, UINT16 result); -void avct_l2c_br_config_cfm_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg); -void avct_l2c_br_config_ind_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg); -void avct_l2c_br_disconnect_ind_cback(UINT16 lcid, BOOLEAN ack_needed); -void avct_l2c_br_disconnect_cfm_cback(UINT16 lcid, UINT16 result); -void avct_l2c_br_congestion_ind_cback(UINT16 lcid, BOOLEAN is_congested); -void avct_l2c_br_data_ind_cback(UINT16 lcid, BT_HDR *p_buf); - -/* L2CAP callback function structure */ -const tL2CAP_APPL_INFO avct_l2c_br_appl = { - avct_l2c_br_connect_ind_cback, - avct_l2c_br_connect_cfm_cback, - NULL, - avct_l2c_br_config_ind_cback, - avct_l2c_br_config_cfm_cback, - avct_l2c_br_disconnect_ind_cback, - avct_l2c_br_disconnect_cfm_cback, - NULL, - avct_l2c_br_data_ind_cback, - avct_l2c_br_congestion_ind_cback, - NULL /* tL2CA_TX_COMPLETE_CB */ -}; - -/* Browsing channel eL2CAP default options */ -const tL2CAP_FCR_OPTS avct_l2c_br_fcr_opts_def = { - L2CAP_FCR_ERTM_MODE, /* Mandatory for Browsing channel */ - AVCT_BR_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */ - AVCT_BR_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */ - AVCT_BR_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */ - AVCT_BR_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ - L2CAP_DEFAULT_ERM_MPS /* MPS segment size */ -}; - -/******************************************************************************* -** -** Function avct_l2c_br_connect_ind_cback -** -** Description This is the L2CAP connect indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_connect_ind_cback(BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id) -{ - tAVCT_LCB *p_lcb; - UINT16 result = L2CAP_CONN_NO_RESOURCES; - tL2CAP_CFG_INFO cfg; - tAVCT_BCB *p_bcb; - tL2CAP_ERTM_INFO ertm_info; - - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = TRUE; - - if ((p_lcb = avct_lcb_by_bd(bd_addr)) != NULL) - { - /* control channel exists */ - p_bcb = avct_bcb_by_lcb(p_lcb); - - if (!p_bcb->allocated) - { - /* browsing channel does not exist yet and the browsing channel is registered - * - accept connection */ - p_bcb->allocated = p_lcb->allocated; /* copy the index from lcb */ - - result = L2CAP_CONN_OK; - cfg.mtu = avct_cb.mtu_br; - - cfg.fcr_present = TRUE; - cfg.fcr = avct_l2c_br_fcr_opts_def; - } - } - /* else no control channel yet, reject */ - - /* Set the FCR options: Browsing channel mandates ERTM */ - ertm_info.preferred_mode = cfg.fcr.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_pool_id = AVCT_BR_USER_RX_POOL_ID; - ertm_info.user_tx_pool_id = AVCT_BR_USER_TX_POOL_ID; - ertm_info.fcr_rx_pool_id = AVCT_BR_FCR_RX_POOL_ID; - ertm_info.fcr_tx_pool_id = AVCT_BR_FCR_TX_POOL_ID; - - /* Send L2CAP connect rsp */ - L2CA_ErtmConnectRsp(bd_addr, id, lcid, result, 0, &ertm_info); - - /* if result ok, proceed with connection */ - if (result == L2CAP_CONN_OK) - { - /* store LCID */ - p_bcb->ch_lcid = lcid; - - /* transition to configuration state */ - p_bcb->ch_state = AVCT_CH_CFG; - - /* Send L2CAP config req */ - L2CA_ConfigReq(lcid, &cfg); - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_connect_cfm_cback -** -** Description This is the L2CAP connect confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_connect_cfm_cback(UINT16 lcid, UINT16 result) -{ - tAVCT_BCB *p_lcb; - tL2CAP_CFG_INFO cfg; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - /* if in correct state */ - if (p_lcb->ch_state == AVCT_CH_CONN) - { - /* if result successful */ - if (result == L2CAP_CONN_OK) - { - /* set channel state */ - p_lcb->ch_state = AVCT_CH_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - - cfg.mtu_present = TRUE; - cfg.mtu = avct_cb.mtu_br; - - cfg.fcr_present = TRUE; - cfg.fcr = avct_l2c_br_fcr_opts_def; - - L2CA_ConfigReq(lcid, &cfg); - } - /* else failure */ - else - { - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } - } - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_config_cfm_cback -** -** Description This is the L2CAP config confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_config_cfm_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVCT_BCB *p_lcb; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - /* if in correct state */ - if (p_lcb->ch_state == AVCT_CH_CFG) - { - /* if result successful */ - if (p_cfg->result == L2CAP_CFG_OK) - { - /* update flags */ - p_lcb->ch_flags |= AVCT_L2C_CFG_CFM_DONE; - - /* if configuration complete */ - if (p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) - { - p_lcb->ch_state = AVCT_CH_OPEN; - avct_bcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - /* else failure */ - else - { - /* store result value */ - p_lcb->ch_result = p_cfg->result; - - /* Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } - } - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_config_ind_cback -** -** Description This is the L2CAP config indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_config_ind_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVCT_BCB *p_lcb; - UINT16 max_mtu = GKI_MAX_BUF_SIZE - L2CAP_MIN_OFFSET - BT_HDR_SIZE; - - /* Don't include QoS nor flush timeout in the response since we - currently always accept these values. Note: fcr_present is left - untouched since l2cap negotiates this internally - */ - p_cfg->flush_to_present = FALSE; - p_cfg->qos_present = FALSE; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - /* store the mtu in tbl */ - if (p_cfg->mtu_present) - { - p_lcb->peer_mtu = p_cfg->mtu; - } - else - { - p_lcb->peer_mtu = L2CAP_DEFAULT_MTU; - } - - if (p_lcb->peer_mtu > max_mtu) - { - p_lcb->peer_mtu = p_cfg->mtu = max_mtu; - - /* Must tell the peer what the adjusted value is */ - p_cfg->mtu_present = TRUE; - } - else /* Don't include in the response */ - p_cfg->mtu_present = FALSE; - AVCT_TRACE_DEBUG2 ("avct_l2c_br_config_ind_cback peer_mtu:%d use:%d", p_lcb->peer_mtu, max_mtu); - - if (p_lcb->peer_mtu >= AVCT_MIN_BROWSE_MTU) - p_cfg->result = L2CAP_CFG_OK; - else - { - p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - p_cfg->mtu_present = TRUE; - p_cfg->mtu = AVCT_MIN_BROWSE_MTU; - } - - /* send L2CAP configure response */ - L2CA_ConfigRsp(lcid, p_cfg); - - if (p_cfg->result != L2CAP_CFG_OK) - { - return; - } - - /* if first config ind */ - if ((p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) == 0) - { - /* update flags */ - p_lcb->ch_flags |= AVCT_L2C_CFG_IND_DONE; - - /* if configuration complete */ - if (p_lcb->ch_flags & AVCT_L2C_CFG_CFM_DONE) - { - p_lcb->ch_state = AVCT_CH_OPEN; - avct_bcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_disconnect_ind_cback -** -** Description This is the L2CAP disconnect indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_disconnect_ind_cback(UINT16 lcid, BOOLEAN ack_needed) -{ - tAVCT_BCB *p_lcb; - UINT16 result = AVCT_RESULT_FAIL; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - if (ack_needed) - { - /* send L2CAP disconnect response */ - L2CA_DisconnectRsp(lcid); - } - - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_disconnect_cfm_cback -** -** Description This is the L2CAP disconnect confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_disconnect_cfm_cback(UINT16 lcid, UINT16 result) -{ - tAVCT_BCB *p_lcb; - UINT16 res; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - /* result value may be previously stored */ - res = (p_lcb->ch_result != 0) ? p_lcb->ch_result : result; - p_lcb->ch_result = 0; - - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &res); - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_congestion_ind_cback -** -** Description This is the L2CAP congestion indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_congestion_ind_cback(UINT16 lcid, BOOLEAN is_congested) -{ - tAVCT_BCB *p_lcb; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - avct_bcb_event(p_lcb, AVCT_LCB_LL_CONG_EVT, (tAVCT_LCB_EVT *) &is_congested); - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_data_ind_cback -** -** Description This is the L2CAP data indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_data_ind_cback(UINT16 lcid, BT_HDR *p_buf) -{ - tAVCT_BCB *p_lcb; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - avct_bcb_event(p_lcb, AVCT_LCB_LL_MSG_EVT, (tAVCT_LCB_EVT *) &p_buf); - } - else /* prevent buffer leak */ - GKI_freebuf(p_buf); -} -#endif /* (AVCT_BROWSE_INCLUDED == TRUE) */ - - diff --git a/stack/avrc/avrc_api.c b/stack/avrc/avrc_api.c index dd7e752..94425af 100644 --- a/stack/avrc/avrc_api.c +++ b/stack/avrc/avrc_api.c @@ -98,354 +98,6 @@ static UINT8 * avrc_get_data_ptr(BT_HDR *p_pkt) return p_data; } -#if (AVRC_METADATA_INCLUDED == TRUE) -/****************************************************************************** -** -** Function avrc_prep_end_frag -** -** Description This function prepares an end response fragment -** -** -** Returns Nothing. -** -******************************************************************************/ -static void avrc_prep_end_frag(UINT8 handle) -{ - tAVRC_FRAG_CB *p_fcb; - BT_HDR *p_pkt_new; - UINT8 *p_data; - - AVRC_TRACE_DEBUG0 ("avrc_prep_end_frag" ); - p_fcb = &avrc_cb.fcb[handle]; - p_pkt_new = p_fcb->p_fmsg; - p_pkt_new->len -= (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); - p_pkt_new->offset += (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); - p_data = (UINT8 *)(p_pkt_new+1) + p_pkt_new->offset; - *p_data++ = (AVRC_RSP_ACCEPT & AVRC_CTYPE_MASK); - *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); - *p_data++ = AVRC_OP_VENDOR; - AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); - *p_data++ = p_fcb->frag_pdu; - *p_data++ = AVRC_PKT_END; - UINT16_TO_BE_STREAM(p_data, (p_pkt_new->len - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE)); /* 4=pdu, pkt_type & len */ -} - -/****************************************************************************** -** -** Function avrc_send_continue_frag -** -** Description This function sends a continue response fragment -** -** -** Returns Nothing. -** -******************************************************************************/ -static void avrc_send_continue_frag(UINT8 handle, UINT8 label) -{ - tAVRC_FRAG_CB *p_fcb; - BT_HDR *p_pkt_old, *p_pkt; - UINT8 *p_old, *p_data; - UINT8 cr = AVCT_RSP; - tAVRC_RSP rej_rsp; - - p_fcb = &avrc_cb.fcb[handle]; - p_pkt = p_fcb->p_fmsg; - - AVRC_TRACE_DEBUG1 ("avrc_send_continue_frag len(%d) / AVRC_MAX_CTRL_DATA_LEN", p_pkt->len ); - if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) - { - p_pkt_old = p_fcb->p_fmsg; - p_pkt = (BT_HDR *)GKI_getbuf((UINT16)(AVRC_PACKET_LEN + AVCT_MSG_OFFSET + BT_HDR_SIZE)); - if (p_pkt) - { - p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; - p_pkt->offset = AVCT_MSG_OFFSET; - p_pkt->layer_specific = p_pkt_old->layer_specific; - p_pkt->event = p_pkt_old->event; - p_old = (UINT8 *)(p_pkt_old+1) + p_pkt_old->offset; - p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; - memcpy (p_data, p_old, AVRC_MAX_CTRL_DATA_LEN); - /* use AVRC continue packet type */ - p_data += AVRC_VENDOR_HDR_SIZE; - p_data++; /* pdu */ - *p_data++ = AVRC_PKT_CONTINUE; - UINT16_TO_BE_STREAM(p_data, (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - 4)); /* 4=pdu, pkt_type & len */ - - /* prepare the left over for as an end fragment */ - avrc_prep_end_frag (handle); - } - else - { - /* use the current GKI buffer to send Internal error status */ - p_pkt = p_fcb->p_fmsg; - p_fcb->p_fmsg = NULL; - p_fcb->frag_enabled = FALSE; - AVRC_TRACE_ERROR0 ("AVRC_MsgReq no buffers for fragmentation - send internal error" ); - p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; - *p_data++ = AVRC_PDU_REQUEST_CONTINUATION_RSP; - *p_data++ = 0; - UINT16_TO_BE_STREAM(p_data, 0); - p_pkt->len = 4; - rej_rsp.pdu = AVRC_PDU_REQUEST_CONTINUATION_RSP; - rej_rsp.status = AVRC_STS_INTERNAL_ERR; - AVRC_BldResponse( handle, (tAVRC_RESPONSE *)&rej_rsp, &p_pkt); - cr = AVCT_RSP; - } - } - else - { - /* end fragment. clean the control block */ - p_fcb->frag_enabled = FALSE; - p_fcb->p_fmsg = NULL; - } - AVCT_MsgReq( handle, label, cr, p_pkt); -} - -/****************************************************************************** -** -** Function avrc_proc_vendor_command -** -** Description This function processes received vendor command. -** -** -** Returns if not NULL, the response to send right away. -** -******************************************************************************/ -static BT_HDR * avrc_proc_vendor_command(UINT8 handle, UINT8 label, - BT_HDR *p_pkt, tAVRC_MSG_VENDOR *p_msg) -{ - BT_HDR *p_rsp = NULL; - UINT8 *p_data; - UINT8 *p_begin; - UINT8 pkt_type; - BOOLEAN abort_frag = FALSE; - tAVRC_STS status = AVRC_STS_NO_ERROR; - tAVRC_FRAG_CB *p_fcb; - - p_begin = (UINT8 *)(p_pkt+1) + p_pkt->offset; - p_data = p_begin + AVRC_VENDOR_HDR_SIZE; - pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; - - if (pkt_type != AVRC_PKT_SINGLE) - { - /* reject - commands can only be in single packets at AVRCP level */ - AVRC_TRACE_ERROR1 ("commands must be in single packet pdu:0x%x", *p_data ); - /* use the current GKI buffer to send the reject */ - status = AVRC_STS_BAD_CMD; - } - /* check if there are fragments waiting to be sent */ - else if (avrc_cb.fcb[handle].frag_enabled) - { - p_fcb = &avrc_cb.fcb[handle]; - if (p_msg->company_id == AVRC_CO_METADATA) - { - switch (*p_data) - { - case AVRC_PDU_ABORT_CONTINUATION_RSP: - /* aborted by CT - send accept response */ - abort_frag = TRUE; - p_begin = (UINT8 *)(p_pkt+1) + p_pkt->offset; - *p_begin = (AVRC_RSP_ACCEPT & AVRC_CTYPE_MASK); - if (*(p_data + 4) != p_fcb->frag_pdu) - { - *p_begin = (AVRC_RSP_REJ & AVRC_CTYPE_MASK); - *(p_data + 4) = AVRC_STS_BAD_PARAM; - } - else - { - p_data = (p_begin + AVRC_VENDOR_HDR_SIZE + 2); - UINT16_TO_BE_STREAM(p_data, 0); - p_pkt->len = (p_data - p_begin); - } - AVCT_MsgReq( handle, label, AVCT_RSP, p_pkt); - p_msg->hdr.opcode = AVRC_OP_DROP; /* used the p_pkt to send response */ - break; - - case AVRC_PDU_REQUEST_CONTINUATION_RSP: - if (*(p_data + 4) == p_fcb->frag_pdu) - { - avrc_send_continue_frag(handle, label); - p_msg->hdr.opcode = AVRC_OP_DROP_N_FREE; - } - else - { - /* the pdu id does not match - reject the command using the current GKI buffer */ - AVRC_TRACE_ERROR2("avrc_proc_vendor_command continue pdu: 0x%x does not match current re-assembly pdu: 0x%x", - *(p_data + 4), p_fcb->frag_pdu); - status = AVRC_STS_BAD_PARAM; - abort_frag = TRUE; - } - break; - - default: - /* implicit abort */ - abort_frag = TRUE; - } - } - else - { - abort_frag = TRUE; - /* implicit abort */ - } - - if (abort_frag) - { - if (p_fcb->p_fmsg) - GKI_freebuf(p_fcb->p_fmsg); - p_fcb->p_fmsg = NULL; - p_fcb->frag_enabled = FALSE; - } - } - - if (status != AVRC_STS_NO_ERROR) - { - /* use the current GKI buffer to build/send the reject message */ - p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; - *p_data++ = AVRC_RSP_REJ; - p_data += AVRC_VENDOR_HDR_SIZE; /* pdu */ - *p_data++ = 0; /* pkt_type */ - UINT16_TO_BE_STREAM(p_data, 1); /* len */ - *p_data++ = status; /* error code */ - p_pkt->len = AVRC_VENDOR_HDR_SIZE + 5; - p_rsp = p_pkt; - } - - return p_rsp; -} - -/****************************************************************************** -** -** Function avrc_proc_far_msg -** -** Description This function processes vendor command/response fragmetation -** and reassembly -** -** Returns 0, to report the message with msg_cback . -** -******************************************************************************/ -static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_pkt, tAVRC_MSG_VENDOR *p_msg) -{ - BT_HDR *p_pkt = *pp_pkt; - UINT8 *p_data; - BOOLEAN drop = FALSE; - BT_HDR *p_rsp = NULL; - BT_HDR *p_cmd = NULL; - BOOLEAN req_continue = FALSE; - BT_HDR *p_pkt_new = NULL; - UINT8 pkt_type; - UINT16 buf_len; - tAVRC_RASM_CB *p_rcb; - tAVRC_NEXT_CMD avrc_cmd; - - p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; - pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; - AVRC_TRACE_DEBUG1 ("pkt_type %d", pkt_type ); - p_rcb = &avrc_cb.rcb[handle]; - if (p_msg->company_id == AVRC_CO_METADATA) - { - /* check if the message needs to be re-assembled */ - if (pkt_type == AVRC_PKT_SINGLE || pkt_type == AVRC_PKT_START) - { - /* previous fragments need to be dropped, when received another new message */ - p_rcb->rasm_offset = 0; - if (p_rcb->p_rmsg) - { - GKI_freebuf(p_rcb->p_rmsg); - p_rcb->p_rmsg = NULL; - } - } - - if (pkt_type != AVRC_PKT_SINGLE && cr == AVCT_RSP) - { - /* not a single response packet - need to re-assemble metadata messages */ - if (pkt_type == AVRC_PKT_START) - { - p_rcb->rasm_offset = p_pkt->offset; - p_rcb->p_rmsg = p_pkt; - /* set offset to point to where to copy next - use the same re-asm logic as AVCT */ - p_rcb->p_rmsg->offset += p_rcb->p_rmsg->len; - p_rcb->rasm_pdu = *p_data; - req_continue = TRUE; - } - else - { - /* get size of buffer holding assembled message */ - buf_len = GKI_get_buf_size (p_rcb->p_rmsg) - sizeof(BT_HDR); - /* adjust offset and len of fragment for header byte */ - p_pkt->offset += (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); - p_pkt->len -= (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); - /* verify length */ - if ((p_rcb->p_rmsg->offset + p_pkt->len) > buf_len) - { - AVRC_TRACE_WARNING0("Fragmented message too big! - report the partial message"); - p_pkt->len = buf_len - p_rcb->p_rmsg->offset; - pkt_type = AVRC_PKT_END; - } - - /* copy contents of p_pkt to p_rx_msg */ - memcpy((UINT8 *)(p_rcb->p_rmsg + 1) + p_rcb->p_rmsg->offset, - (UINT8 *)(p_pkt + 1) + p_pkt->offset, p_pkt->len); - - if (pkt_type == AVRC_PKT_END) - { - p_rcb->p_rmsg->offset = p_rcb->rasm_offset; - p_rcb->p_rmsg->len += p_pkt->len; - p_pkt_new = p_rcb->p_rmsg; - p_rcb->rasm_offset = 0; - p_rcb->p_rmsg = NULL; - p_msg->p_vendor_data = (UINT8 *)(p_pkt_new+1) + p_pkt_new->offset; - p_msg->hdr.ctype = p_msg->p_vendor_data[0] & AVRC_CTYPE_MASK; - p_msg->p_vendor_data += AVRC_VENDOR_HDR_SIZE; /* 6 = ctype, subunit*, opcode & CO_ID */ - p_msg->vendor_len = p_pkt_new->len - AVRC_VENDOR_HDR_SIZE; - p_data = p_msg->p_vendor_data + 1; /* skip pdu */ - *p_data++ = AVRC_PKT_SINGLE; - UINT16_TO_BE_STREAM(p_data, (p_msg->vendor_len - AVRC_MIN_META_HDR_SIZE)); - AVRC_TRACE_DEBUG3("end frag:%d, total len:%d, offset:%d", p_pkt->len, p_pkt_new->len, p_pkt_new->offset); - } - else - { - p_rcb->p_rmsg->offset += p_pkt->len; - p_rcb->p_rmsg->len += p_pkt->len; - p_pkt_new = NULL; - req_continue = TRUE; - } - GKI_freebuf(p_pkt); - *pp_pkt = p_pkt_new; - } - } - - if (cr == AVCT_CMD) - { - p_rsp = avrc_proc_vendor_command(handle, label, *pp_pkt, p_msg); - if (p_rsp) - { - AVCT_MsgReq( handle, label, AVCT_RSP, p_rsp); - drop = 3; - } - else if (p_msg->hdr.opcode == AVRC_OP_DROP) - { - drop = 1; - } - else if (p_msg->hdr.opcode == AVRC_OP_DROP_N_FREE) - drop = 4; - - } - else if (cr == AVCT_RSP && req_continue == TRUE) - { - avrc_cmd.pdu = AVRC_PDU_REQUEST_CONTINUATION_RSP; - avrc_cmd.status = AVRC_STS_NO_ERROR; - avrc_cmd.target_pdu = p_rcb->rasm_pdu; - if (AVRC_BldCommand ((tAVRC_COMMAND *)&avrc_cmd, &p_cmd) == AVRC_STS_NO_ERROR) - { - cr = AVCT_CMD; - drop = 2; - AVRC_MsgReq (handle, (UINT8)(label+1), cr, p_cmd); - } - } - } - return drop; -} -#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ /****************************************************************************** ** @@ -497,17 +149,6 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; memset(&msg, 0, sizeof(tAVRC_MSG) ); -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) - if (p_pkt->layer_specific == AVCT_DATA_BROWSE) - { - opcode = AVRC_OP_BROWSE; - msg.browse.hdr.ctype= cr; - msg.browse.p_browse_data = p_data; - msg.browse.browse_len = p_pkt->len; - msg.browse.p_browse_pkt = p_pkt; - } - else -#endif { msg.hdr.ctype = p_data[0] & AVRC_CTYPE_MASK; AVRC_TRACE_DEBUG4("avrc_msg_cback handle:%d, ctype:%d, offset:%d, len: %d", @@ -602,34 +243,6 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, p_msg->p_vendor_data = p_data; p_msg->vendor_len = p_pkt->len - (p_data - p_begin); -#if (AVRC_METADATA_INCLUDED == TRUE) - drop = avrc_proc_far_msg(handle, label, cr, &p_pkt, p_msg); - if (drop) - { - free = FALSE; - if (drop == 4) - free = TRUE; -#if (BT_USE_TRACES == TRUE) - switch (drop) - { - case 1: - p_drop_msg = "sent_frag"; - break; - case 2: - p_drop_msg = "req_cont"; - break; - case 3: - p_drop_msg = "sent_frag3"; - break; - case 4: - p_drop_msg = "sent_frag_free"; - break; - default: - p_drop_msg = "sent_fragd"; - } -#endif - } -#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ break; case AVRC_OP_PASS_THRU: @@ -657,12 +270,6 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, msg.pass.p_pass_data = NULL; break; -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) - case AVRC_OP_BROWSE: - /* the event data is handled already. - * this empty "case" is to keep the message from being rejected by the default case. */ - break; -#endif default: if ((avrc_cb.ccb[handle].control & AVRC_CT_TARGET) && (cr == AVCT_CMD)) @@ -676,9 +283,6 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, } else /* drop the event */ { -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) - if (opcode != AVRC_OP_BROWSE) -#endif drop = TRUE; } @@ -717,12 +321,6 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, } #endif -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) - if (opcode == AVRC_OP_BROWSE && msg.browse.p_browse_pkt == NULL) - { - free = FALSE; - } -#endif if (free) GKI_freebuf(p_pkt); @@ -847,10 +445,6 @@ UINT16 AVRC_Open(UINT8 *p_handle, tAVRC_CONN_CB *p_ccb, BD_ADDR_PTR peer_addr) if (status == AVCT_SUCCESS) { memcpy(&avrc_cb.ccb[*p_handle], p_ccb, sizeof(tAVRC_CONN_CB)); -#if (AVRC_METADATA_INCLUDED == TRUE) - memset(&avrc_cb.fcb[*p_handle], 0, sizeof(tAVRC_FRAG_CB)); - memset(&avrc_cb.rcb[*p_handle], 0, sizeof(tAVRC_RASM_CB)); -#endif } AVRC_TRACE_DEBUG4("AVRC_Open role: %d, control:%d status:%d, handle:%d", cc.role, cc.control, status, *p_handle); @@ -881,43 +475,6 @@ UINT16 AVRC_Close(UINT8 handle) return AVCT_RemoveConn(handle); } -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) -/****************************************************************************** -** -** Function AVRC_OpenBrowse -** -** Description This function is called to open a browsing connection to AVCTP. -** The connection can be either an initiator or acceptor, as -** determined by the p_conn_role. -** The handle is returned by a previous call to AVRC_Open. -** -** Returns AVRC_SUCCESS if successful. -** AVRC_NO_RESOURCES if there are not enough resources to open -** the connection. -** -******************************************************************************/ -UINT16 AVRC_OpenBrowse(UINT8 handle, UINT8 conn_role) -{ - return AVCT_CreateBrowse(handle, conn_role); -} - -/****************************************************************************** -** -** Function AVRC_CloseBrowse -** -** Description Close a connection opened with AVRC_OpenBrowse(). -** This function is called when the -** application is no longer using a connection. -** -** Returns AVRC_SUCCESS if successful. -** AVRC_BAD_HANDLE if handle is invalid. -** -******************************************************************************/ -UINT16 AVRC_CloseBrowse(UINT8 handle) -{ - return AVCT_RemoveBrowse(handle); -} -#endif /****************************************************************************** ** @@ -937,121 +494,7 @@ UINT16 AVRC_CloseBrowse(UINT8 handle) ******************************************************************************/ UINT16 AVRC_MsgReq (UINT8 handle, UINT8 label, UINT8 ctype, BT_HDR *p_pkt) { -#if (AVRC_METADATA_INCLUDED == TRUE) - UINT8 *p_data; - UINT8 cr = AVCT_CMD; - BOOLEAN chk_frag = TRUE; - UINT8 *p_start = NULL; - tAVRC_FRAG_CB *p_fcb; - UINT16 len; - BT_HDR *p_pkt_new; -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) - UINT16 peer_mtu; -#endif - - if (!p_pkt) - return AVRC_BAD_PARAM; - - if (ctype >= AVRC_RSP_NOT_IMPL) - cr = AVCT_RSP; - - if (p_pkt->event == AVRC_OP_VENDOR) - { - /* add AVRCP Vendor Dependent headers */ - p_start = ((UINT8 *)(p_pkt + 1) + p_pkt->offset); - p_pkt->offset -= AVRC_VENDOR_HDR_SIZE; - p_pkt->len += AVRC_VENDOR_HDR_SIZE; - p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - *p_data++ = (ctype & AVRC_CTYPE_MASK); - *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); - *p_data++ = AVRC_OP_VENDOR; - AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); - } - else if (p_pkt->event == AVRC_OP_PASS_THRU) - { - /* add AVRCP Pass Through headers */ - p_start = ((UINT8 *)(p_pkt + 1) + p_pkt->offset); - p_pkt->offset -= AVRC_PASS_THRU_SIZE; - p_pkt->len += AVRC_PASS_THRU_SIZE; - p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - *p_data++ = (ctype & AVRC_CTYPE_MASK); - *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); - *p_data++ = AVRC_OP_PASS_THRU;/* opcode */ - *p_data++ = AVRC_ID_VENDOR; /* operation id */ - *p_data++ = 5; /* operation data len */ - AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); - } -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) - else - { - chk_frag = FALSE; - peer_mtu = AVCT_GetBrowseMtu (handle); - if (p_pkt->len > (peer_mtu-AVCT_HDR_LEN_SINGLE)) - { - AVRC_TRACE_ERROR3 ("p_pkt->len(%d) > peer_mtu(%d-%d)", p_pkt->len, peer_mtu, AVCT_HDR_LEN_SINGLE ); - GKI_freebuf(p_pkt); - return AVRC_MSG_TOO_BIG; - } - } -#endif - - /* abandon previous fragments */ - p_fcb = &avrc_cb.fcb[handle]; - if (p_fcb->frag_enabled) - p_fcb->frag_enabled = FALSE; - - if (p_fcb->p_fmsg) - { - GKI_freebuf(p_fcb->p_fmsg); - p_fcb->p_fmsg = NULL; - } - - /* AVRCP spec has not defined any control channel commands that needs fragmentation at this level - * check for fragmentation only on the response */ - if ((cr == AVCT_RSP) && (chk_frag == TRUE)) - { - if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) - { - AVRC_TRACE_DEBUG1 ("p_pkt->len(%d) > AVRC_MAX_CTRL_DATA_LEN", p_pkt->len ); - p_pkt_new = (BT_HDR *)GKI_getbuf((UINT16)(AVRC_PACKET_LEN + AVCT_MSG_OFFSET + BT_HDR_SIZE)); - if (p_pkt_new) - { - p_fcb->frag_enabled = TRUE; - p_fcb->p_fmsg = p_pkt; - p_fcb->frag_pdu = *p_start; - p_pkt = p_pkt_new; - p_pkt_new = p_fcb->p_fmsg; - p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; - p_pkt->offset = p_pkt_new->offset; - p_pkt->layer_specific = p_pkt_new->layer_specific; - p_pkt->event = p_pkt_new->event; - p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; - p_start -= AVRC_VENDOR_HDR_SIZE; - memcpy (p_data, p_start, AVRC_MAX_CTRL_DATA_LEN); - /* use AVRC start packet type */ - p_data += AVRC_VENDOR_HDR_SIZE; - p_data++; /* pdu */ - *p_data++ = AVRC_PKT_START; - len = (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); /* 4 pdu, pkt_type & len */ - UINT16_TO_BE_STREAM(p_data, len); - - /* prepare the left over for as an end fragment */ - avrc_prep_end_frag (handle); - AVRC_TRACE_DEBUG3 ("p_pkt len:%d/%d, next len:%d", p_pkt->len, len, p_fcb->p_fmsg->len ); - } - else - { - AVRC_TRACE_ERROR0 ("AVRC_MsgReq no buffers for fragmentation" ); - GKI_freebuf(p_pkt); - return AVRC_NO_RESOURCES; - } - } - } - - return AVCT_MsgReq( handle, label, cr, p_pkt); -#else return AVRC_NO_RESOURCES; -#endif } diff --git a/stack/avrc/avrc_bld_ct.c b/stack/avrc/avrc_bld_ct.c deleted file mode 100644 index a1d5fa1..0000000 --- a/stack/avrc/avrc_bld_ct.c +++ /dev/null @@ -1,1102 +0,0 @@ -/***************************************************************************** -** -** Name: avrc_bld_ct.c -** -** Description:Interface to AVRCP build message functions for the Control Role -** -** Copyright (c) 2008-2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "gki.h" -#include "avrc_api.h" -#include "avrc_defs.h" -#include "avrc_int.h" - -/***************************************************************************** -** Global data -*****************************************************************************/ - - -#if (AVRC_METADATA_INCLUDED == TRUE) -/******************************************************************************* -** -** Function avrc_bld_get_capability_cmd -** -** Description This function builds the Get Capability command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_capability_cmd (tAVRC_GET_CAPS_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - if (!AVRC_IS_VALID_CAP_ID(p_cmd->capability_id)) - { - AVRC_TRACE_ERROR1("avrc_bld_get_capability_cmd bad capability_id:0x%x", p_cmd->capability_id); - return AVRC_STS_BAD_PARAM; - } - - AVRC_TRACE_API0("avrc_bld_get_capability_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - - /* add fixed lenth - capability_id(1) */ - UINT16_TO_BE_STREAM(p_data, 1); - /* add the capability_id */ - UINT8_TO_BE_STREAM(p_data, p_cmd->capability_id); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_list_app_settings_attr_cmd -** -** Description This function builds the List Application Settings Attribute -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_list_app_settings_attr_cmd (tAVRC_CMD *p_cmd, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_list_app_settings_attr_cmd"); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_list_app_settings_values_cmd -** -** Description This function builds the List Application Setting Values -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_list_app_settings_values_cmd (tAVRC_LIST_APP_VALUES_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - if (!AVRC_IsValidPlayerAttr(p_cmd->attr_id)) - { - AVRC_TRACE_ERROR1("avrc_bld_list_app_settings_values_cmd bad attr:0x%x", p_cmd->attr_id); - return AVRC_STS_BAD_PARAM; - } - - AVRC_TRACE_API0("avrc_bld_list_app_settings_values_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - - /* add fixed lenth - attr_id(1) */ - UINT16_TO_BE_STREAM(p_data, 1); - /* add the attr_id */ - UINT8_TO_BE_STREAM(p_data, p_cmd->attr_id); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_get_cur_app_setting_value_cmd -** -** Description This function builds the Get Current Application Setting Value -** or the Get Application Setting Attribute Text command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_cur_app_setting_value_cmd (tAVRC_GET_CUR_APP_VALUE_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len; - UINT16 len = 0; - UINT8 xx; - UINT8 *p_count; - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_len = p_data = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - p_count = p_data; - if (len == 0) - { - /* first time initialize the attribute count */ - *p_count = 0; - p_data++; - len = 1; - } - else - { - p_data = p_start + p_pkt->len; - } - - for (xx=0; xx<p_cmd->num_attr; xx++) - { - if (AVRC_IsValidPlayerAttr(p_cmd->attrs[xx])) - { - (*p_count)++; - UINT8_TO_BE_STREAM(p_data, p_cmd->attrs[xx]); - len++; - } - } - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_set_app_setting_value_cmd -** -** Description This function builds the Set Application Setting Value -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_set_app_setting_value_cmd (tAVRC_SET_APP_VALUE_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len; - UINT16 len; - UINT8 xx; - UINT8 *p_count; - - if (!p_cmd->p_vals) - { - AVRC_TRACE_ERROR0("avrc_bld_set_app_setting_value_cmd NULL parameter"); - return AVRC_STS_BAD_PARAM; - } - - AVRC_TRACE_API1("avrc_bld_set_app_setting_value_cmd num_val:%d", p_cmd->num_val); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - p_count = p_data; - if (len == 0) - { - /* first time initialize the attribute count */ - *p_count = 0; - p_data++; - len = 1; - } - else - { - p_data = p_start + p_pkt->len; - } - - - for (xx=0; xx<p_cmd->num_val; xx++) - { - AVRC_TRACE_DEBUG3("[%d] id/val = 0x%x/0x%x", xx, p_cmd->p_vals[xx].attr_id, p_cmd->p_vals[xx].attr_val); - if (avrc_is_valid_player_attrib_value(p_cmd->p_vals[xx].attr_id, p_cmd->p_vals[xx].attr_val)) - { - (*p_count)++; - UINT8_TO_BE_STREAM(p_data, p_cmd->p_vals[xx].attr_id); - UINT8_TO_BE_STREAM(p_data, p_cmd->p_vals[xx].attr_val); - len += 2; - } - } - - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_get_app_setting_attr_text_cmd -** -** Description This function builds the Get Application Setting Attribute Text -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_app_setting_attr_text_cmd (tAVRC_GET_APP_ATTR_TXT_CMD *p_cmd, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_get_app_setting_attr_text_cmd"); - return avrc_bld_get_cur_app_setting_value_cmd((tAVRC_GET_CUR_APP_VALUE_CMD *)p_cmd, p_pkt); - -} - -/******************************************************************************* -** -** Function avrc_bld_get_app_setting_value_text_cmd -** -** Description This function builds the Get Application Setting Value Text -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_app_setting_value_text_cmd (tAVRC_GET_APP_VAL_TXT_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len; - UINT16 len = 0; - UINT8 xx; - UINT8 *p_count; - - AVRC_TRACE_API0("avrc_bld_get_app_setting_value_text_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - p_count = p_data + 1; - if (len == 0) - { - /* first time initialize the attribute count */ - UINT8_TO_BE_STREAM(p_data, p_cmd->attr_id); - *p_count = 0; - p_data++; - len = 2; - } - else - { - p_data = p_start + p_pkt->len; - } - - for (xx=0; xx<p_cmd->num_val; xx++) - { - (*p_count)++; - UINT8_TO_BE_STREAM(p_data, p_cmd->vals[xx]); - len++; - } - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_inform_charset_cmd -** -** Description This function builds the Inform Displayable Character Set -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_inform_charset_cmd (tAVRC_INFORM_CHARSET_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT16 len = 0; - UINT8 xx; - - AVRC_TRACE_API0("avrc_bld_inform_charset_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - - len = 1 + (p_cmd->num_id << 1); - UINT16_TO_BE_STREAM(p_data, len); - - UINT8_TO_BE_STREAM(p_data, p_cmd->num_id); - for (xx=0; xx<p_cmd->num_id; xx++) - { - UINT16_TO_BE_STREAM(p_data, p_cmd->charsets[xx]); - } - - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_inform_battery_status_cmd -** -** Description This function builds the Inform Battery Status -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_inform_battery_status_cmd (tAVRC_BATTERY_STATUS_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - if (!AVRC_IS_VALID_BATTERY_STATUS(p_cmd->battery_status)) - { - AVRC_TRACE_ERROR1("avrc_bld_inform_battery_status_cmd bad battery_status:0x%x", p_cmd->battery_status); - return AVRC_STS_BAD_PARAM; - } - - AVRC_TRACE_API0("avrc_bld_inform_battery_status_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed lenth - battery_status(1) */ - UINT16_TO_BE_STREAM(p_data, 1); - /* add the battery_status */ - UINT8_TO_BE_STREAM(p_data, p_cmd->battery_status); - - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_get_elem_attrs_cmd -** -** Description This function builds the Get Element Attributes -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_elem_attrs_cmd (tAVRC_GET_ELEM_ATTRS_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len; - UINT16 len = 0; - UINT8 xx; - UINT8 *p_count; - - AVRC_TRACE_API0("avrc_bld_get_elem_attrs_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_len = p_start + 2; /* pdu + rsvd */ - p_data = p_len + 2; - - /* 8 byte identifier 0 - PLAYING - the only valid one */ - UINT32_TO_BE_STREAM(p_data, 0); - UINT32_TO_BE_STREAM(p_data, 0); - - p_count = p_data; - p_data++; - *p_count = 0; - len = 9; - for (xx=0; xx<p_cmd->num_attr; xx++) - { - if (AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_cmd->attrs[xx])) - { - (*p_count)++; - UINT32_TO_BE_STREAM(p_data, p_cmd->attrs[xx]); - len += 4; - } - } - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_get_play_status_cmd -** -** Description This function builds the Get Play Status -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_play_status_cmd (tAVRC_CMD *p_cmd, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_get_play_status_cmd"); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_notify_cmd -** -** Description This function builds the Register Notification command. -** -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_notify_cmd (tAVRC_REG_NOTIF_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - AVRC_TRACE_API0("avrc_bld_notify_cmd"); - if (!AVRC_IS_VALID_EVENT_ID(p_cmd->event_id)) - { - AVRC_TRACE_ERROR1("avrc_bld_notify_cmd bad event_id:0x%x", p_cmd->event_id); - return AVRC_STS_BAD_PARAM; - } - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - - /* add fixed lenth 5 - event_id (1) + interval(4) */ - UINT16_TO_BE_STREAM(p_data, 5); - UINT8_TO_BE_STREAM(p_data, p_cmd->event_id); - UINT32_TO_BE_STREAM(p_data, p_cmd->param); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_next_cmd -** -** Description This function builds the Request Continue or Abort command. -** -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_next_cmd (tAVRC_NEXT_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - AVRC_TRACE_API0("avrc_bld_next_cmd"); - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - - /* add fixed lenth 1 - pdu_id (1) */ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, p_cmd->target_pdu); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_group_navigation_cmd -** -** Description This function builds the Group Navigation -** command. -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -tAVRC_STS avrc_bld_group_navigation_cmd (UINT16 navi_id, BT_HDR *p_pkt) -{ - UINT8 *p_data; - - if (!AVRC_IS_VALID_GROUP(navi_id)) - { - AVRC_TRACE_ERROR1("avrc_bld_group_navigation_cmd bad navigation op id: %d", navi_id); - return AVRC_STS_BAD_PARAM; - } - - AVRC_TRACE_API0("avrc_bld_group_navigation_cmd"); - p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; - UINT16_TO_BE_STREAM(p_data, navi_id); - p_pkt->len = 2; - return AVRC_STS_NO_ERROR; -} - -/***************************************************************************** -** the following commands are introduced in AVRCP 1.4 -*****************************************************************************/ - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) -/******************************************************************************* -** -** Function avrc_bld_set_addr_player_cmd -** -** Description This function builds the Set Addresses Player command. -** -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_set_addr_player_cmd (tAVRC_SET_ADDR_PLAYER_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - AVRC_TRACE_API0("avrc_bld_set_addr_player_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed lenth - player_id(2) */ - UINT16_TO_BE_STREAM(p_data, 2); - UINT16_TO_BE_STREAM(p_data, p_cmd->player_id); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_set_abs_volume_cmd -** -** Description This function builds the Set Absolute Volume command. -** -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_set_abs_volume_cmd (tAVRC_SET_VOLUME_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - AVRC_TRACE_API0("avrc_bld_set_abs_volume_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed lenth 1 - volume (1) */ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, (AVRC_MAX_VOLUME & p_cmd->volume)); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_set_browsed_player_cmd -** -** Description This function builds the Set Browsed Player command. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_set_browsed_player_cmd (tAVRC_SET_BR_PLAYER_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - AVRC_TRACE_API0("avrc_bld_set_browsed_player_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 1; /* pdu */ - /* add fixed lenth - player_id(2) */ - UINT16_TO_BE_STREAM(p_data, 2); - UINT16_TO_BE_STREAM(p_data, p_cmd->player_id); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - -/******************************************************************************* -** -** Function avrc_bld_get_folder_items_cmd -** -** Description This function builds the Get Folder Items command. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_get_folder_items_cmd (tAVRC_GET_ITEMS_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len, xx; - UINT16 len = 0; - - AVRC_TRACE_API0("avrc_bld_get_folder_items_cmd"); - if (p_cmd->scope > AVRC_SCOPE_NOW_PLAYING || p_cmd->start_item > p_cmd->end_item) - { - AVRC_TRACE_ERROR3("bad scope:0x%x or range (%d-%d)", p_cmd->scope, p_cmd->start_item, p_cmd->end_item); - return AVRC_STS_BAD_PARAM; - } - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_len = p_start + 1; /* pdu */ - p_data = p_len + 2; - - UINT8_TO_BE_STREAM(p_data, p_cmd->scope); - UINT32_TO_BE_STREAM(p_data, p_cmd->start_item); - UINT32_TO_BE_STREAM(p_data, p_cmd->end_item); - /* do not allow us to send the command with attribute list when scope is player list */ - if (p_cmd->scope == AVRC_SCOPE_PLAYER_LIST) - p_cmd->attr_count = 0; - - UINT8_TO_BE_STREAM(p_data, p_cmd->attr_count); - len = 10; - if ((p_cmd->attr_count != AVRC_FOLDER_ITEM_COUNT_NONE) && - (p_cmd->attr_count > 0)) - { - if (p_cmd->p_attr_list) - { - for (xx=0; xx<p_cmd->attr_count; xx++) - { - UINT32_TO_BE_STREAM(p_data, p_cmd->p_attr_list[xx]); - len += 4; - } - } - else - { - AVRC_TRACE_ERROR1("attr_count:%d but NULL p_attr_list", p_cmd->attr_count); - return AVRC_STS_BAD_PARAM; - } - } - - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - -/******************************************************************************* -** -** Function avrc_bld_change_path_cmd -** -** Description This function builds the Change Path command. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_change_path_cmd (tAVRC_CHG_PATH_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - AVRC_TRACE_API0("avrc_bld_change_path_cmd"); - if (p_cmd->direction != AVRC_DIR_UP && p_cmd->direction != AVRC_DIR_DOWN) - { - AVRC_TRACE_ERROR1("AVRC_BldChangePathCmd bad direction:%d", p_cmd->direction); - return AVRC_STS_BAD_PARAM; - } - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 1; /* pdu */ - /* add fixed lenth - uid_counter(2) + direction(1) + uid(8) */ - UINT16_TO_BE_STREAM(p_data, 11); - UINT16_TO_BE_STREAM(p_data, p_cmd->uid_counter); - *p_data++ = p_cmd->direction; - ARRAY_TO_BE_STREAM(p_data, p_cmd->folder_uid, AVRC_UID_SIZE); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - -/******************************************************************************* -** -** Function avrc_bld_get_item_attrs_cmd -** -** Description This function builds the Get Item Attributes command. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_get_item_attrs_cmd (tAVRC_GET_ATTRS_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len, xx; - UINT16 len; - UINT8 *p_count; - - AVRC_TRACE_API0("avrc_bld_get_item_attrs_cmd"); - if (p_cmd->scope > AVRC_SCOPE_NOW_PLAYING) - { - AVRC_TRACE_ERROR1("bad scope:%d", p_cmd->scope); - return AVRC_STS_BAD_PARAM; - } - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_len = p_start + 1; /* pdu */ - p_data = p_len + 2; - - UINT8_TO_BE_STREAM(p_data, p_cmd->scope); - ARRAY_TO_BE_STREAM(p_data, p_cmd->uid, AVRC_UID_SIZE); - UINT16_TO_BE_STREAM(p_data, p_cmd->uid_counter); - //UINT8_TO_BE_STREAM(p_data, p_cmd->attr_count); - p_count = p_data++; - len = AVRC_UID_SIZE + 4; - *p_count = 0; - - if (p_cmd->attr_count>0) - { - if (p_cmd->p_attr_list) - { - for (xx=0; xx<p_cmd->attr_count; xx++) - { - if (AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_cmd->p_attr_list[xx])) - { - (*p_count)++; - UINT32_TO_BE_STREAM(p_data, p_cmd->p_attr_list[xx]); - len += 4; - } -#if (BT_USE_TRACES == TRUE) - else - { - AVRC_TRACE_ERROR1("invalid attr id:%d", p_cmd->p_attr_list[xx]); - } -#endif - } - } -#if (BT_USE_TRACES == TRUE) - else - { - AVRC_TRACE_ERROR1("attr_count:%d, NULL p_attr_list", p_cmd->attr_count); - } -#endif - } - UINT16_TO_BE_STREAM(p_len, len); - - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - -/******************************************************************************* -** -** Function avrc_bld_search_cmd -** -** Description This function builds the Search command. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_search_cmd (tAVRC_SEARCH_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT16 len; - - AVRC_TRACE_API0("avrc_bld_search_cmd"); - if (!p_cmd->string.p_str) - { - AVRC_TRACE_ERROR0("null string"); - return AVRC_STS_BAD_PARAM; - } - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 1; /* pdu */ - /* variable lenth */ - len = p_cmd->string.str_len + 4; - UINT16_TO_BE_STREAM(p_data, len); - - UINT16_TO_BE_STREAM(p_data, p_cmd->string.charset_id); - UINT16_TO_BE_STREAM(p_data, p_cmd->string.str_len); - ARRAY_TO_BE_STREAM(p_data, p_cmd->string.p_str, p_cmd->string.str_len); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - -/******************************************************************************* -** -** Function avrc_bld_play_item_cmd -** -** Description This function builds the Play Item command. -** -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_play_item_cmd (tAVRC_PLAY_ITEM_CMD *p_cmd, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - AVRC_TRACE_API0("avrc_bld_play_item_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - - /* fixed lenth - scope(1) + uid(8) + uid_counter(2) */ - UINT16_TO_BE_STREAM(p_data, 11); - - UINT8_TO_BE_STREAM(p_data, p_cmd->scope); - ARRAY_TO_BE_STREAM(p_data, p_cmd->uid, AVRC_UID_SIZE); - UINT16_TO_BE_STREAM(p_data, p_cmd->uid_counter); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_add_to_now_playing_cmd -** -** Description This function builds the Add to Now Playing command. -** -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_add_to_now_playing_cmd (tAVRC_ADD_TO_PLAY_CMD *p_cmd, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_add_to_now_playing_cmd"); - return avrc_bld_play_item_cmd((tAVRC_PLAY_ITEM_CMD *)p_cmd, p_pkt); -} - -#endif /* AVRC_ADV_CTRL_INCLUDED=TRUE */ - -/******************************************************************************* -** -** Function avrc_bld_init_cmd_buffer -** -** Description This function initializes the command buffer based on PDU -** -** Returns NULL, if no GKI buffer or failure to build the message. -** Otherwise, the GKI buffer that contains the initialized message. -** -*******************************************************************************/ -static BT_HDR *avrc_bld_init_cmd_buffer(tAVRC_COMMAND *p_cmd) -{ - UINT16 offset, chnl = AVCT_DATA_CTRL, len=AVRC_META_CMD_POOL_SIZE; - BT_HDR *p_pkt=NULL; - UINT8 opcode; - - opcode = avrc_opcode_from_pdu(p_cmd->pdu); - AVRC_TRACE_API2("avrc_bld_init_cmd_buffer: pdu=%x, opcode=%x", p_cmd->pdu, opcode); - - switch (opcode) - { -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_OP_BROWSE: - chnl = AVCT_DATA_BROWSE; - offset = AVCT_BROWSE_OFFSET; - len = AVRC_BROWSE_POOL_SIZE; - break; -#endif /* AVCT_BROWSE_INCLUDED */ - - case AVRC_OP_PASS_THRU: - offset = AVRC_MSG_PASS_THRU_OFFSET; - break; - - case AVRC_OP_VENDOR: - offset = AVRC_MSG_VENDOR_OFFSET; - break; - } - - /* allocate and initialize the buffer */ - p_pkt = (BT_HDR *)GKI_getbuf(len); - if (p_pkt) - { - UINT8 *p_data, *p_start; - - p_pkt->layer_specific = chnl; - p_pkt->event = opcode; - p_pkt->offset = offset; - p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_start = p_data; - - /* pass thru - group navigation - has a two byte op_id, so dont do it here */ - if (opcode != AVRC_OP_PASS_THRU) - *p_data++ = p_cmd->pdu; - - switch (opcode) - { - case AVRC_OP_VENDOR: - /* reserved 0, packet_type 0 */ - UINT8_TO_BE_STREAM(p_data, 0); - /* continue to the next "case to add length */ -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_OP_BROWSE: -#endif - /* add fixed lenth - 0 */ - UINT16_TO_BE_STREAM(p_data, 0); - break; - } - - p_pkt->len = (p_data - p_start); - } - p_cmd->cmd.opcode = opcode; - return p_pkt; -} - -/******************************************************************************* -** -** Function AVRC_BldCommand -** -** Description This function builds the given AVRCP command to the given -** GKI buffer -** -** Returns AVRC_STS_NO_ERROR, if the command is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -tAVRC_STS AVRC_BldCommand( tAVRC_COMMAND *p_cmd, BT_HDR **pp_pkt) -{ - tAVRC_STS status = AVRC_STS_BAD_PARAM; - BT_HDR *p_pkt; - BOOLEAN alloc = FALSE; - - AVRC_TRACE_API2("AVRC_BldCommand: pdu=%x status=%x", p_cmd->cmd.pdu, p_cmd->cmd.status); - if (!p_cmd || !pp_pkt) - { - AVRC_TRACE_API2("AVRC_BldCommand. Invalid parameters passed. p_cmd=%p, pp_pkt=%p", p_cmd, pp_pkt); - return AVRC_STS_BAD_PARAM; - } - - if (*pp_pkt == NULL) - { - if ((*pp_pkt = avrc_bld_init_cmd_buffer(p_cmd)) == NULL) - { - AVRC_TRACE_API0("AVRC_BldCommand: Failed to initialize command buffer"); - return AVRC_STS_INTERNAL_ERR; - } - alloc = TRUE; - } - status = AVRC_STS_NO_ERROR; - p_pkt = *pp_pkt; - - switch (p_cmd->pdu) - { - case AVRC_PDU_NEXT_GROUP: /* 0x00 */ - case AVRC_PDU_PREV_GROUP: /* 0x01 */ - status = avrc_bld_group_navigation_cmd (p_cmd->pdu, p_pkt); - break; - - case AVRC_PDU_GET_CAPABILITIES: - status = avrc_bld_get_capability_cmd(&p_cmd->get_caps, p_pkt); - break; - - case AVRC_PDU_LIST_PLAYER_APP_ATTR: - status = avrc_bld_list_app_settings_attr_cmd(&p_cmd->list_app_attr, p_pkt); - break; - - case AVRC_PDU_LIST_PLAYER_APP_VALUES: - status = avrc_bld_list_app_settings_values_cmd(&p_cmd->list_app_values, p_pkt); - break; - - case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: - status = avrc_bld_get_cur_app_setting_value_cmd(&p_cmd->get_cur_app_val, p_pkt); - break; - - case AVRC_PDU_SET_PLAYER_APP_VALUE: - status = avrc_bld_set_app_setting_value_cmd(&p_cmd->set_app_val, p_pkt); - break; - - case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: - status = avrc_bld_get_app_setting_attr_text_cmd(&p_cmd->get_app_attr_txt, p_pkt); - break; - - case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: - status = avrc_bld_get_app_setting_value_text_cmd(&p_cmd->get_app_val_txt, p_pkt); - break; - - case AVRC_PDU_INFORM_DISPLAY_CHARSET: - status = avrc_bld_inform_charset_cmd(&p_cmd->inform_charset, p_pkt); - break; - - case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: - status = avrc_bld_inform_battery_status_cmd(&p_cmd->inform_battery_status, p_pkt); - break; - - case AVRC_PDU_GET_ELEMENT_ATTR: - status = avrc_bld_get_elem_attrs_cmd(&p_cmd->get_elem_attrs, p_pkt); - break; - - case AVRC_PDU_GET_PLAY_STATUS: - status = avrc_bld_get_play_status_cmd(&p_cmd->get_play_status, p_pkt); - break; - - case AVRC_PDU_REGISTER_NOTIFICATION: - status = avrc_bld_notify_cmd(&p_cmd->reg_notif, p_pkt); - break; - - case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ - status = avrc_bld_next_cmd(&p_cmd->continu, p_pkt); - break; - - case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ - status = avrc_bld_next_cmd(&p_cmd->abort, p_pkt); - break; - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - status = avrc_bld_set_abs_volume_cmd(&p_cmd->volume, p_pkt); - break; - - case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ - status = avrc_bld_set_addr_player_cmd(&p_cmd->addr_player, p_pkt); - break; - - case AVRC_PDU_PLAY_ITEM: /* 0x74 */ - status = avrc_bld_play_item_cmd(&p_cmd->play_item, p_pkt); - break; - - case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ - status = avrc_bld_add_to_now_playing_cmd(&p_cmd->add_to_play, p_pkt); - break; - -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_PDU_SET_BROWSED_PLAYER: /* 0x70 */ - status = avrc_bld_set_browsed_player_cmd(&p_cmd->br_player, p_pkt); - break; - - case AVRC_PDU_GET_FOLDER_ITEMS: /* 0x71 */ - status = avrc_bld_get_folder_items_cmd(&p_cmd->get_items, p_pkt); - break; - - case AVRC_PDU_CHANGE_PATH: /* 0x72 */ - status = avrc_bld_change_path_cmd(&p_cmd->chg_path, p_pkt); - break; - - case AVRC_PDU_GET_ITEM_ATTRIBUTES: /* 0x73 */ - status = avrc_bld_get_item_attrs_cmd(&p_cmd->get_attrs, p_pkt); - break; - - case AVRC_PDU_SEARCH: /* 0x80 */ - status = avrc_bld_search_cmd(&p_cmd->search, p_pkt); - break; -#endif -#endif - - } - - if (alloc && (status != AVRC_STS_NO_ERROR) ) - { - GKI_freebuf(p_pkt); - *pp_pkt = NULL; - } - AVRC_TRACE_API1("AVRC_BldCommand: returning %d", status); - return status; -} -#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ - diff --git a/stack/avrc/avrc_bld_tg.c b/stack/avrc/avrc_bld_tg.c deleted file mode 100644 index 667499e..0000000 --- a/stack/avrc/avrc_bld_tg.c +++ /dev/null @@ -1,1547 +0,0 @@ -/***************************************************************************** -** -** Name: avrc_bld_tg.c -** -** Description:Interface to AVRCP build message functions for the Target Role -** -** Copyright (c) 2008-2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "gki.h" -#include "avrc_api.h" -#include "avrc_defs.h" -#include "avrc_int.h" - -/***************************************************************************** -** Global data -*****************************************************************************/ -#if (AVRC_METADATA_INCLUDED == TRUE) - -/******************************************************************************* -** -** Function avrc_bld_get_capability_rsp -** -** Description This function builds the Get Capability response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_capability_rsp (tAVRC_GET_CAPS_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start, *p_len, *p_count; - UINT16 len = 0; - UINT8 xx; - UINT32 *p_company_id; - UINT8 *p_event_id; - tAVRC_STS status = AVRC_STS_NO_ERROR; - - if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id))) - { - AVRC_TRACE_ERROR1("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", p_rsp); - status = AVRC_STS_BAD_PARAM; - return status; - } - - AVRC_TRACE_API0("avrc_bld_get_capability_rsp"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - UINT8_TO_BE_STREAM(p_data, p_rsp->capability_id); - p_count = p_data; - - if (len == 0) - { - *p_count = p_rsp->count; - p_data++; - len = 2; /* move past the capability_id and count */ - } - else - { - p_data = p_start + p_pkt->len; - *p_count += p_rsp->count; - } - - if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID) - { - p_company_id = p_rsp->param.company_id; - for (xx=0; xx< p_rsp->count; xx++) - { - UINT24_TO_BE_STREAM(p_data, p_company_id[xx]); - } - len += p_rsp->count * 3; - } - else - { - p_event_id = p_rsp->param.event_id; - *p_count = 0; - for (xx=0; xx< p_rsp->count; xx++) - { - if (AVRC_IS_VALID_EVENT_ID(p_event_id[xx])) - { - (*p_count)++; - UINT8_TO_BE_STREAM(p_data, p_event_id[xx]); - } - } - len += (*p_count); - } - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - status = AVRC_STS_NO_ERROR; - - return status; -} - -/******************************************************************************* -** -** Function avrc_bld_list_app_settings_attr_rsp -** -** Description This function builds the List Application Settings Attribute -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_list_app_settings_attr_rsp (tAVRC_LIST_APP_ATTR_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start, *p_len, *p_num; - UINT16 len = 0; - UINT8 xx; - - AVRC_TRACE_API0("avrc_bld_list_app_settings_attr_rsp"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - p_num = p_data; - if (len == 0) - { - /* first time initialize the attribute count */ - *p_num = 0; - p_data++; - } - else - { - p_data = p_start + p_pkt->len; - } - - for (xx=0; xx<p_rsp->num_attr; xx++) - { - if(AVRC_IsValidPlayerAttr(p_rsp->attrs[xx])) - { - (*p_num)++; - UINT8_TO_BE_STREAM(p_data, p_rsp->attrs[xx]); - } - } - - len = *p_num + 1; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_list_app_settings_values_rsp -** -** Description This function builds the List Application Setting Values -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_list_app_settings_values_rsp (tAVRC_LIST_APP_VALUES_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start, *p_len, *p_num; - UINT8 xx; - UINT16 len; - - AVRC_TRACE_API0("avrc_bld_list_app_settings_values_rsp"); - - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - /* get the existing length, if any, and also the num attributes */ - BE_STREAM_TO_UINT16(len, p_data); - p_num = p_data; - /* first time initialize the attribute count */ - if (len == 0) - { - *p_num = p_rsp->num_val; - p_data++; - } - else - { - p_data = p_start + p_pkt->len; - *p_num += p_rsp->num_val; - } - - - for (xx=0; xx<p_rsp->num_val; xx++) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->vals[xx]); - } - - len = *p_num + 1; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_get_cur_app_setting_value_rsp -** -** Description This function builds the Get Current Application Setting Value -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_cur_app_setting_value_rsp (tAVRC_GET_CUR_APP_VALUE_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start, *p_len, *p_count; - UINT16 len; - UINT8 xx; - - if (!p_rsp->p_vals) - { - AVRC_TRACE_ERROR0("avrc_bld_get_cur_app_setting_value_rsp NULL parameter"); - return AVRC_STS_BAD_PARAM; - } - - AVRC_TRACE_API0("avrc_bld_get_cur_app_setting_value_rsp"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - p_count = p_data; - if (len == 0) - { - /* first time initialize the attribute count */ - *p_count = 0; - p_data++; - } - else - { - p_data = p_start + p_pkt->len; - } - - for (xx=0; xx<p_rsp->num_val; xx++) - { - if (avrc_is_valid_player_attrib_value(p_rsp->p_vals[xx].attr_id, p_rsp->p_vals[xx].attr_val)) - { - (*p_count)++; - UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_id); - UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_val); - } - } - len = ((*p_count) << 1) + 1; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_set_app_setting_value_rsp -** -** Description This function builds the Set Application Setting Value -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_set_app_setting_value_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - /* nothing to be added. */ - AVRC_TRACE_API0("avrc_bld_set_app_setting_value_rsp"); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_app_setting_text_rsp -** -** Description This function builds the Get Application Settings Attribute Text -** or Get Application Settings Value Text response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_app_setting_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start, *p_len, *p_count; - UINT16 len, len_left; - UINT8 xx; - tAVRC_STS sts = AVRC_STS_NO_ERROR; - UINT8 num_added = 0; - - if (!p_rsp->p_attrs) - { - AVRC_TRACE_ERROR0("avrc_bld_app_setting_text_rsp NULL parameter"); - return AVRC_STS_BAD_PARAM; - } - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - len_left = GKI_get_buf_size(p_pkt) - BT_HDR_SIZE - p_pkt->offset - p_pkt->len; - - BE_STREAM_TO_UINT16(len, p_data); - p_count = p_data; - - if (len == 0) - { - *p_count = 0; - p_data++; - } - else - { - p_data = p_start + p_pkt->len; - } - - for (xx=0; xx<p_rsp->num_attr; xx++) - { - if (len_left < (p_rsp->p_attrs[xx].str_len + 4)) - { - AVRC_TRACE_ERROR3("avrc_bld_app_setting_text_rsp out of room (str_len:%d, left:%d)", - xx, p_rsp->p_attrs[xx].str_len, len_left); - p_rsp->num_attr = num_added; - sts = AVRC_STS_INTERNAL_ERR; - break; - } - if ( !p_rsp->p_attrs[xx].str_len || !p_rsp->p_attrs[xx].p_str ) - { - AVRC_TRACE_ERROR1("avrc_bld_app_setting_text_rsp NULL attr text[%d]", xx); - continue; - } - UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].attr_id); - UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].charset_id); - UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].str_len); - ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].p_str, p_rsp->p_attrs[xx].str_len); - (*p_count)++; - num_added++; - } - len = p_data - p_count; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return sts; -} - -/******************************************************************************* -** -** Function avrc_bld_get_app_setting_attr_text_rsp -** -** Description This function builds the Get Application Setting Attribute Text -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_app_setting_attr_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_get_app_setting_attr_text_rsp"); - return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); -} - -/******************************************************************************* -** -** Function avrc_bld_get_app_setting_value_text_rsp -** -** Description This function builds the Get Application Setting Value Text -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_app_setting_value_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_get_app_setting_value_text_rsp"); - return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); -} - -/******************************************************************************* -** -** Function avrc_bld_inform_charset_rsp -** -** Description This function builds the Inform Displayable Character Set -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_inform_charset_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - /* nothing to be added. */ - AVRC_TRACE_API0("avrc_bld_inform_charset_rsp"); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_inform_battery_status_rsp -** -** Description This function builds the Inform Battery Status -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_inform_battery_status_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - /* nothing to be added. */ - AVRC_TRACE_API0("avrc_bld_inform_battery_status_rsp"); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_get_elem_attrs_rsp -** -** Description This function builds the Get Element Attributes -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_elem_attrs_rsp (tAVRC_GET_ELEM_ATTRS_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start, *p_len, *p_count; - UINT16 len; - UINT8 xx; - - AVRC_TRACE_API0("avrc_bld_get_elem_attrs_rsp"); - if (!p_rsp->p_attrs) - { - AVRC_TRACE_ERROR0("avrc_bld_get_elem_attrs_rsp NULL parameter"); - return AVRC_STS_BAD_PARAM; - } - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - p_count = p_data; - - if (len == 0) - { - *p_count = 0; - p_data++; - } - else - { - p_data = p_start + p_pkt->len; - } - - for (xx=0; xx<p_rsp->num_attr; xx++) - { - if (!AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_rsp->p_attrs[xx].attr_id)) - { - AVRC_TRACE_ERROR2("avrc_bld_get_elem_attrs_rsp invalid attr id[%d]: %d", xx, p_rsp->p_attrs[xx].attr_id); - continue; - } - if ( !p_rsp->p_attrs[xx].name.p_str ) - { - p_rsp->p_attrs[xx].name.str_len = 0; - } - UINT32_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].attr_id); - UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.p_str, p_rsp->p_attrs[xx].name.str_len); - (*p_count)++; - } - len = p_data - p_count; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_get_play_status_rsp -** -** Description This function builds the Get Play Status -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_get_play_status_rsp (tAVRC_GET_PLAY_STATUS_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - AVRC_TRACE_API0("avrc_bld_get_play_status_rsp"); - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; - - /* add fixed lenth - song len(4) + song position(4) + status(1) */ - UINT16_TO_BE_STREAM(p_data, 9); - UINT32_TO_BE_STREAM(p_data, p_rsp->song_len); - UINT32_TO_BE_STREAM(p_data, p_rsp->song_pos); - UINT8_TO_BE_STREAM(p_data, p_rsp->play_status); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_notify_rsp -** -** Description This function builds the Notification response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_notify_rsp (tAVRC_REG_NOTIF_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len; - UINT16 len = 0; - UINT8 xx; - tAVRC_STS status = AVRC_STS_NO_ERROR; - - AVRC_TRACE_API0("avrc_bld_notify_rsp"); - - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - p_data += 2; - - UINT8_TO_BE_STREAM(p_data, p_rsp->event_id); - switch (p_rsp->event_id) - { - case AVRC_EVT_PLAY_STATUS_CHANGE: /* 0x01 */ - /* p_rsp->param.play_status >= AVRC_PLAYSTATE_STOPPED is always TRUE */ - if ((p_rsp->param.play_status <= AVRC_PLAYSTATE_REV_SEEK) || - (p_rsp->param.play_status == AVRC_PLAYSTATE_ERROR) ) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.play_status); - len = 2; - } - else - { - AVRC_TRACE_ERROR0("bad play state"); - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_EVT_TRACK_CHANGE: /* 0x02 */ - ARRAY_TO_BE_STREAM(p_data, p_rsp->param.track, AVRC_UID_SIZE); - len = (UINT8)(AVRC_UID_SIZE + 1); - break; - - case AVRC_EVT_TRACK_REACHED_END: /* 0x03 */ - case AVRC_EVT_TRACK_REACHED_START: /* 0x04 */ -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_EVT_NOW_PLAYING_CHANGE: /* 0x09 */ - case AVRC_EVT_AVAL_PLAYERS_CHANGE: /* 0x0a */ -#endif - len = 1; - break; - - case AVRC_EVT_PLAY_POS_CHANGED: /* 0x05 */ - UINT32_TO_BE_STREAM(p_data, p_rsp->param.play_pos); - len = 5; - break; - - case AVRC_EVT_BATTERY_STATUS_CHANGE: /* 0x06 */ - if (AVRC_IS_VALID_BATTERY_STATUS(p_rsp->param.battery_status)) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.battery_status); - len = 2; - } - else - { - AVRC_TRACE_ERROR0("bad battery status"); - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_EVT_SYSTEM_STATUS_CHANGE: /* 0x07 */ - if (AVRC_IS_VALID_SYSTEM_STATUS(p_rsp->param.system_status)) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.system_status); - len = 2; - } - else - { - AVRC_TRACE_ERROR0("bad system status"); - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_EVT_APP_SETTING_CHANGE: /* 0x08 */ - if (p_rsp->param.player_setting.num_attr > AVRC_MAX_APP_SETTINGS) - p_rsp->param.player_setting.num_attr = AVRC_MAX_APP_SETTINGS; - - if (p_rsp->param.player_setting.num_attr > 0) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.num_attr); - len = 2; - for (xx=0; xx<p_rsp->param.player_setting.num_attr; xx++) - { - if (avrc_is_valid_player_attrib_value(p_rsp->param.player_setting.attr_id[xx], p_rsp->param.player_setting.attr_value[xx])) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_id[xx]); - UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_value[xx]); - } - else - { - AVRC_TRACE_ERROR0("bad player app seeting attribute or value"); - status = AVRC_STS_BAD_PARAM; - break; - } - len += 2; - } - } - else - status = AVRC_STS_BAD_PARAM; - break; - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_EVT_ADDR_PLAYER_CHANGE: /* 0x0b */ - UINT16_TO_BE_STREAM(p_data, p_rsp->param.addr_player.player_id); /* player_id */ - UINT16_TO_BE_STREAM(p_data, p_rsp->param.addr_player.uid_counter); /* uid counter */ - len = 5; - break; - - case AVRC_EVT_UIDS_CHANGE: /* 0x0c */ - UINT16_TO_BE_STREAM(p_data, p_rsp->param.uid_counter); /* uid counter */ - len = 3; - break; - - case AVRC_EVT_VOLUME_CHANGE: /* 0x0d */ - UINT8_TO_BE_STREAM(p_data, (UINT8)(p_rsp->param.volume&AVRC_MAX_VOLUME)); - len = 2; - break; -#endif - - default: - status = AVRC_STS_BAD_PARAM; - AVRC_TRACE_ERROR0("unknown event_id"); - } - - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return status; -} - -/******************************************************************************* -** -** Function avrc_bld_next_rsp -** -** Description This function builds the Request Continue or Abort -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_next_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - /* nothing to be added. */ - AVRC_TRACE_API0("avrc_bld_next_rsp"); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_group_navigation_rsp -** -** Description This function builds the Group Navigation -** response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -tAVRC_STS avrc_bld_group_navigation_rsp (UINT16 navi_id, BT_HDR *p_pkt) -{ - UINT8 *p_data; - - if (!AVRC_IS_VALID_GROUP(navi_id)) - { - AVRC_TRACE_ERROR1("avrc_bld_group_navigation_rsp bad navigation op id: %d", navi_id); - return AVRC_STS_BAD_PARAM; - } - - AVRC_TRACE_API0("avrc_bld_group_navigation_rsp"); - p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; - UINT16_TO_BE_STREAM(p_data, navi_id); - p_pkt->len = 2; - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_rejected_rsp -** -** Description This function builds the General Response response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_rejected_rsp( tAVRC_RSP *p_rsp, BT_HDR *p_pkt ) -{ - UINT8 *p_data, *p_start; -#if (AVCT_BROWSE_INCLUDED == TRUE) - UINT8 opcode = avrc_opcode_from_pdu(p_rsp->pdu); -#endif - - AVRC_TRACE_API2("avrc_bld_rejected_rsp: status=%d, pdu:x%x", p_rsp->status, p_rsp->pdu); - - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; -#if (AVCT_BROWSE_INCLUDED == TRUE) - if (opcode == AVRC_OP_BROWSE) - { - p_data = p_start + 1; - if (avrc_opcode_from_pdu(*p_start) != AVRC_OP_BROWSE) - { - /* if the given opcode is not recognized as a browsing command opcode, use general reject command */ - *p_start = AVRC_PDU_GENERAL_REJECT; - } - } - else -#endif - { - p_data = p_start + 2; - } - AVRC_TRACE_DEBUG1("pdu:x%x", *p_start); - - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - p_pkt->len = p_data - p_start; - - return AVRC_STS_NO_ERROR; -} - - -/***************************************************************************** -** the following commands are introduced in AVRCP 1.4 -*****************************************************************************/ - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) -/******************************************************************************* -** -** Function avrc_bld_ctrl_status_rsp -** -** Description This function builds the responses with a UINT8 parameter. -** -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_ctrl_status_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - - /* add fixed lenth - status(1) */ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} - -/******************************************************************************* -** -** Function avrc_bld_set_addr_player_rsp -** -** Description This function builds the Set Addresses Player response. -** -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_set_addr_player_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_set_addr_player_rsp"); - return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); -} - -/******************************************************************************* -** -** Function avrc_bld_set_abs_volume_rsp -** -** Description This function builds the Set Absolute Volume response. -** -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_set_abs_volume_rsp (tAVRC_SET_VOLUME_RSP *p_rsp, BT_HDR *p_pkt) -{ - p_rsp->status = (p_rsp->volume & AVRC_MAX_VOLUME); - AVRC_TRACE_API2("avrc_bld_set_abs_volume_rsp volume:%d, sts:%d", p_rsp->volume, p_rsp->status); - return avrc_bld_ctrl_status_rsp((tAVRC_RSP *)p_rsp, p_pkt); -} - - -/******************************************************************************* -** -** Function avrc_bld_set_browsed_player_rsp -** -** Description This function builds the Set Browsed Player response. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_set_browsed_player_rsp (tAVRC_SET_BR_PLAYER_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len, xx; - UINT16 len; - tAVRC_NAME *p_folders = p_rsp->p_folders; - UINT16 len_left; - UINT8 *p_num; - UINT16 mtu; - - AVRC_TRACE_API0("avrc_bld_set_browsed_player_rsp"); - /* make sure the given GKI buffer can accomodate this response */ - len_left = GKI_get_buf_size(p_pkt) - BT_HDR_SIZE; - p_data = (UINT8 *)(p_pkt + 1); - BE_STREAM_TO_UINT16 (mtu, p_data); - if (len_left > mtu) - { - len_left = mtu; - } - len_left = len_left - p_pkt->offset - p_pkt->len; - AVRC_TRACE_DEBUG2("len_left:%d, mtu:%d ", len_left, mtu); - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 1; /* pdu */ - - /* the existing len */ - BE_STREAM_TO_UINT16(len, p_data); - p_num = p_data + 9; - if (len == 0) - { - /* first time initialize the attribute count */ - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); - UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); - UINT16_TO_BE_STREAM(p_data, p_rsp->charset_id); - *p_num = 0; - p_data++; - len = 10; - len_left -= 12; /* assuming that we would never use a GKI buffer that is too small for headers */ - } - else - { - p_data = p_start + p_pkt->len; - } - - for (xx=0; (xx<p_rsp->folder_depth) && (len_left>(p_folders[xx].str_len + 2)); xx++) - { - (*p_num)++; - UINT16_TO_BE_STREAM(p_data, p_folders[xx].str_len); - ARRAY_TO_BE_STREAM(p_data, p_folders[xx].p_str, p_folders[xx].str_len); - len += (p_folders[xx].str_len + 2); - } - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - - -/******************************************************************************* -** -** Function avrc_bld_get_folder_items_rsp -** -** Description This function builds the Get Folder Items response. -** The error code is returned in *p_status. -** AVRC_STS_INTERNAL_ERR means no GKI buffers. -** Try again later or with smaller item_count -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** AVRC_STS_INTERNAL_ERR, if the given GKI buffer does not have enough room -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_get_folder_items_rsp (tAVRC_GET_ITEMS_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len, xx; - UINT16 len; - UINT16 item_len; - UINT8 *p_item_len, yy; - tAVRC_ITEM_PLAYER *p_player; - tAVRC_ITEM_FOLDER *p_folder; - tAVRC_ITEM_MEDIA *p_media; - tAVRC_ATTR_ENTRY *p_attr; - tAVRC_ITEM *p_item_list = p_rsp->p_item_list; - tAVRC_STS status = AVRC_STS_NO_ERROR; - UINT16 len_left; - UINT8 *p_num, *p; - UINT8 *p_item_start, *p_attr_count; - UINT16 item_count; - UINT16 mtu; - - AVRC_TRACE_API0("avrc_bld_get_folder_items_rsp"); - /* make sure the given GKI buffer can accomodate this response */ - len_left = GKI_get_buf_size(p_pkt) - BT_HDR_SIZE; - p = (UINT8 *)(p_pkt + 1); - BE_STREAM_TO_UINT16 (mtu, p); - if (len_left > mtu) - len_left = mtu; - len_left = len_left - p_pkt->offset - p_pkt->len; - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 1; /* pdu */ - - /* the existing len */ - BE_STREAM_TO_UINT16(len, p_data); - p_num = p_data + 3; - if (len == 0) - { - /* first time initialize the attribute count */ - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); - item_count = 0; - p_data+= 2; - len = 5; - len_left -= 5; - } - else - { - p_data = p_start + p_pkt->len; - p = p_num; - BE_STREAM_TO_UINT16 (item_count, p); - } - AVRC_TRACE_DEBUG3("len:%d, len_left:%d, num:%d", len, len_left, item_count); - - /* min len required = item_type(1) + item len(2) + min item (14) = 17 */ - for (xx=0; xx<p_rsp->item_count && len_left > 17; xx++) - { - p_item_start = p_data; - UINT8_TO_BE_STREAM(p_data, p_item_list[xx].item_type); - /* variable item lenth - save the location to add length */ - p_item_len = p_data; - p_data += 2; - item_len = 0; - len_left -= 3; /* item_type(1) + item len(2) */ - switch (p_item_list[xx].item_type) - { - case AVRC_ITEM_PLAYER: - /* min len required: 2 + 1 + 4 + 1 + 16 + 2 + 2 = 30 + str_len */ - p_player = &p_item_list[xx].u.player; - item_len = AVRC_FEATURE_MASK_SIZE + p_player->name.str_len + 12; - if ((len_left > item_len) && - p_player->name.p_str && - (p_player->major_type & AVRC_MJ_TYPE_INVALID) == 0 && - (p_player->sub_type & AVRC_SUB_TYPE_INVALID) == 0 && - (p_player->play_status <= AVRC_PLAYSTATE_REV_SEEK || p_player->play_status == AVRC_PLAYSTATE_ERROR) ) - { - UINT16_TO_BE_STREAM(p_data, p_player->player_id); - UINT8_TO_BE_STREAM(p_data, p_player->major_type); - UINT32_TO_BE_STREAM(p_data, p_player->sub_type); - UINT8_TO_BE_STREAM(p_data, p_player->play_status); - ARRAY_TO_BE_STREAM(p_data, p_player->features, AVRC_FEATURE_MASK_SIZE); - UINT16_TO_BE_STREAM(p_data, p_player->name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_player->name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_player->name.p_str, p_player->name.str_len); - } - else - { - p_data = p_item_start; - } - break; - - case AVRC_ITEM_FOLDER: - /* min len required: 8 + 1 + 1 + 2 + 2 = 14 + str_len */ - p_folder = &p_item_list[xx].u.folder; - item_len = AVRC_UID_SIZE + p_folder->name.str_len + 6; - if ((len_left > item_len) && - p_folder->name.p_str && - p_folder->type <= AVRC_FOLDER_TYPE_YEARS && - p_folder->playable <= TRUE) - { - ARRAY_TO_BE_STREAM(p_data, p_folder->uid, AVRC_UID_SIZE); - UINT8_TO_BE_STREAM(p_data, p_folder->type); - UINT8_TO_BE_STREAM(p_data, p_folder->playable); - UINT16_TO_BE_STREAM(p_data, p_folder->name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_folder->name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_folder->name.p_str, p_folder->name.str_len); - } - else - { - p_data = p_item_start; - } - break; - - case AVRC_ITEM_MEDIA: - /* min len required: 8 + 1 + 2 + 2 + 1 = 14 + str_len */ - p_media = &p_item_list[xx].u.media; - item_len = AVRC_UID_SIZE + p_media->name.str_len + 6; - if ((len_left > item_len) && - p_media->name.p_str && - p_media->type <= AVRC_MEDIA_TYPE_VIDEO) - { - ARRAY_TO_BE_STREAM(p_data, p_media->uid, AVRC_UID_SIZE); - UINT8_TO_BE_STREAM(p_data, p_media->type); - UINT16_TO_BE_STREAM(p_data, p_media->name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_media->name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_media->name.p_str, p_media->name.str_len); - p_attr_count = p_data++; - *p_attr_count = 0; - len_left -= item_len; - if (p_media->attr_count>0) - { - p_attr = p_media->p_attr_list; - for (yy=0; yy<p_media->attr_count && len_left > 8; yy++) - { - if (p_attr[yy].name.p_str && - AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_attr[yy].attr_id) && - (len_left >= (p_attr[yy].name.str_len + 8)) ) - { - (*p_attr_count) ++; - UINT32_TO_BE_STREAM(p_data, p_attr[yy].attr_id); - UINT16_TO_BE_STREAM(p_data, p_attr[yy].name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_attr[yy].name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_attr[yy].name.p_str, p_attr[yy].name.str_len); - item_len += (p_attr[yy].name.str_len + 8); - len_left -= (p_attr[yy].name.str_len + 8); - } - } - } - } - else - { - p_data = p_item_start; - } - break; - } /* switch item_type */ - - if (p_item_start != p_data) - { - /* successfully added the item */ - item_count++; - /* fill in variable item lenth */ - UINT16_TO_BE_STREAM(p_item_len, item_len); - } - else - { - /* some item is not added properly - set an error status */ - if (len_left > item_len) - status = AVRC_STS_INTERNAL_ERR; - else - status = AVRC_STS_BAD_PARAM; - } - - len += item_len; - len += 3; /* the item_type(1) and item_len(2) */ - AVRC_TRACE_DEBUG4("len:%d, len_left:%d, num:%d, item_len:%d", len, len_left, item_count, item_len); - } /* for item_count */ - - UINT16_TO_BE_STREAM(p_num, item_count); - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - if (p_rsp->item_count != xx) - { - p_rsp->item_count = xx; - if (status == AVRC_STS_NO_ERROR) - status = AVRC_STS_INTERNAL_ERR; - } - - return status; -} -#endif - - -/******************************************************************************* -** -** Function avrc_bld_change_path_rsp -** -** Description This function builds the Change Path response. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_change_path_rsp (tAVRC_CHG_PATH_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 1; /* pdu */ - /* add fixed lenth - status(1) + num_items(4) */ - UINT16_TO_BE_STREAM(p_data, 5); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - - -/******************************************************************************* -** -** Function avrc_bld_get_item_attrs_rsp -** -** Description This function builds the Get Item Attributes response. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** AVRC_STS_INTERNAL_ERR, if the given GKI buffer does not have enough room -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_get_item_attrs_rsp (tAVRC_GET_ATTRS_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start; - UINT8 *p_len, xx; - UINT16 len, len_left; - UINT8 *p_num; - UINT16 mtu; - - AVRC_TRACE_API0("avrc_bld_get_item_attrs_rsp"); - /* calculate the GKI buffer size needed and validate the parameters */ - if (!p_rsp->p_attr_list) - { - AVRC_TRACE_ERROR0("NULL p_attr_list"); - return AVRC_STS_BAD_PARAM; - } - - /* check the length before adding the attr to the message */ - len = 2; - for (xx=0; xx<p_rsp->attr_count; xx++) - { - if(p_rsp->p_attr_list[xx].name.p_str == 0 || - !AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_rsp->p_attr_list[xx].attr_id)) - { - AVRC_TRACE_ERROR2("[%d] NULL p_attr_list str or bad attr_id:%d", xx, p_rsp->p_attr_list[xx].attr_id); - return AVRC_STS_BAD_PARAM; - } - len += (p_rsp->p_attr_list[xx].name.str_len + 8); - } - len_left = GKI_get_buf_size(p_pkt) - BT_HDR_SIZE; - p_data = (UINT8 *)(p_pkt + 1); - BE_STREAM_TO_UINT16 (mtu, p_data); - if (len_left > mtu) - { - len_left = mtu; - } - len_left = len_left - p_pkt->offset - p_pkt->len; - - AVRC_TRACE_DEBUG3("len_left:%d, mtu:%d len needed:%d", len_left, mtu, len); - if (len_left < 11) /* 11 is 4/attr_id + 2/charset_id + 2/str_len + 3/first timer/attr count & len */ - { - return AVRC_STS_INTERNAL_ERR; - } - if (len > len_left) - { - AVRC_TRACE_ERROR0("The GKI buffer does not have enough room to hold the given data."); - } - - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 1; /* pdu */ - - /* the existing len */ - BE_STREAM_TO_UINT16(len, p_data); - p_num = p_data + 1; - if (len == 0) - { - /* first time initialize the attribute count */ - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - *p_num = 0; - p_data++; - len = 2; - len_left -= 3; - } - else - { - p_data = p_start + p_pkt->len; - } - - - for (xx=0; (xx<p_rsp->attr_count) && (len_left>9); xx++) - { - (*p_num)++; - UINT32_TO_BE_STREAM(p_data, p_rsp->p_attr_list[xx].attr_id); - UINT16_TO_BE_STREAM(p_data, p_rsp->p_attr_list[xx].name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_rsp->p_attr_list[xx].name.str_len); - len_left -= 8; - if (p_rsp->p_attr_list[xx].name.str_len > len_left) - p_rsp->p_attr_list[xx].name.str_len = len_left; - ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attr_list[xx].name.p_str, p_rsp->p_attr_list[xx].name.str_len); - len_left -= p_rsp->p_attr_list[xx].name.str_len; - len += (p_rsp->p_attr_list[xx].name.str_len + 8); - } - - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - - -/******************************************************************************* -** -** Function avrc_bld_search_rsp -** -** Description This function builds the Search response. -** -** This message goes through the Browsing channel and is -** valid only when AVCT_BROWSE_INCLUDED compile option is TRUE -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -#if (AVCT_BROWSE_INCLUDED == TRUE) -static tAVRC_STS avrc_bld_search_rsp (tAVRC_SEARCH_RSP *p_rsp, BT_HDR *p_pkt) -{ - UINT8 *p_data, *p_start, *p_len; - - AVRC_TRACE_API0("avrc_bld_search_rsp"); - /* get the existing length, if any, and also the num attributes */ - p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 1; /* pdu */ - - /* add fixed lenth - status(1) + uid_counter(2) + num_items(4) */ - UINT16_TO_BE_STREAM(p_data, 7); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); - UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; -} -#endif - - -/******************************************************************************* -** -** Function avrc_bld_play_item_rsp -** -** Description This function builds the Play Item response. -** -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_play_item_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_play_item_rsp"); - return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); -} - - -/******************************************************************************* -** -** Function avrc_bld_add_to_now_playing_rsp -** -** Description This function builds the Add to Now Playing response. -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -static tAVRC_STS avrc_bld_add_to_now_playing_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - AVRC_TRACE_API0("avrc_bld_add_to_now_playing_rsp"); - return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); -} - -#endif /* AVRC_ADV_CTRL_INCLUDED=TRUE */ - -/******************************************************************************* -** -** Function avrc_bld_init_rsp_buffer -** -** Description This function initializes the response buffer based on PDU -** -** Returns NULL, if no GKI buffer or failure to build the message. -** Otherwise, the GKI buffer that contains the initialized message. -** -*******************************************************************************/ -static BT_HDR *avrc_bld_init_rsp_buffer(tAVRC_RESPONSE *p_rsp) -{ - UINT16 offset, chnl = AVCT_DATA_CTRL, len=AVRC_META_CMD_POOL_SIZE; - BT_HDR *p_pkt=NULL; - UINT8 opcode = avrc_opcode_from_pdu(p_rsp->pdu); - - AVRC_TRACE_API3("avrc_bld_init_rsp_buffer: pdu=%x, opcode=%x/%x", p_rsp->pdu, opcode, p_rsp->rsp.opcode); - if (opcode != p_rsp->rsp.opcode && p_rsp->rsp.status != AVRC_STS_NO_ERROR && avrc_is_valid_opcode(p_rsp->rsp.opcode)) - { - opcode = p_rsp->rsp.opcode; - AVRC_TRACE_API1("opcode=%x", opcode); - } - - switch (opcode) - { -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_OP_BROWSE: - chnl = AVCT_DATA_BROWSE; - offset = AVCT_BROWSE_OFFSET; - len = AVRC_BROWSE_POOL_SIZE; - break; -#endif /* AVCT_BROWSE_INCLUDED */ - - case AVRC_OP_PASS_THRU: - offset = AVRC_MSG_PASS_THRU_OFFSET; - break; - - case AVRC_OP_VENDOR: - offset = AVRC_MSG_VENDOR_OFFSET; - if (p_rsp->pdu == AVRC_PDU_GET_ELEMENT_ATTR) - len = AVRC_BROWSE_POOL_SIZE; - break; - } - - /* allocate and initialize the buffer */ - p_pkt = (BT_HDR *)GKI_getbuf(len); - if (p_pkt) - { - UINT8 *p_data, *p_start; - - p_pkt->layer_specific = chnl; - p_pkt->event = opcode; - p_pkt->offset = offset; - p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - p_start = p_data; - - /* pass thru - group navigation - has a two byte op_id, so dont do it here */ - if (opcode != AVRC_OP_PASS_THRU) - *p_data++ = p_rsp->pdu; - - switch (opcode) - { - case AVRC_OP_VENDOR: - /* reserved 0, packet_type 0 */ - UINT8_TO_BE_STREAM(p_data, 0); - /* continue to the next "case to add length */ -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_OP_BROWSE: -#endif - /* add fixed lenth - 0 */ - UINT16_TO_BE_STREAM(p_data, 0); - break; - } - - p_pkt->len = (p_data - p_start); - } - p_rsp->rsp.opcode = opcode; - return p_pkt; -} - -/******************************************************************************* -** -** Function AVRC_BldResponse -** -** Description This function builds the given AVRCP response to the given -** GKI buffer -** -** Returns AVRC_STS_NO_ERROR, if the response is built successfully -** Otherwise, the error code. -** -*******************************************************************************/ -tAVRC_STS AVRC_BldResponse( UINT8 handle, tAVRC_RESPONSE *p_rsp, BT_HDR **pp_pkt) -{ - tAVRC_STS status = AVRC_STS_BAD_PARAM; - BT_HDR *p_pkt; - BOOLEAN alloc = FALSE; -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) - UINT8 *p; - UINT16 peer_mtu; -#endif - - if (!p_rsp || !pp_pkt) - { - AVRC_TRACE_API2("AVRC_BldResponse. Invalid parameters passed. p_rsp=%p, pp_pkt=%p", p_rsp, pp_pkt); - return AVRC_STS_BAD_PARAM; - } - - if (*pp_pkt == NULL) - { - if ((*pp_pkt = avrc_bld_init_rsp_buffer(p_rsp)) == NULL) - { - AVRC_TRACE_API0("AVRC_BldResponse: Failed to initialize response buffer"); - return AVRC_STS_INTERNAL_ERR; - } -#if ((AVRC_ADV_CTRL_INCLUDED == TRUE) && (AVCT_BROWSE_INCLUDED == TRUE)) - if ((*pp_pkt)->layer_specific == AVCT_DATA_BROWSE) - { - p = (UINT8 *)((*pp_pkt) + 1); - peer_mtu = AVCT_GetBrowseMtu(handle) - AVCT_HDR_LEN_SINGLE; - UINT16_TO_BE_STREAM(p, peer_mtu); - } -#endif - alloc = TRUE; - } - status = AVRC_STS_NO_ERROR; - p_pkt = *pp_pkt; - - AVRC_TRACE_API2("AVRC_BldResponse: pdu=%x status=%x", p_rsp->rsp.pdu, p_rsp->rsp.status); - if (p_rsp->rsp.status != AVRC_STS_NO_ERROR) - { - return( avrc_bld_rejected_rsp(&p_rsp->rsp, p_pkt) ); - } - - switch (p_rsp->pdu) - { - case AVRC_PDU_NEXT_GROUP: - case AVRC_PDU_PREV_GROUP: - status = avrc_bld_group_navigation_rsp(p_rsp->pdu, p_pkt); - break; - - case AVRC_PDU_GET_CAPABILITIES: - status = avrc_bld_get_capability_rsp(&p_rsp->get_caps, p_pkt); - break; - - case AVRC_PDU_LIST_PLAYER_APP_ATTR: - status = avrc_bld_list_app_settings_attr_rsp(&p_rsp->list_app_attr, p_pkt); - break; - - case AVRC_PDU_LIST_PLAYER_APP_VALUES: - status = avrc_bld_list_app_settings_values_rsp(&p_rsp->list_app_values, p_pkt); - break; - - case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: - status = avrc_bld_get_cur_app_setting_value_rsp(&p_rsp->get_cur_app_val, p_pkt); - break; - - case AVRC_PDU_SET_PLAYER_APP_VALUE: - status = avrc_bld_set_app_setting_value_rsp(&p_rsp->set_app_val, p_pkt); - break; - - case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: - status = avrc_bld_get_app_setting_attr_text_rsp(&p_rsp->get_app_attr_txt, p_pkt); - break; - - case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: - status = avrc_bld_get_app_setting_value_text_rsp(&p_rsp->get_app_val_txt, p_pkt); - break; - - case AVRC_PDU_INFORM_DISPLAY_CHARSET: - status = avrc_bld_inform_charset_rsp(&p_rsp->inform_charset, p_pkt); - break; - - case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: - status = avrc_bld_inform_battery_status_rsp(&p_rsp->inform_battery_status, p_pkt); - break; - - case AVRC_PDU_GET_ELEMENT_ATTR: - status = avrc_bld_get_elem_attrs_rsp(&p_rsp->get_elem_attrs, p_pkt); - break; - - case AVRC_PDU_GET_PLAY_STATUS: - status = avrc_bld_get_play_status_rsp(&p_rsp->get_play_status, p_pkt); - break; - - case AVRC_PDU_REGISTER_NOTIFICATION: - status = avrc_bld_notify_rsp(&p_rsp->reg_notif, p_pkt); - break; - - case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ - status = avrc_bld_next_rsp(&p_rsp->continu, p_pkt); - break; - - case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ - status = avrc_bld_next_rsp(&p_rsp->abort, p_pkt); - break; - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - status = avrc_bld_set_abs_volume_rsp(&p_rsp->volume, p_pkt); - break; - - case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ - status = avrc_bld_set_addr_player_rsp(&p_rsp->addr_player, p_pkt); - break; - - case AVRC_PDU_PLAY_ITEM: /* 0x74 */ - status = avrc_bld_play_item_rsp(&p_rsp->play_item, p_pkt); - break; - - case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ - status = avrc_bld_add_to_now_playing_rsp(&p_rsp->add_to_play, p_pkt); - break; - -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_PDU_SET_BROWSED_PLAYER: /* 0x70 */ - status = avrc_bld_set_browsed_player_rsp(&p_rsp->br_player, p_pkt); - break; - - case AVRC_PDU_GET_FOLDER_ITEMS: /* 0x71 */ - status = avrc_bld_get_folder_items_rsp(&p_rsp->get_items, p_pkt); - break; - - case AVRC_PDU_CHANGE_PATH: /* 0x72 */ - status = avrc_bld_change_path_rsp(&p_rsp->chg_path, p_pkt); - break; - - case AVRC_PDU_GET_ITEM_ATTRIBUTES: /* 0x73 */ - status = avrc_bld_get_item_attrs_rsp(&p_rsp->get_attrs, p_pkt); - break; - - case AVRC_PDU_SEARCH: /* 0x80 */ - status = avrc_bld_search_rsp(&p_rsp->search, p_pkt); - break; -#endif -#endif - } - - if (alloc && (status != AVRC_STS_NO_ERROR) ) - { - GKI_freebuf(p_pkt); - *pp_pkt = NULL; - } - AVRC_TRACE_API1("AVRC_BldResponse: returning %d", status); - return status; -} - -#endif /* (AVRC_METADATA_INCLUDED == TRUE)*/ - diff --git a/stack/avrc/avrc_int.h b/stack/avrc/avrc_int.h index 33e561c..a2a4073 100644 --- a/stack/avrc/avrc_int.h +++ b/stack/avrc/avrc_int.h @@ -83,31 +83,10 @@ ** Type definitions *****************************************************************************/ -#if (AVRC_METADATA_INCLUDED == TRUE) -/* type for Metadata fragmentation control block */ -typedef struct -{ - BT_HDR *p_fmsg; /* the fragmented message */ - UINT8 frag_pdu; /* the PDU ID for fragmentation */ - BOOLEAN frag_enabled; /* fragmentation flag */ -} tAVRC_FRAG_CB; - -/* type for Metadata re-assembly control block */ -typedef struct -{ - BT_HDR *p_rmsg; /* the received message */ - UINT16 rasm_offset; /* re-assembly flag, the offset of the start fragment */ - UINT8 rasm_pdu; /* the PDU ID for re-assembly */ -} tAVRC_RASM_CB; -#endif typedef struct { tAVRC_CONN_CB ccb[AVCT_NUM_CONN]; -#if (AVRC_METADATA_INCLUDED == TRUE) - tAVRC_FRAG_CB fcb[AVCT_NUM_CONN]; - tAVRC_RASM_CB rcb[AVCT_NUM_CONN]; -#endif tAVRC_FIND_CBACK *p_cback; /* pointer to application callback */ tSDP_DISCOVERY_DB *p_db; /* pointer to discovery database */ UINT16 service_uuid; /* service UUID to search */ diff --git a/stack/avrc/avrc_opt.c b/stack/avrc/avrc_opt.c index 7711655..8902ac9 100644 --- a/stack/avrc/avrc_opt.c +++ b/stack/avrc/avrc_opt.c @@ -40,13 +40,8 @@ static BT_HDR * avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg) WC_ASSERT(p_msg != NULL); -#if AVRC_METADATA_INCLUDED == TRUE - WC_ASSERT(AVRC_META_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len)); - if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_META_CMD_POOL_ID)) != NULL) -#else WC_ASSERT(AVRC_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len)); if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) -#endif { p_cmd->offset = AVCT_MSG_OFFSET; p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; diff --git a/stack/avrc/avrc_pars_ct.c b/stack/avrc/avrc_pars_ct.c deleted file mode 100644 index 4feb256..0000000 --- a/stack/avrc/avrc_pars_ct.c +++ /dev/null @@ -1,663 +0,0 @@ -/***************************************************************************** -** -** Name: avrc_pars_ct.c -** -** Description:Interface to AVRCP parse message functions for the Control Role -** -** Copyright (c) 2008-2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "gki.h" -#include "avrc_api.h" -#include "avrc_defs.h" -#include "avrc_int.h" - -/***************************************************************************** -** Global data -*****************************************************************************/ - -#if (AVRC_METADATA_INCLUDED == TRUE) - -/******************************************************************************* -** -** Function avrc_pars_vendor_rsp -** -** Description This function parses the vendor specific commands defined by -** Bluetooth SIG -** -** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. -** Otherwise, the error code defined by AVRCP 1.4 -** -*******************************************************************************/ -static tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - UINT8 *p = p_msg->p_vendor_data; - UINT16 len; - UINT8 xx, yy; - tAVRC_NOTIF_RSP_PARAM *p_param; - tAVRC_APP_SETTING *p_app_set; - tAVRC_APP_SETTING_TEXT *p_app_txt; - tAVRC_ATTR_ENTRY *p_entry; - UINT32 *p_u32; - UINT8 *p_u8; - UINT16 size_needed; - - BE_STREAM_TO_UINT8 (p_result->pdu, p); - p++; /* skip the reserved/packe_type byte */ - BE_STREAM_TO_UINT16 (len, p); - AVRC_TRACE_DEBUG4("avrc_pars_vendor_rsp() ctype:0x%x pdu:0x%x, len:%d/0x%x", p_msg->hdr.ctype, p_result->pdu, len, len); - if (p_msg->hdr.ctype == AVRC_RSP_REJ) - { - p_result->rsp.status = *p; - return p_result->rsp.status; - } - - switch (p_result->pdu) - { - case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ - p_result->get_caps.capability_id = *p++; - if (AVRC_IS_VALID_CAP_ID(p_result->get_caps.capability_id)) - { - p_result->get_caps.count = *p++; - if (p_result->get_caps.capability_id == AVRC_CAP_COMPANY_ID) - { - p_u32 = p_result->get_caps.param.company_id; - for (xx=0; xx<p_result->get_caps.count; xx++) - { - AVRC_BE_STREAM_TO_CO_ID (p_u32[xx], p); - } - } - else - { - p_u8 = p_result->get_caps.param.event_id; - for (xx=0; xx<p_result->get_caps.count; xx++) - { - BE_STREAM_TO_UINT8 (p_u8[xx], p); - } - } - } - else - status = AVRC_STS_BAD_PARAM; - break; - - case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ - BE_STREAM_TO_UINT8 (p_result->list_app_attr.num_attr, p); - p_u8 = p_result->list_app_attr.attrs; - for(xx=0, yy=0; xx< p_result->list_app_attr.num_attr; xx++) - { - /* only report the valid player app attributes */ - if (AVRC_IsValidPlayerAttr(*p)) - p_u8[yy++] = *p; - p++; - } - p_result->list_app_attr.num_attr = yy; - break; - - case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ - BE_STREAM_TO_UINT8 (p_result->list_app_values.num_val, p); - p_u8 = p_result->list_app_values.vals; - for(xx=0; xx< p_result->list_app_values.num_val; xx++) - { - p_u8[xx] = *p++; - } - break; - - case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ - BE_STREAM_TO_UINT8 (p_result->get_cur_app_val.num_val, p); - size_needed = sizeof(tAVRC_APP_SETTING); - if (p_buf) - { - p_result->get_cur_app_val.p_vals = (tAVRC_APP_SETTING *)p_buf; - p_app_set = p_result->get_cur_app_val.p_vals; - for(xx=0; ((xx< p_result->get_cur_app_val.num_val) && (buf_len > size_needed)); xx++) - { - buf_len -= size_needed; - BE_STREAM_TO_UINT8 (p_app_set[xx].attr_id, p); - BE_STREAM_TO_UINT8 (p_app_set[xx].attr_val, p); - } - if (xx != p_result->get_cur_app_val.num_val) - { - AVRC_TRACE_ERROR2("GET_CUR_PLAYER_APP_VALUE not enough room:%d orig num_val:%d", - xx, p_result->get_cur_app_val.num_val); - p_result->get_cur_app_val.num_val = xx; - } - } - else - { - AVRC_TRACE_ERROR2("GET_CUR_PLAYER_APP_VALUE not enough room:len: %d needed for struct: %d", buf_len, size_needed); - status = AVRC_STS_INTERNAL_ERR; - } - break; - - case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ - case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ - case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT:/* 0x18 */ - /* no additional parameters */ - if (len != 0) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ - case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:/* 0x16 */ - BE_STREAM_TO_UINT8 (p_result->get_app_attr_txt.num_attr, p); - size_needed = sizeof(tAVRC_APP_SETTING_TEXT) * p_result->get_app_attr_txt.num_attr; - if (p_buf && (buf_len > size_needed)) - { - p_result->get_app_attr_txt.p_attrs = (tAVRC_APP_SETTING_TEXT *)p_buf; - p_app_txt = p_result->get_app_attr_txt.p_attrs; - p_u8 = p_buf + size_needed; - buf_len -= size_needed; - for(xx=0; xx< p_result->get_app_attr_txt.num_attr; xx++) - { - BE_STREAM_TO_UINT8 (p_app_txt[xx].attr_id, p); - BE_STREAM_TO_UINT16 (p_app_txt[xx].charset_id, p); - BE_STREAM_TO_UINT8 (p_app_txt[xx].str_len, p); - p_app_txt[xx].p_str = p_u8; - if (buf_len > p_app_txt[xx].str_len) - { - BE_STREAM_TO_ARRAY(p, p_u8, p_app_txt[xx].str_len); - p_u8 += p_app_txt[xx].str_len; - buf_len -= p_app_txt[xx].str_len; - } - else - { - AVRC_TRACE_ERROR4("GET_CUR_PLAYER_APP_VALUE not enough room:[%d] len orig/left: %d/%d, orig num_attr:%d", - xx, p_app_txt[xx].str_len, buf_len, p_result->get_app_attr_txt.num_attr); - p_app_txt[xx].str_len = (UINT8)buf_len; - BE_STREAM_TO_ARRAY(p, p_u8, p_app_txt[xx].str_len); - p_result->get_app_attr_txt.num_attr = xx+1; - status = AVRC_STS_INTERNAL_ERR; - break; - } - } - } - else - { - AVRC_TRACE_ERROR2("GET_CUR_PLAYER_APP_VALUE not enough room:len: %d needed for struct: %d", buf_len, size_needed); - status = AVRC_STS_INTERNAL_ERR; - } - break; - - case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ - BE_STREAM_TO_UINT8 (p_result->get_elem_attrs.num_attr, p); - size_needed = sizeof(tAVRC_ATTR_ENTRY) * p_result->get_elem_attrs.num_attr; - if (p_buf && (buf_len > size_needed)) - { - p_result->get_elem_attrs.p_attrs = (tAVRC_ATTR_ENTRY *)p_buf; - p_entry = p_result->get_elem_attrs.p_attrs; - p_u8 = p_buf + size_needed; - buf_len -= size_needed; - for(xx=0; xx< p_result->get_elem_attrs.num_attr; xx++) - { - BE_STREAM_TO_UINT32 (p_entry[xx].attr_id, p); - BE_STREAM_TO_UINT16 (p_entry[xx].name.charset_id, p); - BE_STREAM_TO_UINT16 (p_entry[xx].name.str_len, p); - p_entry[xx].name.p_str = p_u8; - if (buf_len > p_entry[xx].name.str_len) - { - BE_STREAM_TO_ARRAY(p, p_u8, p_entry[xx].name.str_len); - p_u8 += p_entry[xx].name.str_len; - buf_len -= p_entry[xx].name.str_len; - } - else - { - AVRC_TRACE_ERROR4("GET_ELEMENT_ATTR not enough room:[%d] len orig/left: %d/%d, orig num_attr:%d", - xx, p_entry[xx].name.str_len, buf_len, p_result->get_elem_attrs.num_attr); - p_entry[xx].name.str_len = buf_len; - BE_STREAM_TO_ARRAY(p, p_u8, p_entry[xx].name.str_len); - p_result->get_elem_attrs.num_attr = xx + 1; - status = AVRC_STS_INTERNAL_ERR; - break; - } - } - } - else - { - AVRC_TRACE_ERROR2("GET_ELEMENT_ATTR not enough room:len: %d needed for struct: %d", buf_len, size_needed); - status = AVRC_STS_INTERNAL_ERR; - } - break; - - case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ - BE_STREAM_TO_UINT32 (p_result->get_play_status.song_len, p); - BE_STREAM_TO_UINT32 (p_result->get_play_status.song_pos, p); - BE_STREAM_TO_UINT8 (p_result->get_play_status.play_status, p); - if (len != 9) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ - BE_STREAM_TO_UINT8 (p_result->reg_notif.event_id, p); - p_param = &p_result->reg_notif.param; - switch (p_result->reg_notif.event_id) - { - case AVRC_EVT_PLAY_STATUS_CHANGE: /* 0x01 */ - BE_STREAM_TO_UINT8 (p_param->play_status, p); - if ((p_param->play_status > AVRC_PLAYSTATE_REV_SEEK) && - (p_param->play_status != AVRC_PLAYSTATE_ERROR) ) - { - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_EVT_TRACK_CHANGE: /* 0x02 */ - BE_STREAM_TO_ARRAY (p, p_param->track, AVRC_UID_SIZE); - break; - - case AVRC_EVT_TRACK_REACHED_END: /* 0x03 */ - case AVRC_EVT_TRACK_REACHED_START: /* 0x04 */ -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_EVT_NOW_PLAYING_CHANGE: /* 0x09 */ - case AVRC_EVT_AVAL_PLAYERS_CHANGE: /* 0x0a */ -#endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */ - /* these events do not have additional parameters */ - break; - - case AVRC_EVT_PLAY_POS_CHANGED: /* 0x05 */ - BE_STREAM_TO_UINT32 (p_param->play_pos, p); - break; - - case AVRC_EVT_BATTERY_STATUS_CHANGE:/* 0x06 */ - BE_STREAM_TO_UINT8 (p_param->battery_status, p); - if (!AVRC_IS_VALID_BATTERY_STATUS(p_param->battery_status)) - { - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_EVT_SYSTEM_STATUS_CHANGE: /* 0x07 */ - BE_STREAM_TO_UINT8 (p_param->system_status, p); - if (!AVRC_IS_VALID_SYSTEM_STATUS(p_param->system_status)) - { - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_EVT_APP_SETTING_CHANGE: /* 0x08 */ - BE_STREAM_TO_UINT8 (p_param->player_setting.num_attr, p); - if (p_param->player_setting.num_attr > AVRC_MAX_APP_SETTINGS) - p_param->player_setting.num_attr = AVRC_MAX_APP_SETTINGS; - for (xx=0; xx<p_param->player_setting.num_attr; xx++) - { - BE_STREAM_TO_UINT8 (p_param->player_setting.attr_id[xx], p); - BE_STREAM_TO_UINT8 (p_param->player_setting.attr_value[xx], p); - if (!avrc_is_valid_player_attrib_value(p_param->player_setting.attr_id[xx], p_param->player_setting.attr_value[xx])) - { - status = AVRC_STS_BAD_PARAM; - break; - } - } - break; - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_EVT_ADDR_PLAYER_CHANGE: /* 0x0b */ - BE_STREAM_TO_UINT16 (p_param->addr_player.player_id, p); - BE_STREAM_TO_UINT16 (p_param->addr_player.uid_counter, p); - break; - - case AVRC_EVT_UIDS_CHANGE: /* 0x0c */ - BE_STREAM_TO_UINT16 (p_param->uid_counter, p); - break; - - case AVRC_EVT_VOLUME_CHANGE: /* 0x0d */ - BE_STREAM_TO_UINT8 (p_param->volume, p); - break; -#endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */ - - default: - status = AVRC_STS_BAD_PARAM; - break; - } - break; - - /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */ - /* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */ - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ - case AVRC_PDU_PLAY_ITEM: /* 0x74 */ - case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ - BE_STREAM_TO_UINT8 (p_result->volume.volume, p); - if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - break; -#endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */ - - default: - status = AVRC_STS_BAD_CMD; - break; - } - - return status; -} - -#if (AVCT_BROWSE_INCLUDED == TRUE) -/******************************************************************************* -** -** Function avrc_pars_browsing_rsp -** -** Description This function parses the commands that go through the -** browsing channel -** -** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. -** Otherwise, the error code defined by AVRCP 1.4 -** -*******************************************************************************/ -static tAVRC_STS avrc_pars_browsing_rsp(tAVRC_MSG_BROWSE *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - UINT8 *p = p_msg->p_browse_data; - UINT16 len; - int i, count; - UINT8 *p_left = p_buf; - tAVRC_ITEM *p_item; - tAVRC_ITEM_PLAYER *p_player; - tAVRC_ITEM_FOLDER *p_folder; - tAVRC_ITEM_MEDIA *p_media; - tAVRC_ATTR_ENTRY *p_attrs; - UINT16 item_len; - UINT8 xx; - UINT16 size_needed; - - p_result->pdu = *p++; - BE_STREAM_TO_UINT16 (len, p); - BE_STREAM_TO_UINT8 (status, p); - AVRC_TRACE_DEBUG4("avrc_pars_browsing_rsp() pdu:0x%x, len:%d/0x%x, status:0x%x", p_result->pdu, len, len, status); - if (status != AVRC_STS_NO_ERROR) - return status; - - switch (p_result->pdu) - { - case AVRC_PDU_SET_BROWSED_PLAYER: /* 0x70 */ - BE_STREAM_TO_UINT16 (p_result->br_player.uid_counter, p); - BE_STREAM_TO_UINT32 (p_result->br_player.num_items, p); - BE_STREAM_TO_UINT16 (p_result->br_player.charset_id, p); - BE_STREAM_TO_UINT8 (p_result->br_player.folder_depth, p); - p_result->br_player.p_folders = NULL; - if (p_result->br_player.folder_depth == 0) - return status; - - size_needed = sizeof(tAVRC_NAME) * p_result->br_player.folder_depth; - if (p_buf && (buf_len > size_needed)) - { - p_result->br_player.p_folders = (tAVRC_NAME *)p_buf; - p_left = p_buf + size_needed; - count = p_result->br_player.folder_depth; - buf_len -= size_needed; - for (i=0; i<count; i++) - { - p_result->br_player.p_folders[i].p_str = p_left; - BE_STREAM_TO_UINT16 (p_result->br_player.p_folders[i].str_len, p); - if (buf_len > p_result->br_player.p_folders[i].str_len) - { - BE_STREAM_TO_ARRAY (p, p_result->br_player.p_folders[i].p_str, p_result->br_player.p_folders[i].str_len); - p_left += p_result->br_player.p_folders[i].str_len; - buf_len -= p_result->br_player.p_folders[i].str_len; - } - else - { - AVRC_TRACE_ERROR4("SET_BROWSED_PLAYER not enough room:[%d] len orig/left: %d/%d, orig depth:%d", - i, p_result->br_player.p_folders[i].str_len, buf_len, p_result->br_player.folder_depth); - p_result->br_player.p_folders[i].str_len = buf_len; - BE_STREAM_TO_ARRAY (p, p_result->br_player.p_folders[i].p_str, p_result->br_player.p_folders[i].str_len); - p_result->br_player.folder_depth = i+1; - status = AVRC_STS_INTERNAL_ERR; - break; - } - } - } - else - { - AVRC_TRACE_ERROR2("SET_BROWSED_PLAYER not enough room:len: %d needed for struct: %d", buf_len, size_needed); - status = AVRC_STS_INTERNAL_ERR; - } - break; - - case AVRC_PDU_GET_FOLDER_ITEMS: /* 0x71 */ - BE_STREAM_TO_UINT16 (p_result->get_items.uid_counter, p); - BE_STREAM_TO_UINT16 (p_result->get_items.item_count, p); - p_result->get_items.p_item_list = NULL; - if (p_result->get_items.item_count == 0) - return status; - size_needed = sizeof(tAVRC_ITEM) * p_result->get_items.item_count; - if (p_buf && (buf_len > size_needed)) - { - p_result->get_items.p_item_list = p_item = (tAVRC_ITEM *)p_buf; - p_left = p_buf + size_needed; - count = p_result->get_items.item_count; - buf_len -= size_needed; - for (i=0; i<count; i++) - { - BE_STREAM_TO_UINT8 (p_item[i].item_type, p); - BE_STREAM_TO_UINT16 (item_len, p); - AVRC_TRACE_DEBUG3("[%d] type:%d len left:%d", i, p_item[i].item_type, buf_len); - switch(p_item[i].item_type) - { - case AVRC_ITEM_PLAYER: - p_player = &p_item[i].u.player; - BE_STREAM_TO_UINT16 (p_player->player_id, p); - BE_STREAM_TO_UINT8 (p_player->major_type, p); - BE_STREAM_TO_UINT32 (p_player->sub_type, p); - BE_STREAM_TO_UINT8 (p_player->play_status, p); - BE_STREAM_TO_ARRAY (p, p_player->features, AVRC_FEATURE_MASK_SIZE); - BE_STREAM_TO_UINT16 (p_player->name.charset_id, p); - BE_STREAM_TO_UINT16 (p_player->name.str_len, p); - p_player->name.p_str = p_left; - if (buf_len > p_player->name.str_len) - { - p_left += p_player->name.str_len; - BE_STREAM_TO_ARRAY (p, p_player->name.p_str, p_player->name.str_len); - buf_len -= p_player->name.str_len; - } - else - { - AVRC_TRACE_ERROR4("GET_FOLDER_ITEMS player not enough room:[%d] len orig/left: %d/%d, orig item count:%d", - i, p_player->name.str_len, buf_len, p_result->get_items.item_count); - p_player->name.str_len = buf_len; - BE_STREAM_TO_ARRAY (p, p_player->name.p_str, p_player->name.str_len); - p_result->get_items.item_count = i+1; - return AVRC_STS_INTERNAL_ERR; - } - break; - - case AVRC_ITEM_FOLDER: - p_folder = &p_item[i].u.folder; - BE_STREAM_TO_ARRAY (p, p_folder->uid, AVRC_UID_SIZE); - BE_STREAM_TO_UINT8 (p_folder->type, p); - BE_STREAM_TO_UINT8 (p_folder->playable, p); - BE_STREAM_TO_UINT16 (p_folder->name.charset_id, p); - BE_STREAM_TO_UINT16 (p_folder->name.str_len, p); - p_folder->name.p_str = p_left; - if (buf_len > p_folder->name.str_len) - { - p_left += p_folder->name.str_len; - BE_STREAM_TO_ARRAY (p, p_folder->name.p_str, p_folder->name.str_len); - buf_len -= p_folder->name.str_len; - } - else - { - AVRC_TRACE_ERROR4("GET_FOLDER_ITEMS folder not enough room:[%d] len orig/left: %d/%d, orig item count:%d", - i, p_folder->name.str_len, buf_len, p_result->get_items.item_count); - p_folder->name.str_len = buf_len; - BE_STREAM_TO_ARRAY (p, p_folder->name.p_str, p_folder->name.str_len); - p_result->get_items.item_count = i+1; - return AVRC_STS_INTERNAL_ERR; - } - break; - - case AVRC_ITEM_MEDIA: - p_media = &p_item[i].u.media; - BE_STREAM_TO_ARRAY (p, p_media->uid, AVRC_UID_SIZE); - BE_STREAM_TO_UINT8 (p_media->type, p); - BE_STREAM_TO_UINT16 (p_media->name.charset_id, p); - BE_STREAM_TO_UINT16 (p_media->name.str_len, p); - p_media->name.p_str = p_left; - if (buf_len < p_media->name.str_len) - { - AVRC_TRACE_ERROR4("GET_FOLDER_ITEMS media not enough room:[%d] len orig/left: %d/%d, orig item count:%d", - i, p_media->name.str_len, buf_len, p_result->get_items.item_count); - p_media->name.str_len = buf_len; - BE_STREAM_TO_ARRAY (p, p_media->name.p_str, p_media->name.str_len); - p_media->attr_count = 0; - p_media->p_attr_list = NULL; - p_result->get_items.item_count = i+1; - return AVRC_STS_INTERNAL_ERR; - } - p_left += p_media->name.str_len; - buf_len -= p_media->name.str_len; - BE_STREAM_TO_ARRAY (p, p_media->name.p_str, p_media->name.str_len); - BE_STREAM_TO_UINT8 (p_media->attr_count, p); - size_needed = sizeof(tAVRC_ATTR_ENTRY) * p_media->attr_count; - if (buf_len < size_needed) - { - AVRC_TRACE_ERROR4("GET_FOLDER_ITEMS media not enough room:[%d] attr_count orig/left: %d/%d, orig item count:%d", - i, p_media->attr_count, buf_len, p_result->get_items.item_count); - p_media->name.str_len = buf_len; - BE_STREAM_TO_ARRAY (p, p_media->name.p_str, p_media->name.str_len); - p_media->attr_count = 0; - p_media->p_attr_list = NULL; - p_result->get_items.item_count = i+1; - return AVRC_STS_INTERNAL_ERR; - } - p_media->p_attr_list = p_attrs = (tAVRC_ATTR_ENTRY *)p_left; - p_left += size_needed; - buf_len -= size_needed; - for (xx= 0; xx<p_media->attr_count; xx++) - { - BE_STREAM_TO_UINT32 (p_attrs[xx].attr_id, p); - BE_STREAM_TO_UINT16 (p_attrs[xx].name.charset_id, p); - BE_STREAM_TO_UINT16 (p_attrs[xx].name.str_len, p); - p_attrs[xx].name.p_str = p_left; - if (buf_len > p_attrs[xx].name.str_len) - { - p_left += p_attrs[xx].name.str_len; - BE_STREAM_TO_ARRAY (p, p_attrs[xx].name.p_str, p_attrs[xx].name.str_len); - buf_len -= p_attrs[xx].name.str_len; - } - else - { - AVRC_TRACE_ERROR4("GET_FOLDER_ITEMS media not enough room:[%d] attr name len orig/left: %d/%d, orig item count:%d", - i, p_attrs[xx].name.str_len, buf_len, p_result->get_items.item_count); - p_attrs[xx].name.str_len = buf_len; - BE_STREAM_TO_ARRAY (p, p_attrs[xx].name.p_str, p_attrs[xx].name.str_len); - p_media->attr_count = xx+1; - p_result->get_items.item_count = i+1; - return AVRC_STS_INTERNAL_ERR; - } - } - break; - } - } - } - break; - - case AVRC_PDU_CHANGE_PATH: /* 0x72 */ - BE_STREAM_TO_UINT32 (p_result->chg_path.num_items, p); - break; - - case AVRC_PDU_GET_ITEM_ATTRIBUTES: /* 0x73 */ - BE_STREAM_TO_UINT8 (p_result->get_attrs.attr_count, p); - p_result->get_attrs.p_attr_list = p_attrs = NULL; - if (p_result->get_attrs.attr_count == 0) - return status; - - size_needed = sizeof(tAVRC_ATTR_ENTRY) * p_result->get_attrs.attr_count; - if (p_buf && (buf_len > size_needed)) - { - p_result->get_attrs.p_attr_list = p_attrs = (tAVRC_ATTR_ENTRY *)p_left; - p_left += size_needed; - buf_len -= size_needed; - for (xx= 0; xx<p_result->get_attrs.attr_count; xx++) - { - BE_STREAM_TO_UINT32 (p_attrs[xx].attr_id, p); - BE_STREAM_TO_UINT16 (p_attrs[xx].name.charset_id, p); - BE_STREAM_TO_UINT16 (p_attrs[xx].name.str_len, p); - p_attrs[xx].name.p_str = p_left; - if (buf_len > p_attrs[xx].name.str_len) - { - p_left += p_attrs[xx].name.str_len; - BE_STREAM_TO_ARRAY (p, p_attrs[xx].name.p_str, p_attrs[xx].name.str_len); - buf_len -= p_attrs[xx].name.str_len; - } - else - { - AVRC_TRACE_ERROR4("GET_ITEM_ATTRIBUTES not enough room:[%d] len orig/left: %d/%d, orig attr_count:%d", - xx, p_attrs[xx].name.str_len, buf_len, p_result->get_attrs.attr_count); - p_attrs[xx].name.str_len = buf_len; - BE_STREAM_TO_ARRAY (p, p_attrs[xx].name.p_str, p_attrs[xx].name.str_len); - p_result->get_attrs.attr_count = xx+1; - status = AVRC_STS_INTERNAL_ERR; - break; - } - } - } - break; - - case AVRC_PDU_SEARCH: /* 0x80 */ - BE_STREAM_TO_UINT16 (p_result->search.uid_counter, p); - BE_STREAM_TO_UINT32 (p_result->search.num_items, p); - break; - - default: - status = AVRC_STS_BAD_CMD; - break; - } - - return status; -} -#endif /* (AVCT_BROWSE_INCLUDED == TRUE)*/ - -/******************************************************************************* -** -** Function AVRC_ParsResponse -** -** Description This function is a superset of AVRC_ParsMetadata to parse the response. -** -** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. -** Otherwise, the error code defined by AVRCP 1.4 -** -*******************************************************************************/ -tAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len) -{ - tAVRC_STS status = AVRC_STS_INTERNAL_ERR; - UINT16 id; - - if (p_msg && p_result) - { - switch (p_msg->hdr.opcode) - { - case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ - status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result, p_buf, buf_len); - break; - - case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */ - status = avrc_pars_pass_thru(&p_msg->pass, &id); - if (status == AVRC_STS_NO_ERROR) - { - p_result->pdu = (UINT8)id; - } - break; - -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_OP_BROWSE: - status = avrc_pars_browsing_rsp(&p_msg->browse, p_result, p_buf, buf_len); - break; -#endif /* (AVCT_BROWSE_INCLUDED == TRUE) */ - - default: - AVRC_TRACE_ERROR1("AVRC_ParsCommand() unknown opcode:0x%x", p_msg->hdr.opcode); - break; - } - p_result->rsp.opcode = p_msg->hdr.opcode; - p_result->rsp.status = status; - } - return status; -} - - -#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ diff --git a/stack/avrc/avrc_pars_tg.c b/stack/avrc/avrc_pars_tg.c deleted file mode 100644 index 8237655..0000000 --- a/stack/avrc/avrc_pars_tg.c +++ /dev/null @@ -1,452 +0,0 @@ -/***************************************************************************** -** -** Name: avrc_pars_tg.c -** -** Description:Interface to AVRCP parse message functions for the Target Role -** -** Copyright (c) 2008-2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "gki.h" -#include "avrc_api.h" -#include "avrc_defs.h" -#include "avrc_int.h" - -/***************************************************************************** -** Global data -*****************************************************************************/ -#if (AVRC_METADATA_INCLUDED == TRUE) - -/******************************************************************************* -** -** Function avrc_pars_vendor_cmd -** -** Description This function parses the vendor specific commands defined by -** Bluetooth SIG -** -** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. -** Otherwise, the error code defined by AVRCP 1.4 -** -*******************************************************************************/ -static tAVRC_STS avrc_pars_vendor_cmd(tAVRC_MSG_VENDOR *p_msg, tAVRC_COMMAND *p_result, UINT8 *p_buf, UINT16 buf_len) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - UINT8 *p = p_msg->p_vendor_data; - UINT16 len; - UINT8 xx, yy; - UINT8 *p_u8; - UINT16 *p_u16; - UINT32 u32, u32_2, *p_u32; - tAVRC_APP_SETTING *p_app_set; - UINT16 size_needed; - - p_result->pdu = *p++; - AVRC_TRACE_DEBUG1("avrc_pars_vendor_cmd() pdu:0x%x", p_result->pdu); - if (!AVRC_IsValidAvcType (p_result->pdu, p_msg->hdr.ctype)) - { - AVRC_TRACE_DEBUG0("avrc_pars_vendor_cmd() detects wrong AV/C type!"); - status = AVRC_STS_BAD_CMD; - } - - p++; /* skip the reserved byte */ - BE_STREAM_TO_UINT16 (len, p); - if ((len+4) != (p_msg->vendor_len)) - { - status = AVRC_STS_INTERNAL_ERR; - } - - if (status != AVRC_STS_NO_ERROR) - return status; - - switch (p_result->pdu) - { - case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ - p_result->get_caps.capability_id = *p++; - if (!AVRC_IS_VALID_CAP_ID(p_result->get_caps.capability_id)) - status = AVRC_STS_BAD_PARAM; - else if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ - /* no additional parameters */ - if (len != 0) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ - p_result->list_app_values.attr_id = *p++; - if (!AVRC_IS_VALID_ATTRIBUTE(p_result->list_app_values.attr_id)) - status = AVRC_STS_BAD_PARAM; - else if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ - case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ - BE_STREAM_TO_UINT8 (p_result->get_cur_app_val.num_attr, p); - if (len != (p_result->get_cur_app_val.num_attr+1)) - { - status = AVRC_STS_INTERNAL_ERR; - break; - } - p_u8 = p_result->get_cur_app_val.attrs; - for (xx=0, yy=0; xx< p_result->get_cur_app_val.num_attr; xx++) - { - /* only report the valid player app attributes */ - if (AVRC_IsValidPlayerAttr(*p)) - p_u8[yy++] = *p; - p++; - } - p_result->get_cur_app_val.num_attr = yy; - if (yy == 0) - { - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ - BE_STREAM_TO_UINT8 (p_result->set_app_val.num_val, p); - size_needed = sizeof(tAVRC_APP_SETTING); - if (p_buf && (len == ((p_result->set_app_val.num_val<<1) + 1))) - { - p_result->set_app_val.p_vals = (tAVRC_APP_SETTING *)p_buf; - p_app_set = p_result->set_app_val.p_vals; - for (xx=0; ((xx< p_result->set_app_val.num_val) && (buf_len > size_needed)); xx++) - { - p_app_set[xx].attr_id = *p++; - p_app_set[xx].attr_val = *p++; - if (!avrc_is_valid_player_attrib_value(p_app_set[xx].attr_id, p_app_set[xx].attr_val)) - status = AVRC_STS_BAD_PARAM; - } - if (xx != p_result->set_app_val.num_val) - { - AVRC_TRACE_ERROR2("AVRC_PDU_SET_PLAYER_APP_VALUE not enough room:%d orig num_val:%d", - xx, p_result->set_app_val.num_val); - p_result->set_app_val.num_val = xx; - } - } - else - { - AVRC_TRACE_ERROR0("AVRC_PDU_SET_PLAYER_APP_VALUE NULL decode buffer or bad len"); - status = AVRC_STS_INTERNAL_ERR; - } - break; - - case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:/* 0x16 */ - if (len < 3) - status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.attr_id, p); - if (!AVRC_IS_VALID_ATTRIBUTE(p_result->get_app_val_txt.attr_id)) - status = AVRC_STS_BAD_PARAM; - else - { - BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.num_val, p); - if ( (len - 2/* attr_id & num_val */) != p_result->get_app_val_txt.num_val) - status = AVRC_STS_INTERNAL_ERR; - else - { - p_u8 = p_result->get_app_val_txt.vals; - for (xx=0; xx< p_result->get_app_val_txt.num_val; xx++) - { - p_u8[xx] = *p++; - if (!avrc_is_valid_player_attrib_value(p_result->get_app_val_txt.attr_id, p_u8[xx])) - { - status = AVRC_STS_BAD_PARAM; - break; - } - } - } - } - } - break; - - case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ - if (len < 3) - status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT8 (p_result->inform_charset.num_id, p); - if ( (len - 1/* num_id */) != p_result->inform_charset.num_id * 2) - status = AVRC_STS_INTERNAL_ERR; - else - { - p_u16 = p_result->inform_charset.charsets; - if (p_result->inform_charset.num_id > AVRC_MAX_CHARSET_SIZE) - p_result->inform_charset.num_id = AVRC_MAX_CHARSET_SIZE; - for (xx=0; xx< p_result->inform_charset.num_id; xx++) - { - BE_STREAM_TO_UINT16 (p_u16[xx], p); - } - } - } - break; - - case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT:/* 0x18 */ - if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - else - { - p_result->inform_battery_status.battery_status = *p++; - if (!AVRC_IS_VALID_BATTERY_STATUS(p_result->inform_battery_status.battery_status)) - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ - if (len < 9) /* UID/8 and num_attr/1 */ - status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT32 (u32, p); - BE_STREAM_TO_UINT32 (u32_2, p); - if (u32== 0 && u32_2 == 0) - { - BE_STREAM_TO_UINT8 (p_result->get_elem_attrs.num_attr, p); - if ( (len - 9/* UID/8 and num_attr/1 */) != (p_result->get_elem_attrs.num_attr * 4)) - status = AVRC_STS_INTERNAL_ERR; - else - { - p_u32 = p_result->get_elem_attrs.attrs; - if (p_result->get_elem_attrs.num_attr > AVRC_MAX_ELEM_ATTR_SIZE) - p_result->get_elem_attrs.num_attr = AVRC_MAX_ELEM_ATTR_SIZE; - for (xx=0; xx< p_result->get_elem_attrs.num_attr; xx++) - { - BE_STREAM_TO_UINT32 (p_u32[xx], p); - } - } - } - else - status = AVRC_STS_NOT_FOUND; - } - break; - - case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ - /* no additional parameters */ - if (len != 0) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ - if (len != 5) - status = AVRC_STS_INTERNAL_ERR; - BE_STREAM_TO_UINT8 (p_result->reg_notif.event_id, p); - BE_STREAM_TO_UINT32 (p_result->reg_notif.param, p); - break; - - /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */ - /* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */ - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - p_result->volume.volume = *p++; - break; - - case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ - if (len != 2) - status = AVRC_STS_INTERNAL_ERR; - BE_STREAM_TO_UINT16 (p_result->addr_player.player_id, p); - break; - - case AVRC_PDU_PLAY_ITEM: /* 0x74 */ - case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ - if (len != (AVRC_UID_SIZE + 3)) - status = AVRC_STS_INTERNAL_ERR; - BE_STREAM_TO_UINT8 (p_result->play_item.scope, p); - if (p_result->play_item.scope > AVRC_SCOPE_NOW_PLAYING) - { - status = AVRC_STS_BAD_SCOPE; - } - BE_STREAM_TO_ARRAY (p, p_result->play_item.uid, AVRC_UID_SIZE); - BE_STREAM_TO_UINT16 (p_result->play_item.uid_counter, p); - break; -#endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */ - - default: - status = AVRC_STS_BAD_CMD; - break; - } - - return status; -} - -#if (AVCT_BROWSE_INCLUDED == TRUE) -/******************************************************************************* -** -** Function avrc_pars_browsing -** -** Description This function parses the commands that go through the -** browsing channel -** -** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. -** Otherwise, the error code defined by AVRCP+1 -** -*******************************************************************************/ -static tAVRC_STS avrc_pars_browsing_cmd(tAVRC_MSG_BROWSE *p_msg, tAVRC_COMMAND *p_result, UINT8 *p_buf, UINT16 buf_len) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - UINT8 *p = p_msg->p_browse_data; - UINT16 len; - int i, count; - - p_result->pdu = *p++; - AVRC_TRACE_DEBUG1("avrc_pars_browsing_cmd() pdu:0x%x", p_result->pdu); - BE_STREAM_TO_UINT16 (len, p); - switch (p_result->pdu) - { - case AVRC_PDU_SET_BROWSED_PLAYER: /* 0x70 */ - BE_STREAM_TO_UINT16 (p_result->br_player.player_id, p); - break; - - case AVRC_PDU_GET_FOLDER_ITEMS: /* 0x71 */ - BE_STREAM_TO_UINT8 (p_result->get_items.scope, p); - if (p_result->get_items.scope > AVRC_SCOPE_NOW_PLAYING) - { - status = AVRC_STS_BAD_SCOPE; - } - BE_STREAM_TO_UINT32 (p_result->get_items.start_item, p); - BE_STREAM_TO_UINT32 (p_result->get_items.end_item, p); - if (p_result->get_items.start_item > p_result->get_items.end_item) - { - status = AVRC_STS_BAD_RANGE; - } - BE_STREAM_TO_UINT8 (p_result->get_items.attr_count, p); - p_result->get_items.p_attr_list = NULL; - if (p_result->get_items.attr_count && p_buf && - (p_result->get_items.attr_count != AVRC_FOLDER_ITEM_COUNT_NONE)) - { - p_result->get_items.p_attr_list = (UINT32 *)p_buf; - count = p_result->get_items.attr_count; - if (buf_len < (count<<2)) - p_result->get_items.attr_count = count = (buf_len >> 2); - for (i=0; i<count; i++) - { - BE_STREAM_TO_UINT32 (p_result->get_items.p_attr_list[i], p); - } - } - break; - - case AVRC_PDU_CHANGE_PATH: /* 0x72 */ - BE_STREAM_TO_UINT16 (p_result->chg_path.uid_counter, p); - BE_STREAM_TO_UINT8 (p_result->chg_path.direction, p); - if (p_result->chg_path.direction != AVRC_DIR_UP && p_result->chg_path.direction != AVRC_DIR_DOWN) - { - status = AVRC_STS_BAD_DIR; - } - BE_STREAM_TO_ARRAY (p, p_result->chg_path.folder_uid, AVRC_UID_SIZE); - break; - - case AVRC_PDU_GET_ITEM_ATTRIBUTES: /* 0x73 */ - BE_STREAM_TO_UINT8 (p_result->get_attrs.scope, p); - if (p_result->get_attrs.scope > AVRC_SCOPE_NOW_PLAYING) - { - status = AVRC_STS_BAD_SCOPE; - break; - } - BE_STREAM_TO_ARRAY (p, p_result->get_attrs.uid, AVRC_UID_SIZE); - BE_STREAM_TO_UINT16 (p_result->get_attrs.uid_counter, p); - BE_STREAM_TO_UINT8 (p_result->get_attrs.attr_count, p); - p_result->get_attrs.p_attr_list = NULL; - if (p_result->get_attrs.attr_count && p_buf) - { - p_result->get_attrs.p_attr_list = (UINT32 *)p_buf; - count = p_result->get_attrs.attr_count; - if (buf_len < (count<<2)) - p_result->get_attrs.attr_count = count = (buf_len >> 2); - for (i=0, count=0; i<p_result->get_attrs.attr_count; i++) - { - BE_STREAM_TO_UINT32 (p_result->get_attrs.p_attr_list[count], p); - if (AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_result->get_attrs.p_attr_list[count])) - { - count++; - } - } - - if (p_result->get_attrs.attr_count != count && count == 0) - status = AVRC_STS_BAD_PARAM; - else - p_result->get_attrs.attr_count = count; - } - break; - - case AVRC_PDU_SEARCH: /* 0x80 */ - BE_STREAM_TO_UINT16 (p_result->search.string.charset_id, p); - BE_STREAM_TO_UINT16 (p_result->search.string.str_len, p); - p_result->search.string.p_str = p_buf; - if (p_buf) - { - if (buf_len > p_result->search.string.str_len) - buf_len = p_result->search.string.str_len; - BE_STREAM_TO_ARRAY (p, p_buf, p_result->search.string.str_len); - } - else - { - status = AVRC_STS_INTERNAL_ERR; - } - break; - - default: - status = AVRC_STS_BAD_CMD; - break; - } - return status; -} -#endif /* AVCT_BROWSE_INCLUDED == TRUE*/ - -/******************************************************************************* -** -** Function AVRC_ParsCommand -** -** Description This function is a superset of AVRC_ParsMetadata to parse the command. -** -** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. -** Otherwise, the error code defined by AVRCP 1.4 -** -*******************************************************************************/ -tAVRC_STS AVRC_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result, UINT8 *p_buf, UINT16 buf_len) -{ - tAVRC_STS status = AVRC_STS_INTERNAL_ERR; - UINT16 id; - - if (p_msg && p_result) - { - switch (p_msg->hdr.opcode) - { - case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ - status = avrc_pars_vendor_cmd(&p_msg->vendor, p_result, p_buf, buf_len); - break; - - case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */ - status = avrc_pars_pass_thru(&p_msg->pass, &id); - if (status == AVRC_STS_NO_ERROR) - { - p_result->pdu = (UINT8)id; - } - break; - -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_OP_BROWSE: - status = avrc_pars_browsing_cmd(&p_msg->browse, p_result, p_buf, buf_len); - break; -#endif /*(AVCT_BROWSE_INCLUDED == TRUE)*/ - - default: - AVRC_TRACE_ERROR1("AVRC_ParsCommand() unknown opcode:0x%x", p_msg->hdr.opcode); - break; - } - p_result->cmd.opcode = p_msg->hdr.opcode; - p_result->cmd.status = status; - } - AVRC_TRACE_DEBUG1("AVRC_ParsCommand() return status:0x%x", status); - return status; -} - -#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ - diff --git a/stack/avrc/avrc_sdp.c b/stack/avrc/avrc_sdp.c index ad2024e..c9ad935 100644 --- a/stack/avrc/avrc_sdp.c +++ b/stack/avrc/avrc_sdp.c @@ -25,26 +25,9 @@ tAVRC_CB avrc_cb; const tSDP_PROTOCOL_ELEM avrc_proto_list [] = { {UUID_PROTOCOL_L2CAP, 1, {AVCT_PSM, 0} }, -#if AVRC_ADV_CTRL_INCLUDED == TRUE - {UUID_PROTOCOL_AVCTP, 1, {AVCT_REV_1_3, 0} } -#else -#if AVRC_METADATA_INCLUDED == TRUE - {UUID_PROTOCOL_AVCTP, 1, {AVCT_REV_1_2, 0} } -#else {UUID_PROTOCOL_AVCTP, 1, {AVCT_REV_1_0, 0} } -#endif -#endif }; -#if AVRC_ADV_CTRL_INCLUDED == TRUE -const tSDP_PROTO_LIST_ELEM avrc_add_proto_list [] = -{ - {AVRC_NUM_PROTO_ELEMS, - { - {UUID_PROTOCOL_L2CAP, 1, {AVCT_BR_PSM, 0} }, - {UUID_PROTOCOL_AVCTP, 1, {AVCT_REV_1_3, 0} }}} -}; -#endif /****************************************************************************** @@ -210,30 +193,13 @@ UINT16 AVRC_AddRecord(UINT16 service_uuid, char *p_service_name, /* add service class id list */ class_list[0] = service_uuid; -#if AVRC_ADV_CTRL_INCLUDED == TRUE - if( service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL ) - { - class_list[1] = UUID_SERVCLASS_AV_REM_CTRL_CONTROL; - count = 2; - } -#endif result &= SDP_AddServiceClassIdList(sdp_handle, count, class_list); /* add protocol descriptor list */ result &= SDP_AddProtocolList(sdp_handle, AVRC_NUM_PROTO_ELEMS, (tSDP_PROTOCOL_ELEM *)avrc_proto_list); /* add profile descriptor list */ -#if AVRC_ADV_CTRL_INCLUDED == TRUE - result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, AVRC_REV_1_4); - /* additional protocol list to include browsing channel */ - result &= SDP_AddAdditionProtoLists( sdp_handle, 1, (tSDP_PROTO_LIST_ELEM *)avrc_add_proto_list); -#else -#if AVRC_METADATA_INCLUDED == TRUE - result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, AVRC_REV_1_3); -#else result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, AVRC_REV_1_0); -#endif -#endif /* add supported categories */ p = temp; diff --git a/stack/avrc/avrc_utils.c b/stack/avrc/avrc_utils.c deleted file mode 100644 index b9eef9b..0000000 --- a/stack/avrc/avrc_utils.c +++ /dev/null @@ -1,254 +0,0 @@ -/***************************************************************************** -** -** Name: avrc_utils.c -** -** Description: Utility functions to validate AVRC command/response paramaters -** -** Copyright (c) 2003-2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "gki.h" -#include "avrc_api.h" -#include "avrc_int.h" - - -#if (AVRC_METADATA_INCLUDED == TRUE) - -/************************************************************************** -** -** Function AVRC_IsValidAvcType -** -** Description Check if correct AVC type is specified -** -** Returns returns TRUE if it is valid -** -** -*******************************************************************************/ -BOOLEAN AVRC_IsValidAvcType(UINT8 pdu_id, UINT8 avc_type) -{ - BOOLEAN result=FALSE; - - if (avc_type < AVRC_RSP_NOT_IMPL) /* command msg */ - { - switch (pdu_id) - { - case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ - case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ - case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ - case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ - case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ - case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: /* 0x16 */ - case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ - case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ - if (avc_type == AVRC_CMD_STATUS) - result=TRUE; - break; - - case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ - case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ - case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: /* 0x18 */ - case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ - case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ - if (avc_type == AVRC_CMD_CTRL) - result=TRUE; - break; - - case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ - if (avc_type == AVRC_CMD_NOTIF) - result=TRUE; - break; - -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ - case AVRC_PDU_PLAY_ITEM: /* 0x74 */ - case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ - if (avc_type == AVRC_CMD_CTRL) - result=TRUE; - break; -#endif - } - } - else /* response msg */ - { - if (avc_type >= AVRC_RSP_NOT_IMPL && - avc_type <= AVRC_RSP_INTERIM ) - result=TRUE; - } - - return result; -} - -/******************************************************************************* -** -** Function avrc_is_valid_player_attrib_value -** -** Description Check if the given attrib value is valid for its attribute -** -** -** Returns returns TRUE if it is valid -** -*******************************************************************************/ -BOOLEAN avrc_is_valid_player_attrib_value(UINT8 attrib, UINT8 value) -{ - BOOLEAN result=FALSE; - - switch(attrib) - { - case AVRC_PLAYER_SETTING_EQUALIZER: - if ((value > 0) && - (value <= AVRC_PLAYER_VAL_ON)) - result=TRUE; - break; - - case AVRC_PLAYER_SETTING_REPEAT: - if ((value > 0) && - (value <= AVRC_PLAYER_VAL_GROUP_REPEAT)) - result=TRUE; - break; - - case AVRC_PLAYER_SETTING_SHUFFLE: - case AVRC_PLAYER_SETTING_SCAN: - if ((value > 0) && - (value <= AVRC_PLAYER_VAL_GROUP_SHUFFLE)) - result=TRUE; - break; - } - - if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT && - attrib <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT) - result = TRUE; - - if (!result) - AVRC_TRACE_ERROR2("avrc_is_valid_player_attrib_value() found not matching attrib(x%x)-value(x%x) pair!", attrib, value); - - return result; -} - -/******************************************************************************* -** -** Function AVRC_IsValidPlayerAttr -** -** Description Check if the given attrib value is a valid one -** -** -** Returns returns TRUE if it is valid -** -*******************************************************************************/ -BOOLEAN AVRC_IsValidPlayerAttr(UINT8 attr) -{ - BOOLEAN result=FALSE; - - if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) || - (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT && attr <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT) ) - { - result = TRUE; - } - - return result; -} - - - -/******************************************************************************* -** -** Function avrc_pars_pass_thru -** -** Description This function parses the pass thru commands defined by -** Bluetooth SIG -** -** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. -** Otherwise, the error code defined by AVRCP 1.4 -** -*******************************************************************************/ -tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, UINT16 *p_vendor_unique_id) -{ - UINT8 *p_data; - UINT32 co_id; - UINT16 id; - tAVRC_STS status = AVRC_STS_BAD_CMD; - - if (p_msg->op_id == AVRC_ID_VENDOR && p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN) - { - p_data = p_msg->p_pass_data; - AVRC_BE_STREAM_TO_CO_ID (co_id, p_data); - if (co_id == AVRC_CO_METADATA) - { - BE_STREAM_TO_UINT16 (id, p_data); - if (AVRC_IS_VALID_GROUP(id)) - { - *p_vendor_unique_id = id; - status = AVRC_STS_NO_ERROR; - } - } - } - return status; -} - -/******************************************************************************* -** -** Function avrc_opcode_from_pdu -** -** Description This function returns the opcode of the given pdu -** -** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE -** -*******************************************************************************/ -UINT8 avrc_opcode_from_pdu(UINT8 pdu) -{ - UINT8 opcode = 0; - - switch (pdu) - { -#if (AVCT_BROWSE_INCLUDED == TRUE) - case AVRC_PDU_SET_BROWSED_PLAYER: - case AVRC_PDU_GET_FOLDER_ITEMS: - case AVRC_PDU_CHANGE_PATH: - case AVRC_PDU_GET_ITEM_ATTRIBUTES: - case AVRC_PDU_SEARCH: - case AVRC_PDU_GENERAL_REJECT: - opcode = AVRC_OP_BROWSE; - break; -#endif /* AVCT_BROWSE_INCLUDED */ - - case AVRC_PDU_NEXT_GROUP: - case AVRC_PDU_PREV_GROUP: /* pass thru */ - opcode = AVRC_OP_PASS_THRU; - break; - - default: /* vendor */ - opcode = AVRC_OP_VENDOR; - break; - } - - return opcode; -} - -/******************************************************************************* -** -** Function avrc_is_valid_opcode -** -** Description This function returns the opcode of the given pdu -** -** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE -** -*******************************************************************************/ -BOOLEAN avrc_is_valid_opcode(UINT8 opcode) -{ - BOOLEAN is_valid = FALSE; - switch (opcode) - { - case AVRC_OP_BROWSE: - case AVRC_OP_PASS_THRU: - case AVRC_OP_VENDOR: - is_valid = TRUE; - break; - } - return is_valid; -} - -#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ - diff --git a/stack/dun/dun_api.c b/stack/dun/dun_api.c deleted file mode 100644 index ce7380e..0000000 --- a/stack/dun/dun_api.c +++ /dev/null @@ -1,592 +0,0 @@ -/*****************************************************************************/ -/* */ -/* Name: dun_api.c */ -/* */ -/* Description: This file contains the DUN API routines */ -/* */ -/* */ -/* Copyright (c) 1999-2009, Broadcom Corp., All Rights Reserved. */ -/* Broadcom Bluetooth Core. Proprietary and confidential. */ -/*****************************************************************************/ - -#include <string.h> -#include "bt_target.h" -#include "btm_api.h" -#include "port_api.h" -#include "dun_api.h" -#include "dun_int.h" -#include "rfcdefs.h" - -/***************************************************************************** -** Constants -*****************************************************************************/ - -/* Number of attributes in DUN and Fax SDP records. */ -#define DUN_NUM_ATTR_DUN 4 -#define DUN_NUM_ATTR_FAX 7 - -/* Number of protocol elements in protocol element list. */ -#define DUN_NUM_PROTO_ELEMS 2 - - -/* Global DUN/FAX control block structure -*/ -#if DUN_DYNAMIC_MEMORY == FALSE -tDUN_CB dun_cb; -#endif - -/****************************************************************************** -** -** Function dun_sdp_cback -** -** Description This is the SDP callback function used by DUN_FindService. -** This function will be executed by SDP when the service -** search is completed. If the search is successful, it -** finds the first record in the database that matches the -** UUID of the search. Then retrieves various parameters -** from the record. When it is finished it calls the -** application callback function. -** -** Returns Nothing. -** -******************************************************************************/ -static void dun_sdp_cback(UINT16 status) -{ - tSDP_DISC_REC *p_rec = NULL; - tSDP_DISC_ATTR *p_attr; - tSDP_PROTOCOL_ELEM pe; - UINT8 scn = 0; - UINT16 name_len = 0; - char *p_name = ""; - UINT16 options = 0; - BOOLEAN found = FALSE; - - DUN_TRACE_API1("dun_sdp_cback status: %d", status); - - if (status == SDP_SUCCESS) - { - /* loop through all records we found */ - do - { - /* get next record; if none found, we're done */ - if ((p_rec = SDP_FindServiceInDb(dun_cb.find_cb.p_db, - dun_cb.find_cb.service_uuid, p_rec)) == NULL) - { - break; - } - - /* get scn from proto desc list; if not found, go to next record */ - if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) - { - scn = (UINT8) pe.params[0]; - } - else - { - continue; - } - - /* get service name */ - if ((p_attr = SDP_FindAttributeInRec(p_rec, - ATTR_ID_SERVICE_NAME)) != NULL) - { - p_name = (char *) p_attr->attr_value.v.array; - name_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type); - } - - /* get audio support */ - if ((p_attr = SDP_FindAttributeInRec(p_rec, - ATTR_ID_AUDIO_FEEDBACK_SUPPORT)) != NULL) - { - options |= (p_attr->attr_value.v.u8) ? DUN_OPTIONS_AUDIO : 0; - } - - /* get fax options */ - if(dun_cb.find_cb.service_uuid == UUID_SERVCLASS_FAX) - { - if ((p_attr = SDP_FindAttributeInRec(p_rec, - ATTR_ID_FAX_CLASS_1_SUPPORT)) != NULL) - { - options |= (p_attr->attr_value.v.u8) ? DUN_OPTIONS_CLASS1 : 0; - } - - if ((p_attr = SDP_FindAttributeInRec(p_rec, - ATTR_ID_FAX_CLASS_2_0_SUPPORT)) != NULL) - { - options |= (p_attr->attr_value.v.u8) ? DUN_OPTIONS_CLASS20 : 0; - } - - if ((p_attr = SDP_FindAttributeInRec(p_rec, - ATTR_ID_FAX_CLASS_2_SUPPORT)) != NULL) - { - options |= (p_attr->attr_value.v.u8) ? DUN_OPTIONS_CLASS2 : 0; - } - } - - /* we've got everything, we're done */ - found = TRUE; - break; - - } while (TRUE); - } - - /* return info from sdp record in app callback function */ - if (dun_cb.find_cb.p_cback != NULL) - { - (*dun_cb.find_cb.p_cback)(found, scn, p_name, name_len, options); - } - - return; -} - -/****************************************************************************** -** -** Function DUN_Listen -** -** Description This function opens a DUN or Fax connection in server mode. -** It configures the security settings for the connection and -** opens an RFCOMM connection in server mode. It returns -** the handle for the RFCOMM connection. -** -** Input Parameters: -** service_uuid: Indicates DUN or Fax. -** -** p_service_name: A null-terminated character string -** containing the service name. This is used for security. -** -** scn: The server channel number for the RFCOMM -** connection. -** -** mtu: The MTU, or maximum data frame size, for the -** RFCOMM connection. -** -** security_mask: Security configuration. See the BTM API. -** -** p_cback: RFCOMM port callback function. See the -** RFCOMM API. -** -** Output Parameters: -** p_handle: The handle for the RFCOMM connection. -** This value is used in subsequent calls to the RFCOMM API. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -UINT8 DUN_Listen(UINT16 service_uuid, char *p_service_name, UINT8 scn, UINT16 mtu, - UINT8 security_mask, UINT16 *p_handle, tPORT_CALLBACK *p_cback) -{ - BD_ADDR bd_addr = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - UINT8 status = DUN_SUCCESS; - UINT8 service_id; - - DUN_TRACE_API1("DUN_Listen uuid: %x", service_uuid); - - switch (service_uuid) - { - case UUID_SERVCLASS_DIALUP_NETWORKING: - service_id = BTM_SEC_SERVICE_DUN; - break; - - case UUID_SERVCLASS_FAX: - service_id = BTM_SEC_SERVICE_FAX; - break; - - case UUID_SERVCLASS_SERIAL_PORT: - default: - service_id = BTM_SEC_SERVICE_SERIAL_PORT; - break; - } - - /* set up security */ - if (BTM_SetSecurityLevel(FALSE, (char *) p_service_name, service_id, - security_mask, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, scn) == FALSE) - { - status = DUN_FAIL; - } - - /* open rfcomm server connection */ - if (status == DUN_SUCCESS) - { - if (RFCOMM_CreateConnection(service_uuid, scn, TRUE, mtu, bd_addr, - p_handle, p_cback) != PORT_SUCCESS) - { - status = DUN_FAIL; - } - } - - return status; -} - -/****************************************************************************** -** -** Function DUN_Connect -** -** Description This function opens a DUN or Fax client connection. -** It configures the security settings for the connection -** and opens an RFCOMM connection in server mode. -** It returns the handle for the RFCOMM connection. -** -** Input Parameters: -** service_uuid: Indicates DUN or Fax. -** -** bd_addr: BD address of the peer device. -** -** scn: The server channel number for the RFCOMM -** connection. -** -** mtu: The MTU, or maximum data frame size, for the -** RFCOMM connection. -** -** security_mask: Security configuration. See the BTM API. -** -** p_cback: RFCOMM port callback function. See the -** RFCOMM API. -** -** Output Parameters: -** p_handle: The handle for the RFCOMM connection. -** This value is used in subsequent calls to the RFCOMM API. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -UINT8 DUN_Connect(UINT16 service_uuid, BD_ADDR bd_addr, UINT8 scn, UINT16 mtu, - UINT8 security_mask, UINT16 *p_handle, tPORT_CALLBACK *p_cback) -{ - char name[] = ""; /* don't bother using a name for security */ - UINT8 status = DUN_SUCCESS; - UINT8 service_id; - - DUN_TRACE_API1("DUN_Connect uuid: %x", service_uuid); - - switch (service_uuid) - { - case UUID_SERVCLASS_DIALUP_NETWORKING: - service_id = BTM_SEC_SERVICE_DUN; - break; - - case UUID_SERVCLASS_FAX: - service_id = BTM_SEC_SERVICE_FAX; - break; - - case UUID_SERVCLASS_SERIAL_PORT: - default: - service_id = BTM_SEC_SERVICE_SERIAL_PORT; - break; - } - - /* set up security */ - if(BTM_SetSecurityLevel(TRUE, name, service_id, security_mask, - BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, scn) == FALSE) - { - status = DUN_FAIL; - } - - /* open rfcomm client connection */ - if (status == DUN_SUCCESS) - { - if (RFCOMM_CreateConnection(service_uuid, scn, FALSE, mtu, bd_addr, - p_handle, p_cback) != PORT_SUCCESS) - { - status = DUN_FAIL; - } - } - - return status; -} - - -/****************************************************************************** -** -** Function DUN_Close -** -** Description This function closes a DUN or Fax client connection -** previously opened with DUN_Connect(). -** -** Input Parameters: -** handle: The handle for the RFCOMM connection -** previously returned by DUN_Connect(). -** -** Output Parameters: -** None. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -UINT8 DUN_Close(UINT16 handle) -{ - UINT8 status = DUN_SUCCESS; - - DUN_TRACE_API0("DUN_close"); - - if (RFCOMM_RemoveConnection(handle) != PORT_SUCCESS) - { - status = DUN_FAIL; - } - - return status; -} - - -/****************************************************************************** -** -** Function DUN_Shutdown -** -** Description This function closes a DUN or Fax server connection -** previously opened with DUN_Listen(). It is called if -** the application wishes to close the DUN or Fax server -** connection at any time. -** -** Input Parameters: -** service_uuid: Indicates DUN or Fax. -** -** handle: The handle for the RFCOMM connection -** previously returned by DUN_Connect(). -** -** Output Parameters: -** None. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -UINT8 DUN_Shutdown(UINT16 handle) -{ - UINT8 status = DUN_SUCCESS; - - DUN_TRACE_API0("DUN_Shutdown"); - - /* close rfcomm connection */ - if (RFCOMM_RemoveServer(handle) != PORT_SUCCESS) - { - status = DUN_FAIL; - } - - return status; -} - -/****************************************************************************** -** -** Function DUN_AddRecord -** -** Description This function is called by a server application to add -** DUN or Fax information to an SDP record. Prior to -** calling this function the application must call -** SDP_CreateRecord() to create an SDP record. -** -** Input Parameters: -** service_uuid: Indicates DUN or Fax. -** -** p_service_name: Pointer to a null-terminated character -** string containing the service name. -** -** scn: The server channel number of the RFCOMM -** connection. -** -** options: Profile support options. -** -** sdp_handle: SDP handle returned by SDP_CreateRecord(). -** -** Output Parameters: -** None. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -UINT8 DUN_AddRecord(UINT16 service_uuid, char *p_service_name, UINT8 scn, - UINT16 options, UINT32 sdp_handle) -{ - tSDP_PROTOCOL_ELEM proto_elem_list[DUN_NUM_PROTO_ELEMS]; - UINT8 audio; - UINT8 class1; - UINT8 class20; - UINT8 class2; - UINT16 browse_list[1]; - BOOLEAN result = TRUE; - - DUN_TRACE_API1("DUN_AddRecord uuid: %x", service_uuid); - - memset((void*) proto_elem_list, 0 , DUN_NUM_PROTO_ELEMS*sizeof(tSDP_PROTOCOL_ELEM)); - - /* add the protocol element sequence */ - proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP; - proto_elem_list[0].num_params = 0; - proto_elem_list[1].protocol_uuid = UUID_PROTOCOL_RFCOMM; - proto_elem_list[1].num_params = 1; - proto_elem_list[1].params[0] = scn; - result &= SDP_AddProtocolList(sdp_handle, DUN_NUM_PROTO_ELEMS, proto_elem_list); - - /* add service class id list */ - result &= SDP_AddServiceClassIdList(sdp_handle, 1, &service_uuid); - - /* add service name */ - if (p_service_name != NULL) - { - result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE, - (UINT32)(strlen(p_service_name)+1), (UINT8 *) p_service_name); - } - - /* add audio feedback support */ - if((service_uuid == UUID_SERVCLASS_FAX) || - (service_uuid == UUID_SERVCLASS_DIALUP_NETWORKING)) - { - audio = (options & DUN_OPTIONS_AUDIO) ? TRUE : FALSE; - result &= SDP_AddAttribute(sdp_handle, ATTR_ID_AUDIO_FEEDBACK_SUPPORT, - BOOLEAN_DESC_TYPE, 1, &audio); - } - - /* add fax service class support */ - if(service_uuid == UUID_SERVCLASS_FAX) - { - class1 = (options & DUN_OPTIONS_CLASS1) ? TRUE : FALSE; - result &= SDP_AddAttribute(sdp_handle, ATTR_ID_FAX_CLASS_1_SUPPORT, - BOOLEAN_DESC_TYPE, 1, &class1); - - class20 = (options & DUN_OPTIONS_CLASS20) ? TRUE : FALSE; - result &= SDP_AddAttribute(sdp_handle, ATTR_ID_FAX_CLASS_2_0_SUPPORT, - BOOLEAN_DESC_TYPE, 1, &class20); - - class2 = (options & DUN_OPTIONS_CLASS2) ? TRUE : FALSE; - result &= SDP_AddAttribute(sdp_handle, ATTR_ID_FAX_CLASS_2_SUPPORT, - BOOLEAN_DESC_TYPE, 1, &class2); - } - - /* add browse group list */ - browse_list[0] = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; - result &= SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list); - - /* add profile descriptor list */ - if (service_uuid != UUID_SERVCLASS_SERIAL_PORT) /* BQB fix: BTA DG uses this for SPP */ - result &= SDP_AddProfileDescriptorList(sdp_handle, service_uuid, 0x0100); - - return (result ? DUN_SUCCESS : DUN_FAIL); -} - -/****************************************************************************** -** -** Function DUN_FindService -** -** Description This function is called by a client application to -** perform service discovery and retrieve DUN or Fax SDP -** record information from a server. Information is -** returned for the first service record found on the -** server that matches the service UUID. The callback -** function will be executed when service discovery is -** complete. There can only be one outstanding call to -** DUN_FindService() at a time; the application must wait -** for the callback before it makes another call to -** the function. -** -** Input Parameters: -** service_uuid: Indicates DUN or Fax. -** -** bd_addr: BD address of the peer device. -** -** p_db: Pointer to the discovery database. -** -** db_len: Length, in bytes, of the discovery database. -** -** p_cback: Pointer to the DUN_FindService() -** callback function. -** -** Output Parameters: -** None. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -UINT8 DUN_FindService(UINT16 service_uuid, BD_ADDR bd_addr, - tSDP_DISCOVERY_DB *p_db, UINT32 db_len, tDUN_FIND_CBACK *p_cback) -{ - tSDP_UUID uuid_list; - UINT16 num_attr; - BOOLEAN result = TRUE; - UINT16 dun_attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST, - ATTR_ID_PROTOCOL_DESC_LIST, - ATTR_ID_SERVICE_NAME, - ATTR_ID_AUDIO_FEEDBACK_SUPPORT, - ATTR_ID_FAX_CLASS_1_SUPPORT, - ATTR_ID_FAX_CLASS_2_0_SUPPORT, - ATTR_ID_FAX_CLASS_2_SUPPORT}; - - DUN_TRACE_API1("DUN_FindService uuid: %x", service_uuid); - - /* set up discovery database */ - uuid_list.len = LEN_UUID_16; - uuid_list.uu.uuid16 = service_uuid; - - num_attr = (service_uuid == UUID_SERVCLASS_FAX) ? - DUN_NUM_ATTR_FAX : DUN_NUM_ATTR_DUN; - - result = SDP_InitDiscoveryDb(p_db, db_len, 1, &uuid_list, num_attr, - (UINT16 *) dun_attr_list); - - if (result == TRUE) - { - /* store service_uuid and discovery db pointer */ - dun_cb.find_cb.p_db = p_db; - dun_cb.find_cb.service_uuid = service_uuid; - dun_cb.find_cb.p_cback = p_cback; - - /* perform service search */ - result = SDP_ServiceSearchAttributeRequest(bd_addr, p_db, dun_sdp_cback); - } - - return (result ? DUN_SUCCESS : DUN_FAIL); -} - -/******************************************************************************* -** -** Function DUN_Init -** -** Description This function is called to initialize the control block -** for this layer. It must be called before accessing any -** other API functions for this layer. It is typically called -** once during the start up of the stack. -** -** Returns void -** -*******************************************************************************/ -void DUN_Init (void) -{ - /* All fields are cleared; nonzero fields are reinitialized in appropriate function */ - memset(&dun_cb, 0, sizeof(tDUN_CB)); - -#if defined(DUN_INITIAL_TRACE_LEVEL) - dun_cb.trace_level = DUN_INITIAL_TRACE_LEVEL; -#else - dun_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ -#endif -} - -/****************************************************************************** -** -** Function DUN_SetTraceLevel -** -** Description Sets the trace level for DUN. If 0xff is passed, the -** current trace level is returned. -** -** Input Parameters: -** new_level: The level to set the DUN tracing to: -** 0xff-returns the current setting. -** 0-turns off tracing. -** >= 1-Errors. -** >= 2-Warnings. -** >= 3-APIs. -** >= 4-Events. -** >= 5-Debug. -** -** Returns The new trace level or current trace level if -** the input parameter is 0xff. -** -******************************************************************************/ -UINT8 DUN_SetTraceLevel (UINT8 new_level) -{ - if (new_level != 0xFF) - dun_cb.trace_level = new_level; - - return (dun_cb.trace_level); -} diff --git a/stack/dun/dun_int.h b/stack/dun/dun_int.h deleted file mode 100644 index 1e23bdc..0000000 --- a/stack/dun/dun_int.h +++ /dev/null @@ -1,63 +0,0 @@ -/***************************************************************************** -** -** Name: dun_int.h -** -** File: dun/fax type definitions -** -** Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef DUN_INT_H -#define DUN_INT_H - -#include "dun_api.h" -#include "sdp_api.h" - -/***************************************************************************** -** Constants -*****************************************************************************/ - -/***************************************************************************** -** DUN Control Blocks -******************************************************************************/ -/***************************************************************************** -** Type definitions -*****************************************************************************/ -/* Control block used by DUN_FindService(). */ -typedef struct -{ - tDUN_FIND_CBACK *p_cback; /* pointer to application callback */ - tSDP_DISCOVERY_DB *p_db; /* pointer to discovery database */ - UINT16 service_uuid; /* service UUID of search */ -} tDUN_FIND_CB; - -typedef struct -{ - tDUN_FIND_CB find_cb; - UINT8 trace_level; -} tDUN_CB; - -/***************************************************************************** -** External Definitions -*****************************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif -/* -** Define prototypes for global data -*/ -#if DUN_DYNAMIC_MEMORY == FALSE -DUN_API extern tDUN_CB dun_cb; -#else -DUN_API extern tDUN_CB *dun_cb_ptr; -#define dun_cb (*dun_cb_ptr) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* DUN_INT_H */ - diff --git a/stack/goep/goep_fs.c b/stack/goep/goep_fs.c deleted file mode 100644 index 4373341..0000000 --- a/stack/goep/goep_fs.c +++ /dev/null @@ -1,149 +0,0 @@ -/***************************************************************************** -** -** Name: goep_fs.c -** -** File: Implements the Object Interface for GOEP Profiles -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> -#include <ctype.h> -#include <stdio.h> - -#include "gki.h" -#include "btu.h" -#include "goep_fs.h" - -/***************************************************************************** -** -** Function: GOEP_OpenRsp -** -** Purpose: Report the status of tGOEP_OPEN_CBACK callback function. -** -** Parameters: fd - File handle. -** status - Status of the operation. -** file_size - total number of bytes in this file. -** event_id - event id as given in the tGOEP_OPEN_CBACK function. -** -** Returns: void -** -*****************************************************************************/ -void GOEP_OpenRsp (tGOEP_FD fd, tGOEP_STATUS status, UINT32 file_size, - UINT16 event_id) -{ - tGOEP_OPEN_RSP *p_evt_msg; - UINT16 size = sizeof(tGOEP_OPEN_RSP); - - /* get an GKI buffer and send the event along with the event data to BTU task */ - p_evt_msg = (tGOEP_OPEN_RSP *)GKI_getbuf(size); - if (p_evt_msg != NULL) - { - memset(&p_evt_msg->hdr, 0, sizeof(BT_HDR)); - p_evt_msg->hdr.event = event_id; - p_evt_msg->fd = fd; - p_evt_msg->status = status; - p_evt_msg->file_size = file_size; - - GKI_send_msg(BTU_TASK, BTU_HCI_RCV_MBOX, p_evt_msg); - } -} - -/***************************************************************************** -** -** Function: GOEP_ReadRsp -** -** Purpose: Report the status of tGOEP_READ_CBACK callback function. -** -** Parameters: fd - File handle. -** status - Status of the operation. -** bytes_read - total number of bytes read from the file. -** event_id - event id as given in the tGOEP_READ_CBACK function. -** -** Returns: void -** -*****************************************************************************/ -void GOEP_ReadRsp (tGOEP_FD fd, tGOEP_STATUS status, UINT16 bytes_read, - UINT16 event_id) -{ - tGOEP_READ_RSP *p_evt_msg; - UINT16 size = sizeof(tGOEP_READ_RSP); - - /* get an GKI buffer and send the event along with the event data to BTU task */ - p_evt_msg = (tGOEP_READ_RSP *)GKI_getbuf(size); - if (p_evt_msg != NULL) - { - memset(&p_evt_msg->hdr, 0, sizeof(BT_HDR)); - p_evt_msg->hdr.event = event_id; - p_evt_msg->fd = fd; - p_evt_msg->status = status; - p_evt_msg->bytes_read = bytes_read; - - GKI_send_msg(BTU_TASK, BTU_HCI_RCV_MBOX, p_evt_msg); - } -} - -/***************************************************************************** -** -** Function: GOEP_WriteRsp -** -** Purpose: Report the status of tGOEP_WRITE_CBACK callback function. -** -** Parameters: fd - File handle. -** status - Status of the operation. -** event_id - event id as given in the tGOEP_WRITE_CBACK function. -** -** Returns: void -** -*****************************************************************************/ -void GOEP_WriteRsp (tGOEP_FD fd, tGOEP_STATUS status, UINT16 event_id) -{ - tGOEP_WRITE_RSP *p_evt_msg; - UINT16 size = sizeof(tGOEP_WRITE_RSP); - - /* get an GKI buffer and send the event along with the event data to BTU task */ - p_evt_msg = (tGOEP_WRITE_RSP *)GKI_getbuf(size); - if (p_evt_msg != NULL) - { - memset(&p_evt_msg->hdr, 0, sizeof(BT_HDR)); - p_evt_msg->hdr.event = event_id; - p_evt_msg->fd = fd; - p_evt_msg->status = status; - - GKI_send_msg(BTU_TASK, BTU_HCI_RCV_MBOX, p_evt_msg); - } -} - -/***************************************************************************** -** -** Function: GOEP_DirentryRsp -** -** Purpose: Report the status of tGOEP_DIRENTRY_CBACK callback function. -** -** Parameters: status - GOEP_OK if p_entry points to a valid entry. -** GOEP_EODIR if no more entries (p_entry is ignored). -** GOEP_FAIL if any errors have occurred. -** event_id - event id as given in the tGOEP_DIRENTRY_CBACK function. -** -** Returns: void -** -*****************************************************************************/ -void GOEP_DirentryRsp (tGOEP_STATUS status, UINT16 event_id) -{ - tGOEP_DIRENTRY_RSP *p_evt_msg; - UINT16 size = sizeof(tGOEP_DIRENTRY_RSP); - - /* get an GKI buffer and send the event along with the event data to BTU task */ - p_evt_msg = (tGOEP_DIRENTRY_RSP *)GKI_getbuf(size); - if (p_evt_msg != NULL) - { - memset(&p_evt_msg->hdr, 0, sizeof(BT_HDR)); - p_evt_msg->hdr.event = event_id; - p_evt_msg->status = status; - - GKI_send_msg(BTU_TASK, BTU_HCI_RCV_MBOX, p_evt_msg); - } -} - diff --git a/stack/goep/goep_int.h b/stack/goep/goep_int.h deleted file mode 100644 index 476d55a..0000000 --- a/stack/goep/goep_int.h +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************************** -** -** Name: goep_int.h -** -** File: Generic Object Exchange Profile Internal Definitions -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef GOEP_INT_H -#define GOEP_INT_H - -#include "bt_target.h" -#include "goep_util.h" - - - -/***************************************************************************** -** Constants -*****************************************************************************/ -#define GOEP_PROTOCOL_COUNT 3 - - - -/***************************************************************************** -** Main Control Block Structure -*****************************************************************************/ - -typedef struct -{ - UINT8 trace_level; -} tGOEP_CB; - -/***************************************************************************** -** Function Prototypes -*****************************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif - -#if GOEP_DYNAMIC_MEMORY == FALSE -GOEP_API extern tGOEP_CB goep_cb; -#else -GOEP_API extern tGOEP_CB *goep_cb_ptr; -#define goep_cb (*goep_cb_ptr) -#endif - - - -#ifdef __cplusplus -} -#endif - -#endif /* GOEP_INT_H */ diff --git a/stack/goep/goep_trace.c b/stack/goep/goep_trace.c deleted file mode 100644 index 137f2cd..0000000 --- a/stack/goep/goep_trace.c +++ /dev/null @@ -1,35 +0,0 @@ -/****************************************************************************** -** -** Name: goep_trace.c -** -** Description: This file contains the debug display prototypes -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -******************************************************************************/ -#include "bt_target.h" - -#if (defined(GOEP_INCLUDED) && GOEP_INCLUDED == TRUE) - -#include "goep_int.h" - -#if (defined (BT_USE_TRACES) && BT_USE_TRACES == TRUE) - - -char *GOEP_ErrorName (tGOEP_ERRORS error) -{ - switch (error) - { - case GOEP_SUCCESS: return "GOEP_SUCCESS (0x00)"; - case GOEP_ERROR: return "GOEP_ERROR (0x01)"; - case GOEP_RESOURCES: return "GOEP_RESOURCES (0x02)"; - case GOEP_INVALID_PARAM: return "GOEP_INVALID_PARAM (0x03)"; - default: return "UNKNOWN GOEP ERROR"; - } -} - -/* end if BT_TRACE_VERBOSE */ -#endif - -#endif /* GOEP_INCLUDED */ diff --git a/stack/goep/goep_util.c b/stack/goep/goep_util.c deleted file mode 100644 index 099177a..0000000 --- a/stack/goep/goep_util.c +++ /dev/null @@ -1,504 +0,0 @@ -/***************************************************************************** -** -** Name: goep_util.c -** -** File: Implements the Utility API of the GOEP Profile -** -** Copyright (c) 2000-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> - -#include "btm_api.h" -#include "btu.h" /* BTU_HCI_RCV_MBOX */ -#include "goep_util.h" -#include "goep_fs.h" -#include "goep_int.h" -#include "rfcdefs.h" /* BT_PSM_RFCOMM */ -#include "wcassert.h" /* WC_ASSERT() */ -#include "l2c_api.h" /* WC_ASSERT() */ - -#if GOEP_DYNAMIC_MEMORY == FALSE -tGOEP_CB goep_cb; -#endif - -/******************************************************************************* -** -** Function GOEP_Init -** -** Description GOEP initialization -** -** Returns nothing -** -*******************************************************************************/ -void GOEP_Init(void) -{ - memset(&goep_cb, 0, sizeof(tGOEP_CB)); - -#if defined(GOEP_INITIAL_TRACE_LEVEL) - goep_cb.trace_level = GOEP_INITIAL_TRACE_LEVEL; -#else - goep_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ -#endif - -} - - - -/***************************************************************************** -** -** Function: GOEP_SetSecurityLevel() -** -** Purpose: Register security & encryption level for GOEP server. -** This is not to be used for the GOEP command server. -** -** -** Parameters: -** char *pName service name; Typically GOEP_DEFAULT_SERVICE_NAME -** Not used if BTM_SEC_SERVICE_NAME_LEN is 0. -** UINT8 level Security level; The mandatory GOEP security level -** GOEP_DEFAULT_SECURITY, is or'd in. -** -** -** Returns: (BOOLEAN) TRUE if OK -** FALSE if a bad parameter -** -*****************************************************************************/ -BOOLEAN GOEP_SetSecurityLevel (BOOLEAN bOrig, char *pName, UINT32 service, - UINT8 level, UINT8 scn) -{ -#if BTM_SEC_SERVICE_NAME_LEN > 0 - char sec_name[BTM_SEC_SERVICE_NAME_LEN+1]; -#endif - - /* Guarantee that there is a name */ - if (!pName) - { - pName = ""; - } - -#if BTM_SEC_SERVICE_NAME_LEN > 0 - GOEP_TRACE_EVENT4("GOEP: Set Security Mode; name '%s'; service %d; level 0x%02x; scn %d", - pName, service, level, scn); - - /* Guarantee that name is not too long */ - if (strlen (pName) >= BTM_SEC_SERVICE_NAME_LEN) - { - BCM_STRNCPY_S(sec_name, sizeof(sec_name), pName, BTM_SEC_SERVICE_NAME_LEN); - sec_name[BTM_SEC_SERVICE_NAME_LEN] = '\0'; - pName = sec_name; - } -#else - GOEP_TRACE_EVENT3("GOEP: Set Security Mode: service id %d; level 0x%02x; scn %d", - service, level, scn); -#endif - - /* Register with Security Manager for the specific security level */ - if (!BTM_SetSecurityLevel (bOrig, pName, (UINT8)service, level, BT_PSM_RFCOMM, - BTM_SEC_PROTO_RFCOMM, scn)) - { - GOEP_TRACE_WARNING1("GOEP: Security Registration failed for %s", pName); - return (FALSE); - } - - return (TRUE); -} - -/***************************************************************************** -** -** Function: GOEP_SetTraceLevel -** -** Purpose: This function changes the trace level -** -** Returns: Nothing -*****************************************************************************/ -void GOEP_SetTraceLevel(UINT8 level) -{ - goep_cb.trace_level = level; -} - -/******************************************************************************* -** -** Function GOEP_FreeBuf -** -** Description free memory for specified packet -** -** Returns void -** -*******************************************************************************/ -void GOEP_FreeBuf (void **p_buf) -{ - if (p_buf && *p_buf) - { - GKI_freebuf(*p_buf); - *p_buf = NULL; - } -} - -/******************************************************************************* -** -** Function GOEP_SendMsg -** -** Description send a message to BTU task -** -** Returns void -** -*******************************************************************************/ -void GOEP_SendMsg (void *p_msg) - -{ - if(p_msg) - { - GKI_send_msg(BTU_TASK, BTU_HCI_RCV_MBOX, p_msg); - } -} - -/***************************************************************************** -** -** Function: GOEP_Register() -** -** Purpose: Register an OBEX profile with SDP -** -** Parameters: -** -** char *p_name service name; optional (may be NULL) -** UINT32 *phSDP handle to the created record; cannot be NULL -** UINT8 scn scn desired for the service; must be > 0 -** UINT16 version version of the service; optional (may be 0) -** -** Returns: (tGOEP_ERRORS) GOEP_SUCCESS if ok; GOEP_ERROR on error -** -** Notes: -** -** -** Preconditions: -** - phSDP must be set (to return the SDP record handle) -** - scn must be set -** -** Postconditions: -** - -** -*****************************************************************************/ -tGOEP_ERRORS GOEP_Register (char *p_name, - UINT32 *phSDP, - UINT8 scn, - UINT8 num_srv_class, - UINT16 *p_service_class, - UINT16 profile_id, - UINT16 version) -{ - tGOEP_ERRORS status = GOEP_ERROR; - tSDP_PROTOCOL_ELEM protoList [GOEP_PROTOCOL_COUNT]; - UINT16 browse; - - /* GOEP_TRACE_EVENT4("GOEP: Register with SDP: name %s, scn %d, class %#x, version %d)", - p_name ? p_name : "NULL", - (UINT16)scn, - (UINT16)p_service_class[0], - version); */ - - /* parameter checking */ - WC_ASSERT(phSDP); - WC_ASSERT(scn); - - /* parameter checking */ - if (!(phSDP && scn)) - { - return (GOEP_INVALID_PARAM); - } - - *phSDP = SDP_CreateRecord(); - WC_ASSERT(*phSDP); - GOEP_TRACE_API2("GOEP: Register with SDP: scn %d, record:0x%08x", scn, *phSDP); - - /* could a SDP handle be allocated? */ - if (*phSDP == 0) - { - return (GOEP_RESOURCES); - } - - /* add service class */ - if (SDP_AddServiceClassIdList(*phSDP, num_srv_class, p_service_class)) - { - /* add protocol list, including RFCOMM scn */ - protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP; - protoList[0].num_params = 0; - protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM; - protoList[1].num_params = 1; - protoList[1].params[0] = scn; - protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX; - protoList[2].num_params = 0; - -/* coverity[uninit_use_in_call] -FALSE-POSITIVE: coverity says -Event uninit_use_in_call: Using uninitialized element of array "(protoList)->params" in call to function "SDP_AddProtocolList" -Event uninit_use_in_call: Using uninitialized value "(protoList)->num_params" in call to function "SDP_AddProtocolList" -Event uninit_use_in_call: Using uninitialized value "(protoList)->protocol_uuid" in call to function "SDP_AddProtocolList" -SDP_AddProtocolList() uses (protoList)->params only when (protoList)->num_params is non-0 -*/ - if (SDP_AddProtocolList(*phSDP, GOEP_PROTOCOL_COUNT, protoList)) - { - /* optional: if name is not NULL, add a name entry */ - if (p_name && p_name[0] ) - { - SDP_AddAttribute(*phSDP, - (UINT16)ATTR_ID_SERVICE_NAME, - (UINT8)TEXT_STR_DESC_TYPE, - (UINT32)(strlen(p_name) + 1), - (UINT8 *)p_name); - } /* end of setting optional name */ - /* Add in the Bluetooth Profile Descriptor List for IrMCSync [Sync s7.1.2] */ - if (version) - { - SDP_AddProfileDescriptorList(*phSDP, profile_id, version); - } /* end of setting optional profile version */ - status = GOEP_SUCCESS; - } /* end of setting mandatory protocol list */ - } /* end of setting mandatory service class */ - - /* Make the service browseable */ - browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; - if (status == GOEP_SUCCESS && SDP_AddUuidSequence (*phSDP, - ATTR_ID_BROWSE_GROUP_LIST, - 1, - &browse) == FALSE) - { - status = GOEP_ERROR; - } - - if (status != GOEP_SUCCESS) - { - SDP_DeleteRecord(*phSDP); - GOEP_TRACE_DEBUG1("GOEP_Register status: %d", status); - } - else - { - GOEP_TRACE_EVENT1("GOEP: Register with SDP returns handle 0x%08x", *phSDP); - } - - return (status); -} - -/***************************************************************************** -** -** Function: GOEP_Register2() -** -** Purpose: Register an OBEX 1.4 profile with SDP -** -** Parameters: -** -** char *p_name service name; optional (may be NULL) -** UINT32 *phSDP handle to the created record; cannot be NULL -** UINT8 scn scn desired for the service; must be > 0 -** UINT16 psm psm desired for the service; must be an legal L2CAP dynamic PSM -** UINT16 version version of the service; optional (may be 0) -** -** Returns: (tGOEP_ERRORS) GOEP_SUCCESS if ok; GOEP_ERROR on error -** -** Notes: -** -** -** Preconditions: -** - phSDP must be set (to return the SDP record handle) -** - psm must be set -** -** Postconditions: -** - -** -*****************************************************************************/ -tGOEP_ERRORS GOEP_Register2 (char *p_name, - UINT32 *phSDP, - UINT16 psm, - UINT8 num_srv_class, - UINT16 *p_service_class, - UINT16 profile_id, - UINT16 version) -{ - tGOEP_ERRORS status = GOEP_ERROR; - tSDP_PROTOCOL_ELEM protoList [GOEP_PROTOCOL_COUNT]; - UINT16 browse; - UINT16 num_elem; - UINT8 *p, array[3]; - - /* GOEP_TRACE_EVENT4("GOEP: Register2 with SDP: name %s, psm 0x%x, class %#x, version %d)", - p_name ? p_name : "NULL", - (UINT16)psm, - (UINT16)p_service_class[0], - version); */ - - /* parameter checking */ - WC_ASSERT(phSDP); - - /* parameter checking */ - if (!(phSDP && L2C_IS_VALID_PSM(psm))) - { - return (GOEP_INVALID_PARAM); - } - - *phSDP = SDP_CreateRecord(); - WC_ASSERT(*phSDP); - GOEP_TRACE_API2("GOEP: Register with SDP(2): psm 0x%x, record:0x%08x", psm, *phSDP); - - /* could a SDP handle be allocated? */ - if (*phSDP == 0) - { - return (GOEP_RESOURCES); - } - - /* add service class */ - if (SDP_AddServiceClassIdList(*phSDP, num_srv_class, p_service_class)) - { - /* add protocol list, including RFCOMM scn */ - num_elem=0; - protoList[num_elem].protocol_uuid = UUID_PROTOCOL_L2CAP; - protoList[num_elem].num_params = 0; - num_elem++; - protoList[num_elem].protocol_uuid = UUID_PROTOCOL_OBEX; - protoList[num_elem].num_params = 0; - num_elem++; -/* coverity[uninit_use_in_call] -FALSE-POSITIVE: coverity says -Event uninit_use_in_call: Using uninitialized element of array "(protoList)->params" in call to function "SDP_AddProtocolList" -Event uninit_use_in_call: Using uninitialized value "(protoList)->num_params" in call to function "SDP_AddProtocolList" -Event uninit_use_in_call: Using uninitialized value "(protoList)->protocol_uuid" in call to function "SDP_AddProtocolList" -SDP_AddProtocolList() uses (protoList)->params only when (protoList)->num_params is non-0 -*/ - if (SDP_AddProtocolList(*phSDP, num_elem, protoList)) - { - p = array; - UINT16_TO_BE_STREAM (p, psm); - SDP_AddAttribute (*phSDP, ATTR_ID_OBX_OVR_L2CAP_PSM, UINT_DESC_TYPE, 2, array); - - /* optional: if name is not NULL, add a name entry */ - if (p_name && p_name[0] ) - { - SDP_AddAttribute(*phSDP, - (UINT16)ATTR_ID_SERVICE_NAME, - (UINT8)TEXT_STR_DESC_TYPE, - (UINT32)(strlen(p_name) + 1), - (UINT8 *)p_name); - } /* end of setting optional name */ - /* Add in the Bluetooth Profile Descriptor List for IrMCSync [Sync s7.1.2] */ - if (version) - { - SDP_AddProfileDescriptorList(*phSDP, profile_id, version); - } /* end of setting optional profile version */ - status = GOEP_SUCCESS; - } /* end of setting mandatory protocol list */ - } /* end of setting mandatory service class */ - - /* Make the service browseable */ - browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; - if (status == GOEP_SUCCESS && SDP_AddUuidSequence (*phSDP, - ATTR_ID_BROWSE_GROUP_LIST, - 1, - &browse) == FALSE) - { - status = GOEP_ERROR; - } - - if (status != GOEP_SUCCESS) - { - SDP_DeleteRecord(*phSDP); - GOEP_TRACE_DEBUG1("GOEP_Register status: %d", status); - } - else - { - GOEP_TRACE_EVENT1("GOEP: Register with SDP returns handle 0x%08x", *phSDP); - } - - - return (status); -} - -/***************************************************************************** -** -** Function: GOEP_AddProtoLists() -** -** Purpose: Add the AdditionalProtocolDescriptorLists attribute -** to a SDP record -** -** Parameters: -** -** UINT32 sdp_hdl the SDP record handle -** UINT8 scn scn desired for the service; must be > 0 -** -** Returns: (tGOEP_ERRORS) GOEP_SUCCESS if ok; GOEP_ERROR on error -** -** Notes: -** -** -** Preconditions: -** - sdp_hdl must be set (to the SDP record handle from GOEP_Register()) -** - scn must be set -** -** Postconditions: -** - -** -*****************************************************************************/ -#if (BPP_INCLUDED == TRUE) -tGOEP_ERRORS GOEP_AddProtoLists ( UINT32 sdp_hdl, UINT8 scn) -{ - tGOEP_ERRORS status = GOEP_ERROR; - tSDP_PROTO_LIST_ELEM proto_list_elem; - tSDP_PROTOCOL_ELEM *p_proto_list; - - /* - GOEP_TRACE_EVENT4("GOEP: Register with SDP: name %s, scn %d, class %#x, version %d)", - p_name ? p_name : "NULL", - (UINT16)scn, - (UINT16)p_service_class[0], - version); - */ - - /* parameter checking */ - WC_ASSERT(sdp_hdl); - WC_ASSERT(scn); - - /* parameter checking */ - if (!(sdp_hdl && scn)) - { - return (GOEP_INVALID_PARAM); - } - - proto_list_elem.num_elems = 0; - p_proto_list = &proto_list_elem.list_elem[proto_list_elem.num_elems++]; - p_proto_list->num_params = 0; - p_proto_list->protocol_uuid = UUID_PROTOCOL_L2CAP; - p_proto_list = &proto_list_elem.list_elem[proto_list_elem.num_elems++]; - p_proto_list->num_params = 1; - p_proto_list->params[0] = scn; - p_proto_list->protocol_uuid = UUID_PROTOCOL_RFCOMM; - p_proto_list = &proto_list_elem.list_elem[proto_list_elem.num_elems++]; - p_proto_list->num_params = 0; - p_proto_list->protocol_uuid = UUID_PROTOCOL_OBEX; - - /* add protocol list, including RFCOMM scn */ - if(SDP_AddAdditionProtoLists( sdp_hdl, 1, &proto_list_elem)) - status = GOEP_SUCCESS; - - GOEP_TRACE_DEBUG1("GOEP_AddProtoLists status: %s", GOEP_ErrorName(status)); - - return (status); -} -#endif - -/***************************************************************************** -** -** Function: goep_dummy -** -** Purpose: This is to work around a GCC build linking problem -** -** Returns: none -** -*****************************************************************************/ -#if (RPC_INCLUDED == TRUE && RPC_TRACE_ONLY == TRUE && GOEP_FS_INCLUDED == TRUE) -static void goep_dummy(void) -{ - GOEP_OpenRsp(0, 0, 0, 0); -} -#endif /* RPC stuff */ - - diff --git a/stack/hid/hidd_api.c b/stack/hid/hidd_api.c deleted file mode 100644 index 7ee41ea..0000000 --- a/stack/hid/hidd_api.c +++ /dev/null @@ -1,536 +0,0 @@ -/*****************************************************************************/ -/* */ -/* Name: hidd_api.c */ -/* */ -/* Description: this file contains the Device HID API entry points */ -/* */ -/* */ -/* Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved. */ -/* WIDCOMM Bluetooth Core. Proprietary and confidential. */ -/*****************************************************************************/ - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include "wcassert.h" - -#include "gki.h" -#include "bt_types.h" -#include "hiddefs.h" -#include "hidd_api.h" -#include "hidd_int.h" -#include "btm_api.h" - -#include "hcimsgs.h" -#include "btu.h" -#include "sdpdefs.h" -#include "sdp_api.h" - -static const UINT8 HidDevLangList[] = HID_DEV_LANGUAGELIST; - -#ifndef HID_DEV_BOOT_DEVICE -#define HID_DEV_BOOT_DEVICE TRUE -#endif - - -/******************************************************************************* -** -** Function HID_DevSetSDPRecord -** -** Description This function should be called at startup to create the -** device SDP record -** -** Returns 0 if error else sdp handle for the record. -** -*******************************************************************************/ -UINT32 HID_DevSetSDPRecord (tHID_DEV_SDP_INFO *p_sdp_info) -{ - UINT32 sdp_handle; - tSDP_PROTOCOL_ELEM protocol_list[2]; - tSDP_PROTO_LIST_ELEM additional_list; - UINT16 u16; - UINT8 u8; - UINT8 *pRepDescriptor, *pd; - char buf[2]; - - if( p_sdp_info == NULL ) - return (0); - - /* Create an SDP record for the ctrl/data or notification channel */ - if ((sdp_handle = SDP_CreateRecord()) == FALSE) - { - HIDD_TRACE_ERROR0 ("Could not create service record"); - return (0); - } - - /* Add the UUID to the Service Class ID List */ - u16 = UUID_SERVCLASS_HUMAN_INTERFACE; - SDP_AddServiceClassIdList(sdp_handle, 1, &u16); - - /* Build the protocol descriptor list */ - protocol_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP; - protocol_list[0].num_params = 1; - protocol_list[0].params[0] = HID_PSM_CONTROL; - - protocol_list[1].num_params = 0; - protocol_list[1].protocol_uuid = UUID_PROTOCOL_HIDP; - - SDP_AddProtocolList(sdp_handle, 2, protocol_list); - - /* Language base */ - SDP_AddLanguageBaseAttrIDList (sdp_handle, LANG_ID_CODE_ENGLISH, LANG_ID_CHAR_ENCODE_UTF8, - LANGUAGE_BASE_ID); - - /* Add the Bluetooth Profile Descriptor List (profile version number) */ - SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_HUMAN_INTERFACE, 0x0100); - - /* Add the PSM of the interrupt channel to the Additional Protocol Descriptor List */ - additional_list.num_elems = 2; - additional_list.list_elem[0].protocol_uuid = UUID_PROTOCOL_L2CAP; - additional_list.list_elem[0].num_params = 1; - additional_list.list_elem[0].params[0] = HID_PSM_INTERRUPT; - additional_list.list_elem[1].protocol_uuid = UUID_PROTOCOL_HIDP; - additional_list.list_elem[1].num_params = 0; - - SDP_AddAdditionProtoLists (sdp_handle, 1, &additional_list); - - if( p_sdp_info->svc_name[0] != '\0' ) - SDP_AddAttribute (sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE, - (UINT8)(strlen(p_sdp_info->svc_name)+1), (UINT8 *)p_sdp_info->svc_name); - - if( p_sdp_info->svc_descr[0] != '\0' ) - SDP_AddAttribute (sdp_handle, ATTR_ID_SERVICE_DESCRIPTION, TEXT_STR_DESC_TYPE, - (UINT8)(strlen(p_sdp_info->svc_descr)+1), (UINT8 *)p_sdp_info->svc_descr); - - if( p_sdp_info->prov_name[0] != '\0' ) - SDP_AddAttribute (sdp_handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE, - (UINT8)(strlen(p_sdp_info->prov_name)+1), (UINT8 *)p_sdp_info->prov_name); - - /* HID parser version */ - UINT16_TO_BE_FIELD(buf,p_sdp_info->hpars_ver) ; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_PARSER_VERSION, UINT_DESC_TYPE, 2, (UINT8 *)buf); - - /* HID subclass */ - u8 = p_sdp_info->sub_class; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_DEVICE_SUBCLASS, UINT_DESC_TYPE, 1, &u8); - - /* HID country code */ - u8 = p_sdp_info->ctry_code; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_COUNTRY_CODE, UINT_DESC_TYPE, 1, &u8); - - /* HID Virtual Cable */ - u8 = HID_DEV_VIRTUAL_CABLE; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_VIRTUAL_CABLE, BOOLEAN_DESC_TYPE, 1, &u8); - - /* HID reconnect initiate */ - u8 = HID_DEV_RECONN_INITIATE; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_RECONNECT_INITIATE, BOOLEAN_DESC_TYPE, 1, &u8); - - /* HID report descriptor */ - if ( NULL != (pRepDescriptor = (UINT8 *)GKI_getbuf((UINT16)(p_sdp_info->dscp_info.dl_len + 8 ))) ) - { - pd = pRepDescriptor; - *pd++ = (UINT8)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - *pd++ = (UINT8)(p_sdp_info->dscp_info.dl_len + 4); - *pd++ = (UINT8)((UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE); - *pd++ = (UINT8)(HID_SDP_DESCRIPTOR_REPORT); - *pd++ = (UINT8)((TEXT_STR_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - *pd++ = (UINT8)(p_sdp_info->dscp_info.dl_len); - memcpy (pd, p_sdp_info->dscp_info.dsc_list, p_sdp_info->dscp_info.dl_len); - pd += p_sdp_info->dscp_info.dl_len; - - SDP_AddAttribute (sdp_handle, ATTR_ID_HID_DESCRIPTOR_LIST, DATA_ELE_SEQ_DESC_TYPE, - (UINT32)(pd - pRepDescriptor), pRepDescriptor); - GKI_freebuf( pRepDescriptor ); - } - else - { - SDP_DeleteRecord( sdp_handle ); /* delete freshly allocated record */ - HIDD_TRACE_ERROR1( "HID_DevSetSDPRecord(): SDP creation failed: no memory for rep dscr len: %d", - p_sdp_info->dscp_info.dl_len ); - return 0; - } - /* HID language base list */ - SDP_AddAttribute (sdp_handle, ATTR_ID_HID_LANGUAGE_ID_BASE, DATA_ELE_SEQ_DESC_TYPE, - sizeof (HidDevLangList), (UINT8 *)HidDevLangList); - - /* HID SDP disable (i.e. SDP while Control and Interrupt are up) */ -#if (MAX_L2CAP_CHANNELS > 2) - u8 = 0; -#else - u8 = 1; -#endif - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_SDP_DISABLE, BOOLEAN_DESC_TYPE, 1, &u8); - -#if defined(HID_DEV_BATTERY_POW) - /* HID battery power */ - u8 = HID_DEV_BATTERY_POW; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_BATTERY_POWER, BOOLEAN_DESC_TYPE, 1, &u8); -#endif - -#if defined(HID_DEV_REMOTE_WAKE) - /* HID remote wakeup capable */ - u8 = HID_DEV_REMOTE_WAKE; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_REMOTE_WAKE, BOOLEAN_DESC_TYPE, 1, &u8); -#endif - - /* Link supervision timeout */ - UINT16_TO_BE_FIELD(buf,HID_DEV_LINK_SUPERVISION_TO) ; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_LINK_SUPERVISION_TO, UINT_DESC_TYPE, 2, (UINT8 *)buf); - - /* HID remote wakeup capable */ - u8 = HID_DEV_NORMALLY_CONN; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_NORMALLY_CONNECTABLE, BOOLEAN_DESC_TYPE, 1, &u8); - - /* HID BOOT Device */ - u8 = HID_DEV_BOOT_DEVICE; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_BOOT_DEVICE, BOOLEAN_DESC_TYPE, 1, &u8); - - u16 = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; - SDP_AddUuidSequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &u16); - - /* SSR host max latency */ - if (p_sdp_info->ssr_max_latency != HID_SSR_PARAM_INVALID) - { - UINT16_TO_BE_FIELD(buf,HID_DEV_LINK_SUPERVISION_TO) ; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_SSR_HOST_MAX_LAT, UINT_DESC_TYPE, 2, (UINT8 *)buf); - } - - /* SSR host min timeout */ - if (p_sdp_info->ssr_max_latency != HID_SSR_PARAM_INVALID) - { - UINT16_TO_BE_FIELD(buf,HID_DEV_LINK_SUPERVISION_TO) ; - SDP_AddAttribute(sdp_handle, ATTR_ID_HID_SSR_HOST_MIN_TOUT, UINT_DESC_TYPE, 2, (UINT8 *)buf); - } - return (sdp_handle); -} - -/******************************************************************************* -** -** Function HID_DevInit -** -** Description This function initializes the control block and trace variable -** -** Returns void -** -*******************************************************************************/ -void HID_DevInit (void) -{ - memset(&hd_cb, 0, sizeof(tHIDDEV_CB)); - - /* Initialize control channel L2CAP configuration */ - hd_cb.l2cap_ctrl_cfg.mtu_present = TRUE; - hd_cb.l2cap_ctrl_cfg.mtu = HID_DEV_MTU_SIZE; - - /* Initialize interrupt channel L2CAP configuration */ - hd_cb.l2cap_int_cfg.mtu_present = TRUE; - hd_cb.l2cap_int_cfg.mtu = HID_DEV_MTU_SIZE; - - hd_cb.conn.timer_entry.param = (UINT32) hidd_proc_repage_timeout; -#if defined(HID_INITIAL_TRACE_LEVEL) - hd_cb.trace_level = HID_INITIAL_TRACE_LEVEL; -#else - hd_cb.trace_level = BT_TRACE_LEVEL_NONE; -#endif -} - -/******************************************************************************* -** -** Function HID_DevRegister -** -** Description This function must be called at startup so the device receive -** HID related events and call other HID API Calls. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevRegister( tHID_DEV_REG_INFO *p_reg_info ) -{ - tHID_STATUS st; - BD_ADDR bt_bd_any = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - UINT16 conn_able; - - if( p_reg_info == NULL || - p_reg_info->app_cback == NULL ) - return HID_ERR_INVALID_PARAM; - - if( hd_cb.reg_flag ) - return HID_ERR_ALREADY_REGISTERED; - - /* Check if the host address is provided */ - if( memcmp( p_reg_info->host_addr, bt_bd_any, BD_ADDR_LEN ) ) - { - hd_cb.host_known = TRUE; - memcpy( hd_cb.host_addr, p_reg_info->host_addr, BD_ADDR_LEN ); - hd_cb.dev_state = HID_DEV_ST_NO_CONN ; - - /* When host address is provided, connectibility is determined by the - SDP attribute, otherwise device has to be connectable for initial - pairing process with the host */ - conn_able = (UINT16) HID_DEV_NORMALLY_CONN; - } - else - { - hd_cb.host_known = FALSE; - conn_able = BTM_CONNECTABLE; - } - - hd_cb.virtual_cable = HID_DEV_VIRTUAL_CABLE; - - /* Copy QoS parameters if provided */ - if( p_reg_info->qos_info ) - { - memcpy( &(hd_cb.qos_info), p_reg_info->qos_info, sizeof( tHID_DEV_QOS_INFO ) ); - hd_cb.use_qos_flg = TRUE; - } - else - { - hd_cb.use_qos_flg = FALSE; - } - - hd_cb.callback = p_reg_info->app_cback ; - - /* Register with L2CAP */ - if( (st = hidd_conn_reg()) != HID_SUCCESS ) - { - return st; - } - -#if (!defined(HID_DEV_SET_CONN_MODE) || HID_DEV_SET_CONN_MODE == TRUE) - if( BTM_SetConnectability (conn_able, HID_DEV_PAGE_SCAN_WIN, HID_DEV_PAGE_SCAN_INT) != BTM_SUCCESS ) - return HID_ERR_SET_CONNABLE_FAIL ; -#endif - - hd_cb.reg_flag = TRUE; - hd_cb.unplug_on = FALSE; - - HIDD_TRACE_DEBUG0 ("HID_DevRegister successful"); - return HID_SUCCESS; -} - -/******************************************************************************* -** -** Function HID_DevDeregister -** -** Description This function may be used to remove HID service records and -** deregister from L2CAP. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevDeregister( void ) -{ - if( !hd_cb.reg_flag ) - return HID_ERR_NOT_REGISTERED; - - hidd_mgmt_process_evt( HID_API_DISCONNECT, NULL ) ; /* Disconnect first */ - /* Deregister with L2CAP */ - hidd_conn_dereg() ; - hd_cb.reg_flag = FALSE; - return HID_SUCCESS; -} - -/******************************************************************************* -** -** Function HID_DevConnect -** -** Description This function may be used to initiate a connection to the host.. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevConnect( void ) -{ - if( hd_cb.reg_flag == FALSE ) - return HID_ERR_NOT_REGISTERED; - - return hidd_mgmt_process_evt( HID_API_CONNECT, NULL ) ; /* This will initiate connection */ -} - -/******************************************************************************* -** -** Function HID_DevDisconnect -** -** Description This function may be used to disconnect from the host -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevDisconnect( void ) -{ - if( hd_cb.reg_flag == FALSE ) - return HID_ERR_NOT_REGISTERED; - - return hidd_mgmt_process_evt( HID_API_DISCONNECT, NULL ) ; /* This will initiate disconnection */ -} - -/******************************************************************************* -** -** Function HID_DevHandShake -** -** Description This function may be used to send HAND-SHAKE to host -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevHandShake( UINT8 res_code ) -{ - tHID_SND_DATA_PARAMS hsk_data; - - if( hd_cb.reg_flag == FALSE ) - return HID_ERR_NOT_REGISTERED; - - hsk_data.trans_type = HID_TRANS_HANDSHAKE ; - hsk_data.ctrl_ch = TRUE ; - hsk_data.param = res_code; - hsk_data.buf = NULL; - - return hidd_mgmt_process_evt( HID_API_SEND_DATA, &hsk_data ) ; -} - -/******************************************************************************* -** -** Function HID_DevVirtualUnplug -** -** Description This function may be used to send VIRTUAL-UNPLUG to host -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevVirtualUnplug ( void ) -{ - tHID_STATUS st; - - tHID_SND_DATA_PARAMS vup_data; - - if( hd_cb.reg_flag == FALSE ) - return HID_ERR_NOT_REGISTERED; - - vup_data.trans_type = HID_TRANS_CONTROL ; - vup_data.ctrl_ch = TRUE ; - vup_data.param = HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG; - vup_data.buf = NULL; - - if( (st = hidd_mgmt_process_evt(HID_API_SEND_DATA, &vup_data)) == HID_SUCCESS ) - { - hd_cb.unplug_on = TRUE; - } - - return st; -} - -/******************************************************************************* -** -** Function HID_DevSendData -** -** Description This function may be used to send input reports to host -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevSendData ( BOOLEAN control_ch, UINT8 rep_type, BT_HDR *data_buf ) -{ - tHID_SND_DATA_PARAMS snd_data; - - WC_ASSERT(control_ch != TRUE && control_ch != FALSE); - - if( hd_cb.reg_flag == FALSE ) - return HID_ERR_NOT_REGISTERED; - - snd_data.trans_type = HID_TRANS_DATA ; - snd_data.ctrl_ch = control_ch ; - snd_data.param = rep_type; - snd_data.buf = data_buf; - - return hidd_mgmt_process_evt( HID_API_SEND_DATA, &snd_data ) ; -} - -/******************************************************************************* -** -** Function HID_DevSetSecurityLevel -** -** Description This function set security level for the Hid Device service. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevSetSecurityLevel( char serv_name[], UINT8 sec_lvl ) -{ - hd_cb.sec_mask = sec_lvl; - - if (sec_lvl == 0) - { - if (!BTM_SetSecurityLevel (FALSE, serv_name, BTM_SEC_SERVICE_HID_NOSEC_CTRL, - BTM_SEC_NONE, HID_PSM_CONTROL, BTM_SEC_PROTO_HID , HIDD_NOSEC_CHN)) - { - HIDD_TRACE_ERROR0 ("Security Registration 1 failed"); - return (HID_ERR_NO_RESOURCES); - } - if (!BTM_SetSecurityLevel (TRUE, serv_name, BTM_SEC_SERVICE_HID_NOSEC_CTRL, - BTM_SEC_NONE, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, HIDD_NOSEC_CHN)) - { - HIDD_TRACE_ERROR0 ("Security Registration 2 failed"); - return (HID_ERR_NO_RESOURCES); - } - } - else - { - /* Register with Security Manager for the specific security level */ - if (!BTM_SetSecurityLevel (FALSE, serv_name, BTM_SEC_SERVICE_HID_SEC_CTRL, - sec_lvl, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, HIDD_SEC_CHN)) - { - HIDD_TRACE_ERROR0 ("Security Registration 3 failed"); - return (HID_ERR_NO_RESOURCES); - } - if (!BTM_SetSecurityLevel (TRUE, serv_name, BTM_SEC_SERVICE_HID_SEC_CTRL, - sec_lvl, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, HIDD_SEC_CHN)) - { - HIDD_TRACE_ERROR0 ("Security Registration 4 failed"); - return (HID_ERR_NO_RESOURCES); - } - } - - /* Register with Security Manager for the specific security level for interupt channel*/ - if (!BTM_SetSecurityLevel (TRUE, serv_name, BTM_SEC_SERVICE_HID_INTR, - BTM_SEC_NONE, HID_PSM_INTERRUPT, BTM_SEC_PROTO_HID, 0)) - { - HIDD_TRACE_ERROR0 ("Security Registration 5 failed"); - return (HID_ERR_NO_RESOURCES); - } - - if (!BTM_SetSecurityLevel (FALSE, serv_name, BTM_SEC_SERVICE_HID_INTR, - BTM_SEC_NONE, HID_PSM_INTERRUPT, BTM_SEC_PROTO_HID, 0)) - { - HIDD_TRACE_ERROR0 ("Security Registration 6 failed"); - return (HID_ERR_NO_RESOURCES); - } - - return HID_SUCCESS; -} - -#if HID_DEV_PM_INCLUDED == TRUE -/******************************************************************************* -** -** Function HID_DevSetPowerMgmtParams -** -** Description This function may be used to change power mgmt parameters. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS HID_DevSetPowerMgmtParams( UINT8 conn_substate, tHID_DEV_PM_PWR_MD pm_params ) -{ - if( conn_substate > HID_DEV_SUSP_CONN_ST ) - return (HID_ERR_INVALID_PARAM); - - memcpy( &hd_cb.pm_params[conn_substate], &pm_params, sizeof( tHID_DEV_PM_PWR_MD ) ) ; - - /* Set the power mode to new parameters if currently in that state */ - if( conn_substate == hd_cb.conn_substate ) - hidd_pm_set_power_mode ( &(hd_cb.pm_params[conn_substate]) ); - - return (HID_SUCCESS); -} - -#endif - diff --git a/stack/hid/hidd_conn.c b/stack/hid/hidd_conn.c deleted file mode 100644 index 111dcb7..0000000 --- a/stack/hid/hidd_conn.c +++ /dev/null @@ -1,970 +0,0 @@ -/*****************************************************************************/ -/* */ -/* Name: hidd_conn.c */ -/* */ -/* Description: this file contains the connection interface functions */ -/* for device role */ -/* Copyright (c) 2002-2011, Broadcom Corp., All Rights Reserved. */ -/* Broadcom Bluetooth Core. Proprietary and confidential. */ -/* */ -/*****************************************************************************/ - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - - -#include "gki.h" -#include "bt_types.h" - -#include "l2cdefs.h" -#include "l2c_api.h" - -#include "btu.h" -#include "btm_api.h" -#include "btm_int.h" - -#include "hiddefs.h" - -#include "hidd_api.h" -#include "hidd_int.h" - -/********************************************************************************/ -/* L O C A L F U N C T I O N P R O T O T Y P E S */ -/********************************************************************************/ -static void hidd_l2cif_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, - UINT8 l2cap_id); -static void hidd_l2cif_connect_cfm (UINT16 l2cap_cid, UINT16 result); -static void hidd_l2cif_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void hidd_l2cif_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void hidd_l2cif_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed); -static void hidd_l2cif_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg); -static void hidd_l2cif_disconnect_cfm (UINT16 l2cap_cid, UINT16 result); -static void hidd_l2cif_cong_ind (UINT16 l2cap_cid, BOOLEAN congested); - -static const tL2CAP_APPL_INFO reg_info = -{ - hidd_l2cif_connect_ind, - hidd_l2cif_connect_cfm, - NULL, - hidd_l2cif_config_ind, - hidd_l2cif_config_cfm, - hidd_l2cif_disconnect_ind, - hidd_l2cif_disconnect_cfm, - NULL, - hidd_l2cif_data_ind, - hidd_l2cif_cong_ind, - NULL /* tL2CA_TX_COMPLETE_CB */ -} ; - - -/******************************************************************************* -** -** Function hidd_conn_reg -** -** Description This function registers with L2CAP. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS hidd_conn_reg (void) -{ - /* Now, register with L2CAP for control and interrupt PSMs*/ - if (!L2CA_Register (HID_PSM_CONTROL, (tL2CAP_APPL_INFO *) ®_info)) - { - HIDD_TRACE_ERROR0 ("HID Control Registration failed"); - return( HID_ERR_L2CAP_FAILED ); - } - - if (!L2CA_Register (HID_PSM_INTERRUPT, (tL2CAP_APPL_INFO *) ®_info)) - { - L2CA_Deregister( HID_PSM_CONTROL ) ; - HIDD_TRACE_ERROR0 ("HID Interrupt Registration failed"); - return( HID_ERR_L2CAP_FAILED ); - } - - /* Set up / initialize the l2cap configuration data */ - hd_cb.l2cap_ctrl_cfg.flush_to_present = TRUE; - hd_cb.l2cap_ctrl_cfg.flush_to = HID_DEV_FLUSH_TO; - hd_cb.l2cap_int_cfg.flush_to_present = TRUE; - hd_cb.l2cap_int_cfg.flush_to = HID_DEV_FLUSH_TO; - - if( hd_cb.use_qos_flg == TRUE ) - { - memcpy( &(hd_cb.l2cap_ctrl_cfg.qos), &(hd_cb.qos_info.ctrl_ch), sizeof( FLOW_SPEC ) ) ; - hd_cb.l2cap_ctrl_cfg.qos_present = TRUE ; - - memcpy( &(hd_cb.l2cap_int_cfg.qos), &(hd_cb.qos_info.int_ch), sizeof( FLOW_SPEC ) ) ; - hd_cb.l2cap_int_cfg.qos_present = TRUE ; - } - else - { - hd_cb.l2cap_ctrl_cfg.qos_present = FALSE ; - hd_cb.l2cap_int_cfg.qos_present = FALSE ; - } - - hd_cb.conn.conn_state = HID_CONN_STATE_UNUSED ; - - return( HID_SUCCESS ); -} - -/******************************************************************************* -** -** Function hidd_conn_dereg -** -** Description This function deregisters with L2CAP. -** -** Returns void -** -*******************************************************************************/ -void hidd_conn_dereg( void ) -{ - L2CA_Deregister (HID_PSM_CONTROL); - L2CA_Deregister (HID_PSM_INTERRUPT); -} - -/******************************************************************************* -** -** Function hid_conn_disconnect -** -** Description This function disconnects a connection. -** -** Returns TRUE if disconnect started, FALSE if already disconnected -** -*******************************************************************************/ -void hidd_conn_disconnect () -{ - tHID_CONN *p_hcon = &hd_cb.conn; -#if HID_DEV_PM_INCLUDED == TRUE - tHID_DEV_PM_PWR_MD act_pm = { 0, 0, 0, 0, HCI_MODE_ACTIVE } ; -#endif - - HIDD_TRACE_EVENT0 ("HID - disconnect"); - -#if HID_DEV_PM_INCLUDED == TRUE - hidd_pm_stop(); /* This will stop the idle timer if running */ - - /* Need to go to to active mode to be able to send disconnect */ - hidd_pm_set_power_mode( &act_pm ); -#endif - - if ((p_hcon->ctrl_cid != 0) || (p_hcon->intr_cid != 0)) - { - p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING; - /* Disconnect both control and interrupt channels */ - if (p_hcon->intr_cid) - L2CA_DisconnectReq (p_hcon->intr_cid); - - if (p_hcon->ctrl_cid) - L2CA_DisconnectReq (p_hcon->ctrl_cid); - } - else - { - p_hcon->conn_state = HID_CONN_STATE_UNUSED; - } -} - -/******************************************************************************* -** -** Function hidd_conn_initiate -** -** Description This function is called by the management to create a connection. -** -** Returns void -** -*******************************************************************************/ -tHID_STATUS hidd_conn_initiate (void) -{ - tHID_CONN *p_hcon = &hd_cb.conn; - UINT8 service_id = BTM_SEC_SERVICE_HID_NOSEC_CTRL; - UINT32 mx_chan_id = HIDD_NOSEC_CHN; - -#if HID_DEV_NORMALLY_CONN == TRUE - if( p_hcon->conn_state != HID_CONN_STATE_UNUSED ) - return HID_ERR_CONN_IN_PROCESS ; -#endif - - HIDD_TRACE_EVENT0 ("HID - Originate started"); - - p_hcon->ctrl_cid = 0; - p_hcon->intr_cid = 0; - - /* We are the originator of this connection */ - p_hcon->conn_flags = HID_CONN_FLAGS_IS_ORIG; - if(hd_cb.sec_mask) - { - service_id = BTM_SEC_SERVICE_HID_SEC_CTRL; - mx_chan_id = HIDD_SEC_CHN; - } - BTM_SetOutService (hd_cb.host_addr, service_id, mx_chan_id); - - /* Check if L2CAP started the connection process */ - if ((p_hcon->ctrl_cid = L2CA_ConnectReq (HID_PSM_CONTROL, hd_cb.host_addr)) == 0) - { - HIDD_TRACE_WARNING0 ("HID - Originate failed"); - return (HID_ERR_L2CAP_FAILED); - } - else - { - /* Transition to the next appropriate state, waiting for connection confirm on control channel. */ - p_hcon->conn_state = HID_CONN_STATE_CONNECTING_CTRL; - - return (HID_SUCCESS); - } -} - -/******************************************************************************* -** -** Function hidd_sec_check_complete_term -** -** Description HID device security check complete callback function. -** -** Returns When security check succeed, send L2Cap connect response with -** OK code and send L2C configuration requret; otherwise send -** L2C connection response with security block code. -** -** -*******************************************************************************/ -void hidd_sec_check_complete_term (BD_ADDR bd_addr, void *p_ref_data, UINT8 res) -{ - tHID_CONN *p_hcon = &hd_cb.conn; - - if( res == BTM_SUCCESS && p_hcon->conn_state == HID_CONN_STATE_SECURITY ) - { - p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR; - - /* Send response to the L2CAP layer. */ - L2CA_ConnectRsp (bd_addr, p_hcon->ctrl_id, p_hcon->ctrl_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); - - /* Send a Configuration Request. */ - L2CA_ConfigReq (p_hcon->ctrl_cid, &hd_cb.l2cap_ctrl_cfg); - - } - /* security check fail */ - else if (res != BTM_SUCCESS) - { - L2CA_ConnectRsp (bd_addr, p_hcon->ctrl_id, p_hcon->ctrl_cid, L2CAP_CONN_SECURITY_BLOCK, L2CAP_CONN_OK); - p_hcon->conn_state = HID_CONN_STATE_UNUSED; - } -} - -/******************************************************************************* -** -** Function hidd_l2cif_connect_ind -** -** Description This function handles an inbound connection indication -** from L2CAP. This is the case where we are acting as a -** server. -** -** Returns void -** -*******************************************************************************/ -static void hidd_l2cif_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, UINT8 l2cap_id) -{ - tHID_CONN *p_hcon = &hd_cb.conn; - BOOLEAN bAccept = TRUE; - tL2CAP_CFG_INFO *p_l2cfg = NULL; - - HIDD_TRACE_EVENT2 ("HID - Rcvd L2CAP conn ind, PSM: 0x%04x CID 0x%x", psm, l2cap_cid); - - /* If host address provided during registration does not match, reject connection */ - if( hd_cb.virtual_cable && hd_cb.host_known && - memcmp( hd_cb.host_addr, bd_addr, BD_ADDR_LEN) ) - bAccept = FALSE; - else - { - /* Check we are in the correct state for this */ - if (psm == HID_PSM_INTERRUPT) - { - if (p_hcon->ctrl_cid == 0) - { - HIDD_TRACE_WARNING0 ("HID - Rcvd INTR L2CAP conn ind, but no CTL channel"); - bAccept = FALSE; - } - if (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd INTR L2CAP conn ind, wrong state: %d", p_hcon->conn_state); - bAccept = FALSE; - } - p_l2cfg = &hd_cb.l2cap_int_cfg; - } - else - { - if (p_hcon->conn_state != HID_CONN_STATE_UNUSED) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd CTL L2CAP conn ind, wrong state: %d", p_hcon->conn_state); - bAccept = FALSE; - } - p_l2cfg = &hd_cb.l2cap_ctrl_cfg; - } - } - - if (!bAccept) - { - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_RESOURCES, 0); - return; - } - - if (psm == HID_PSM_CONTROL) - { - p_hcon->conn_flags = 0; - p_hcon->ctrl_cid = l2cap_cid; - p_hcon->ctrl_id = l2cap_id; - - p_hcon->conn_state = HID_CONN_STATE_SECURITY; - - if(btm_sec_mx_access_request (bd_addr, HID_PSM_CONTROL, - FALSE, BTM_SEC_PROTO_HID, - (hd_cb.sec_mask == 0) ? HIDD_NOSEC_CHN : HIDD_SEC_CHN, - &hidd_sec_check_complete_term, NULL) == BTM_CMD_STARTED) - { - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_PENDING, L2CAP_CONN_OK); - } - return; - } - else - { - /* Transition to the next appropriate state, configuration */ - p_hcon->conn_state = HID_CONN_STATE_CONFIG; - p_hcon->intr_cid = l2cap_cid; - } - - /* Send response to the L2CAP layer. */ - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); - - /* Send a Configuration Request. */ - L2CA_ConfigReq (l2cap_cid, p_l2cfg); - - memcpy( hd_cb.host_addr, bd_addr, BD_ADDR_LEN ) ; - - HIDD_TRACE_EVENT2 ("HID - Rcvd L2CAP conn ind, sent config req, PSM: 0x%04x CID 0x%x", psm, l2cap_cid); -} - -/******************************************************************************* -** -** Function hidd_sec_check_complete_orig -** -** Description This function checks to see if security procedures are being -** carried out or not.. -** -** Returns void -** -*******************************************************************************/ -void hidd_sec_check_complete_orig (BD_ADDR bd_addr, void *p_ref_data, UINT8 res) -{ - UINT32 reason; - tHID_CONN *p_hcon = &hd_cb.conn; - - if( res == BTM_SUCCESS && p_hcon->conn_state == HID_CONN_STATE_SECURITY ) - { - HIDD_TRACE_EVENT0 ("HID Device - Originator security pass."); - - /* Send connect request for interrupt channel */ - if ((p_hcon->intr_cid = L2CA_ConnectReq (HID_PSM_INTERRUPT, hd_cb.host_addr)) == 0) - { - HIDD_TRACE_WARNING0 ("HID - INTR Originate failed"); - hidd_conn_disconnect();/* Disconnects the ctrl channel if setting of int chnl failed */ - reason = HID_L2CAP_REQ_FAIL ; - hd_cb.conn_tries = HID_DEV_MAX_CONN_RETRY+1; - hidd_mgmt_process_evt( HOST_CONN_FAIL, &reason ) ; - return; - } - else - { - /* Transition to the next appropriate state, waiting for connection confirm on control channel. */ - p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR; - } - } - - if( res != BTM_SUCCESS && p_hcon->conn_state == HID_CONN_STATE_SECURITY ) - { - hidd_conn_disconnect(); - } - -} - -/******************************************************************************* -** -** Function hid_l2cif_connect_cfm -** -** Description This function handles the connect confirm events -** from L2CAP. This is the case when we are acting as a -** client and have sent a connect request. -** -** Returns void -** -*******************************************************************************/ -static void hidd_l2cif_connect_cfm (UINT16 l2cap_cid, UINT16 result) -{ - UINT32 reason; - tHID_CONN *p_hcon = &hd_cb.conn; - tL2CAP_CFG_INFO *p_l2cfg; - - /* Verify we are in a state to accept this message */ - if (((p_hcon->ctrl_cid != l2cap_cid) && (p_hcon->intr_cid != l2cap_cid)) - || (!(p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG)) - || ((l2cap_cid == p_hcon->ctrl_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_CTRL)) - || ((l2cap_cid == p_hcon->intr_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR))) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd unexpected conn cnf, CID 0x%x ", l2cap_cid); - return; - } - - if (result != L2CAP_CONN_OK) - { - if (l2cap_cid == p_hcon->ctrl_cid) - p_hcon->ctrl_cid = 0; - else - p_hcon->intr_cid = 0; - - reason = HID_L2CAP_CONN_FAIL | ((UINT32) result) ; - hidd_conn_disconnect(); /* Disconnects the ctrl channel if setting of int chnl failed */ - - /* If connection failed due to bad air link, retry... */ - if (result != HCI_ERR_CONNECTION_TOUT && result != HCI_ERR_UNSPECIFIED - && result != HCI_ERR_PAGE_TIMEOUT) - hd_cb.conn_tries = HID_DEV_MAX_CONN_RETRY+1; - hidd_mgmt_process_evt( HOST_CONN_FAIL, &reason ) ; - return; - } - - if (l2cap_cid == p_hcon->ctrl_cid) - { - /* let HID Device handle security itself */ - p_hcon->conn_state = HID_CONN_STATE_SECURITY; - - btm_sec_mx_access_request (hd_cb.host_addr, HID_PSM_CONTROL, - TRUE, BTM_SEC_PROTO_HID, - (hd_cb.sec_mask == 0) ? HIDD_NOSEC_CHN : HIDD_SEC_CHN, - &hidd_sec_check_complete_orig, NULL); - - p_l2cfg = &hd_cb.l2cap_int_cfg; - - } - else - { - p_hcon->conn_state = HID_CONN_STATE_CONFIG; - p_l2cfg = &hd_cb.l2cap_ctrl_cfg; - } - - /* Send a Configuration Request. */ - L2CA_ConfigReq (l2cap_cid, p_l2cfg); - - HIDD_TRACE_EVENT1 ("HID - got CTRL conn cnf, sent cfg req, CID: 0x%x", l2cap_cid); - return; -} - -/******************************************************************************* -** -** Function hidd_l2c_connected -** -** Description This function is called when both control and interrupt channels -** have been created. -** -** Returns void -** -*******************************************************************************/ -void hidd_l2c_connected( tHID_CONN *p_hcon ) -{ - p_hcon->conn_state = HID_CONN_STATE_CONNECTED; - - /* Set HCI QoS */ - if( hd_cb.use_qos_flg ) - BTM_SetQoS( hd_cb.host_addr, &(hd_cb.qos_info.hci), NULL ) ; - - hidd_mgmt_process_evt( HOST_CONN_OPEN, hd_cb.host_addr) ; -#if HID_DEV_PM_INCLUDED == TRUE - hidd_pm_init(); - hidd_pm_start(); /* This kicks in the idle timer */ -#endif -} - -/******************************************************************************* -** -** Function hidd_l2cif_config_ind -** -** Description This function processes the L2CAP configuration indication -** event. -** -** Returns void -** -*******************************************************************************/ -static void hidd_l2cif_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - tHID_CONN *p_hcon = &hd_cb.conn; - - /* Find CCB based on CID */ - if ((p_hcon->ctrl_cid != l2cap_cid) && (p_hcon->intr_cid != l2cap_cid)) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); - return; - } - - HIDD_TRACE_EVENT1 ("HID - Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid); - - /* Remember the remote MTU size */ - if ((!p_cfg->mtu_present) || (p_cfg->mtu > HID_DEV_MTU_SIZE)) - p_hcon->rem_mtu_size = HID_DEV_MTU_SIZE; - else - p_hcon->rem_mtu_size = p_cfg->mtu; - - /* For now, always accept configuration from the other side */ - p_cfg->flush_to_present = FALSE; - p_cfg->mtu_present = FALSE; - p_cfg->result = L2CAP_CFG_OK; - - L2CA_ConfigRsp (l2cap_cid, p_cfg); - - if (l2cap_cid == p_hcon->ctrl_cid) - p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_CTRL_CFG_DONE; - else - p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_INTR_CFG_DONE; - - /* If all configuration is complete, change state and tell management we are up */ - if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED) - && (p_hcon->conn_state == HID_CONN_STATE_CONFIG)) - { - hidd_l2c_connected( p_hcon ); - } -} - - -/******************************************************************************* -** -** Function hid_l2cif_config_cfm -** -** Description This function processes the L2CAP configuration confirmation -** event. -** -** Returns void -** -*******************************************************************************/ -static void hidd_l2cif_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - UINT32 reason; - tHID_CONN *p_hcon = &hd_cb.conn; - tL2CAP_CFG_INFO * p_l2cfg = NULL; - - HIDD_TRACE_EVENT2 ("HID - Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, p_cfg->result); - - /* Find CCB based on CID */ - if ((p_hcon->ctrl_cid != l2cap_cid) && (p_hcon->intr_cid != l2cap_cid)) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); - return; - } - - /* config fail for unaccepted param, send reconfiguration */ - if (p_cfg->result == L2CAP_CFG_UNACCEPTABLE_PARAMS) - { - /* remember the host prefered config param in control block */ - p_l2cfg = (l2cap_cid == p_hcon->ctrl_cid)? &hd_cb.l2cap_ctrl_cfg : &hd_cb.l2cap_int_cfg ; - memcpy(p_l2cfg, p_cfg, sizeof(tL2CAP_CFG_INFO)); - - /* Send a second time configuration request. */ - L2CA_ConfigReq (l2cap_cid, p_l2cfg); - return; - } - /* If configuration failed for other reason, disconnect the channel(s) */ - else if (p_cfg->result != L2CAP_CFG_OK) - { - reason = HID_L2CAP_CFG_FAIL | ((UINT32) p_cfg->result) ; - hidd_conn_disconnect(); - hd_cb.conn_tries = HID_DEV_MAX_CONN_RETRY+1; - hidd_mgmt_process_evt( HOST_CONN_FAIL, &reason ) ; - return; - } - - if (l2cap_cid == p_hcon->ctrl_cid) - p_hcon->conn_flags |= HID_CONN_FLAGS_MY_CTRL_CFG_DONE; - else - p_hcon->conn_flags |= HID_CONN_FLAGS_MY_INTR_CFG_DONE; - - /* If all configuration is complete, change state and tell management we are up */ - if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED) - && (p_hcon->conn_state == HID_CONN_STATE_CONFIG)) - { - hidd_l2c_connected( p_hcon ); - } -} - - -/******************************************************************************* -** -** Function hidd_l2cif_disconnect_ind -** -** Description This function handles a disconnect event from L2CAP. If -** requested to, we ack the disconnect before dropping the CCB -** -** Returns void -** -*******************************************************************************/ -static void hidd_l2cif_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed) -{ - tHID_CONN *p_hcon = &hd_cb.conn; - UINT16 disc_res = HCI_PENDING ; - UINT8 evt = HOST_CONN_CLOSE; - - /* Find CCB based on CID */ - if ((p_hcon->ctrl_cid != l2cap_cid) && (p_hcon->intr_cid != l2cap_cid)) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid); - return; - } - - if (ack_needed) - L2CA_DisconnectRsp (l2cap_cid); - - HIDD_TRACE_EVENT1 ("HID - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); - - p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING; - - if (l2cap_cid == p_hcon->ctrl_cid) - p_hcon->ctrl_cid = 0; - else - p_hcon->intr_cid = 0; - - if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) - { - if (!ack_needed) - disc_res = btm_get_acl_disc_reason_code(); - HIDD_TRACE_EVENT1 ("disc_res: 0x%x", disc_res); - - if( disc_res == HCI_ERR_CONNECTION_TOUT || disc_res == HCI_ERR_UNSPECIFIED ) - evt = HOST_CONN_LOST; - - p_hcon->conn_state = HID_CONN_STATE_UNUSED; - hidd_mgmt_process_evt( evt, &disc_res ) ; -#if HID_DEV_PM_INCLUDED == TRUE - hidd_pm_stop(); -#endif - } -} - - -/******************************************************************************* -** -** Function hid_l2cif_disconnect_cfm -** -** Description This function handles a disconnect confirm event from L2CAP. -** -** Returns void -** -*******************************************************************************/ -static void hidd_l2cif_disconnect_cfm (UINT16 l2cap_cid, UINT16 result) -{ - UINT16 disc_res = HCI_SUCCESS; - tHID_CONN *p_hcon = &hd_cb.conn; - - /* Find CCB based on CID */ - if ((p_hcon->ctrl_cid != l2cap_cid) && (p_hcon->intr_cid != l2cap_cid)) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd L2CAP disc cfm, unknown CID: 0x%x", l2cap_cid); - return; - } - - HIDD_TRACE_EVENT1 ("HID - Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid); - - if (l2cap_cid == p_hcon->ctrl_cid) - p_hcon->ctrl_cid = 0; - else - p_hcon->intr_cid = 0; - - if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) - { - p_hcon->conn_state = HID_CONN_STATE_UNUSED; - hidd_mgmt_process_evt( HOST_CONN_CLOSE, &disc_res ) ; -#if HID_DEV_PM_INCLUDED == TRUE - hidd_pm_stop(); -#endif - } -} - - -/******************************************************************************* -** -** Function hidd_l2cif_cong_ind -** -** Description This function handles a congestion status event from L2CAP. -** -** Returns void -** -*******************************************************************************/ -static void hidd_l2cif_cong_ind (UINT16 l2cap_cid, BOOLEAN congested) -{ - tHID_CONN *p_hcon = &hd_cb.conn; - - /* Find CCB based on CID */ - if ((p_hcon->ctrl_cid != l2cap_cid) && (p_hcon->intr_cid != l2cap_cid)) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd L2CAP congestion status, unknown CID: 0x%x", l2cap_cid); - return; - } - - HIDD_TRACE_EVENT2 ("HID - Rcvd L2CAP congestion status, CID: 0x%x Cong: %d", l2cap_cid, congested); - - if (congested) - p_hcon->conn_flags |= HID_CONN_FLAGS_CONGESTED; - else - { - p_hcon->conn_flags &= ~HID_CONN_FLAGS_CONGESTED; - } - - hd_cb.callback( HID_DEV_EVT_L2CAP_CONGEST, (p_hcon->ctrl_cid == l2cap_cid), (tHID_DEV_CBACK_DATA*) &congested ) ; -} - - -/******************************************************************************* -** -** Function hid_l2cif_data_ind -** -** Description This function is called when data is received from L2CAP. -** if we are the originator of the connection, we are the SDP -** client, and the received message is queued up for the client. -** -** If we are the destination of the connection, we are the SDP -** server, so the message is passed to the server processing -** function. -** -** Returns void -** -*******************************************************************************/ -static void hidd_l2cif_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg) -{ - tHID_CONN *p_hcon = &hd_cb.conn; - UINT8 *p_data = (UINT8 *)(p_msg + 1) + p_msg->offset; - UINT8 ttype, param, rep_type, idle_rate; - tHID_DEV_GET_REP_DATA get_rep; - BOOLEAN suspend = FALSE; - - /* Find CCB based on CID */ - if ((p_hcon->ctrl_cid != l2cap_cid) && (p_hcon->intr_cid != l2cap_cid)) - { - HIDD_TRACE_WARNING1 ("HID - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid); - GKI_freebuf (p_msg); - return; - } - - ttype = HID_GET_TRANS_FROM_HDR(*p_data); - param = HID_GET_PARAM_FROM_HDR(*p_data); - rep_type = param & HID_PAR_REP_TYPE_MASK; - p_data++; - - switch (ttype) - { - case HID_TRANS_CONTROL: - switch (param) - { - case HID_PAR_CONTROL_NOP: - case HID_PAR_CONTROL_HARD_RESET: - case HID_PAR_CONTROL_SOFT_RESET: - case HID_PAR_CONTROL_EXIT_SUSPEND: - break; - - case HID_PAR_CONTROL_SUSPEND: - suspend = TRUE; -#if HID_DEV_PM_INCLUDED == TRUE - hidd_pm_suspend_evt() ; -#endif - break; - - case HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG: - hidd_mgmt_process_evt( HID_API_DISCONNECT, NULL ) ; - hd_cb.unplug_on = TRUE; - break; - - default: - GKI_freebuf (p_msg); - HID_DevHandShake( HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM ) ; - return; - } - hd_cb.callback( HID_DEV_EVT_CONTROL, param, NULL ) ; - break; - - case HID_TRANS_GET_REPORT: - if (param & HID_PAR_GET_REP_BUFSIZE_FOLLOWS) - { - STREAM_TO_UINT8 (get_rep.rep_id, p_data); - STREAM_TO_UINT16 (hd_cb.get_rep_buf_sz, p_data); - } - else - hd_cb.get_rep_buf_sz = 0; - - get_rep.rep_type = param & HID_PAR_REP_TYPE_MASK; - - hd_cb.callback( HID_DEV_EVT_GET_REPORT, param, - (tHID_DEV_CBACK_DATA*) &get_rep ) ; - break; - - case HID_TRANS_SET_REPORT: - hd_cb.callback( HID_DEV_EVT_SET_REPORT, rep_type, (tHID_DEV_CBACK_DATA*) &p_msg ) ; - break; - - case HID_TRANS_DATA: - hd_cb.callback( HID_DEV_EVT_DATA, rep_type, (tHID_DEV_CBACK_DATA*) &p_msg ) ; - break; - - case HID_TRANS_DATAC: - hd_cb.callback( HID_DEV_EVT_DATC, rep_type, (tHID_DEV_CBACK_DATA*) &p_msg ) ; - break; - - case HID_TRANS_GET_PROTOCOL: - /* Get current protocol */ - hd_cb.callback( HID_DEV_EVT_GET_PROTO, 0, NULL ) ; - break; - - case HID_TRANS_SET_PROTOCOL: - hd_cb.callback( HID_DEV_EVT_SET_PROTO, (UINT32) (param & HID_PAR_PROTOCOL_MASK), NULL ) ; - break; - - /* for HID 1.0 device only */ - case HID_TRANS_GET_IDLE: - hd_cb.callback( HID_DEV_EVT_GET_IDLE, 0, NULL ) ; - break; - - /* for HID 1.0 device only */ - case HID_TRANS_SET_IDLE: - STREAM_TO_UINT8 (idle_rate, p_data); - hd_cb.callback( HID_DEV_EVT_SET_IDLE, idle_rate, NULL ) ; - break; - - default: - GKI_freebuf (p_msg); - HID_DevHandShake( HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ ) ; - return; - } - -#if HID_DEV_PM_INCLUDED == TRUE - if( !suspend ) - hidd_pm_start(); -#endif - - if( (ttype != HID_TRANS_SET_REPORT) && (ttype != HID_TRANS_DATA) && (ttype != HID_TRANS_DATAC) ) - GKI_freebuf (p_msg); - /* Else application frees the buffer */ -} - -/******************************************************************************* -** -** Function hidd_conn_snd_data -** -** Description This function is called to send HID data. -** -** Returns void -** -*******************************************************************************/ -tHID_STATUS hidd_conn_snd_data (tHID_SND_DATA_PARAMS *p_data) -{ - tHID_CONN *p_hcon = &hd_cb.conn; - BT_HDR *p_buf; - UINT8 *p_out; - UINT16 bytes_copied; - BOOLEAN seg_req = FALSE; - UINT16 data_size; - UINT16 cid; - UINT8 pool_id; - UINT16 rem_mtu; - -#if HID_DEV_PM_INCLUDED == TRUE - hidd_pm_start(); -#endif - - /* Safety check */ - if (p_data) - { - pool_id = (p_data->ctrl_ch) ? HID_CONTROL_POOL_ID : HID_INTERRUPT_POOL_ID; - } - else - { - HIDD_TRACE_ERROR0 ("HID_ERR_INVALID_PARAM"); - return HID_ERR_INVALID_PARAM; - } - - if (p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) - { - return( HID_ERR_CONGESTED ); - } - - if( (p_data->trans_type == HID_TRANS_DATA) && p_data->ctrl_ch && hd_cb.get_rep_buf_sz ) - { - rem_mtu = hd_cb.get_rep_buf_sz; - hd_cb.get_rep_buf_sz = 0; - } - else - { - rem_mtu = p_hcon->rem_mtu_size; - } - - do - { - /* If buf is null form the HID message with ttype and params alone */ - if ( p_data->buf == NULL ) - { - if((p_buf = (BT_HDR *)GKI_getpoolbuf (pool_id)) == NULL) - return (HID_ERR_NO_RESOURCES); - - p_buf->offset = L2CAP_MIN_OFFSET; - seg_req = FALSE; - data_size = 0; - bytes_copied = 0; - } - /* Segmentation case */ - else if ( (p_data->buf->len > (rem_mtu - 1))) - { - if((p_buf = (BT_HDR *)GKI_getpoolbuf (pool_id)) == NULL) - return (HID_ERR_NO_RESOURCES); - - p_buf->offset = L2CAP_MIN_OFFSET; - seg_req = TRUE; - data_size = p_data->buf->len; - bytes_copied = rem_mtu - 1; - } - else /* NOTE: The initial buffer gets used last */ - { - p_buf = p_data->buf ; - p_buf->offset -= 1; - seg_req = FALSE; - data_size = p_data->buf->len; - bytes_copied = p_data->buf->len; - } - - p_out = (UINT8 *)(p_buf + 1) + p_buf->offset; - *p_out++ = HID_BUILD_HDR(p_data->trans_type, p_data->param); - - if (seg_req) - { - memcpy (p_out, (((UINT8 *)(p_data->buf+1)) + p_data->buf->offset), bytes_copied); - p_data->buf->offset += bytes_copied; - p_data->buf->len -= bytes_copied; - } - - p_buf->len = bytes_copied + 1; - data_size -= bytes_copied; - - cid = (p_data->ctrl_ch ? p_hcon->ctrl_cid : p_hcon->intr_cid); - /* Send the buffer through L2CAP */ - if ((p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) || (!L2CA_DataWrite (cid, p_buf))) - { - return (HID_ERR_CONGESTED); - } - - if (data_size) - p_data->trans_type = HID_TRANS_DATAC; - - } while (data_size != 0); - - if( bytes_copied == (rem_mtu - 1) ) - { - tHID_SND_DATA_PARAMS datc; - - datc.buf = NULL; - datc.ctrl_ch = p_data->ctrl_ch; - datc.param = p_data->param ; - datc.trans_type = HID_TRANS_DATAC ; - - hidd_conn_snd_data( &datc ) ; - } - - return (HID_SUCCESS); -} - diff --git a/stack/hid/hidd_int.h b/stack/hid/hidd_int.h deleted file mode 100644 index 58d7a83..0000000 --- a/stack/hid/hidd_int.h +++ /dev/null @@ -1,136 +0,0 @@ -/****************************************************************************/ -/* */ -/* Name: hidd_int.h */ -/* */ -/* Function: this file contains HID DEVICE internal definitions */ -/* */ -/* */ -/* Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved. */ -/* WIDCOMM Bluetooth Core. Proprietary and confidential. */ -/* */ -/****************************************************************************/ - -#ifndef HIDD_INT_H -#define HIDD_INT_H -#include "hidd_api.h" -#include "hid_conn.h" -#include "l2c_api.h" - -/* Define the possible events of the HID Device state machine. -*/ -enum -{ - HOST_CONN_OPEN, - HOST_CONN_CLOSE, - HOST_CONN_LOST, - HOST_CONN_FAIL, - HID_API_CONNECT, - HID_API_DISCONNECT, - HID_API_SEND_DATA -}; - -/* Define the possible states of the HID Device. -*/ -enum -{ - HID_DEV_ST_NO_CONN, - HID_DEV_ST_CONNECTING, - HID_DEV_ST_CONNECTED, - HID_DEV_ST_DISC_ING -}; - -/* To remember the power mode and setting */ -typedef struct curr_pm_setting -{ - UINT8 mode; - UINT16 interval; -} tHID_DEV_PM_CURR; - -/* Define the HID management control block. -*/ -typedef struct hid_control_block -{ - BD_ADDR host_addr; /* BD-Addr of the host device */ - BOOLEAN host_known; /* Mode */ - BOOLEAN virtual_cable;/* If the device is to behave as virtual cable */ - UINT8 dev_state; /* Device state if in HOST-KNOWN mode */ - UINT8 conn_tries; /* Remembers to the number of connection attempts while CONNECTING */ - UINT8 sec_mask; - UINT16 get_rep_buf_sz; - tHID_CONN conn; /* L2CAP channel info */ - -#if HID_DEV_PM_INCLUDED == TRUE - TIMER_LIST_ENT idle_tle; /* Timer used for inactivity timing */ - tHID_DEV_PM_PWR_MD pm_params[3]; /* Power management parameters for the three possible states */ - tHID_DEV_PM_CURR curr_pm; /* Current power mode */ - BOOLEAN pm_ctrl_busy;/* A power mode transition is going on */ - UINT8 conn_substate; - tHID_DEV_PM_PWR_MD final_pm;/* To remember the power mode while a power mode change is ongoing */ -#endif - - BOOLEAN use_qos_flg; /* Qos information provided by application or not */ - BOOLEAN unplug_on; /* Virtual unplug has been sent or received */ - tHID_DEV_QOS_INFO qos_info; /* Storage for QoS provided by application */ - - tHID_DEV_CALLBACK *callback; /* Application callbacks */ - tL2CAP_CFG_INFO l2cap_ctrl_cfg; /* Configuration data for control channel */ - tL2CAP_CFG_INFO l2cap_int_cfg; /* Configuration data for interrupt channel */ - BOOLEAN reg_flag; - UINT8 trace_level; -} tHIDDEV_CB; - -typedef struct snd_data_params -{ - BOOLEAN ctrl_ch; /* TRUE if control channel, FALSE if interrupt */ - UINT8 trans_type; /* Transaction type */ - UINT8 param; /* Second byte after trans type */ - BT_HDR *buf ; /* Data that comes after param */ -} tHID_SND_DATA_PARAMS; /* Is defined for hidd_conn_snd_data */ - -/* HID management function prototype -*/ -typedef tHID_STATUS (tHIDD_MGMT_EVT_HDLR) (UINT8, void *); - -/* HID Globals -*/ -#ifdef __cplusplus -extern "C" -{ -#endif - -/****************************************************************************** -** Main Control Block -*******************************************************************************/ -#if HID_DYNAMIC_MEMORY == FALSE -HID_API extern tHIDDEV_CB hd_cb; -#else -HID_API extern tHIDDEV_CB *hidd_cb_ptr; -#define hd_cb (*hidd_cb_ptr) -#endif - -extern tHID_STATUS hidd_conn_reg (void); -extern void hidd_conn_dereg( void ); -extern tHID_STATUS hidd_conn_initiate (void); -extern void hidd_conn_disconnect (void); -extern tHID_STATUS hidd_conn_snd_data (tHID_SND_DATA_PARAMS *p_data); - -extern tHID_STATUS hidd_mgmt_process_evt( UINT8 event, void *data ); -extern void hidd_proc_repage_timeout (TIMER_LIST_ENT *p_tle); - -#if HID_DEV_PM_INCLUDED == TRUE -extern tHID_STATUS hidd_pm_start( void ) ; -extern tHID_STATUS hidd_pm_stop( void ); -extern tHID_STATUS hidd_pm_activity_evt( void ); -extern tHID_STATUS hidd_pm_suspend_evt( void ); -extern tHID_STATUS hidd_pm_unsuspend_evt( void ); -extern void hidd_pm_init( void ); -extern BOOLEAN hidd_pm_set_power_mode( tHID_DEV_PM_PWR_MD *pm) ; - -extern void hidd_pm_proc_mode_change( UINT8 hci_status, UINT8 mode, UINT16 interval ); -#endif /* HID_DEV_PM_INCLUDED == TRUE */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/stack/hid/hidd_mgmt.c b/stack/hid/hidd_mgmt.c deleted file mode 100644 index 819dd11..0000000 --- a/stack/hid/hidd_mgmt.c +++ /dev/null @@ -1,287 +0,0 @@ -/*****************************************************************************/ -/* */ -/* Name: hidd_mgmt.c */ -/* */ -/* Description: this file contains the HID Device Management logic */ -/* */ -/* NOTE: In the interest of keeping code small, there is an */ -/* inherent assumption that L2CAP always runs a timer, */ -/* and so the HID management never needs a timer on L2CAP */ -/* actions like connect and disconnect. */ -/* */ -/* */ -/* Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved. */ -/* WIDCOMM Bluetooth Core. Proprietary and confidential. */ -/*****************************************************************************/ - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - -#include "gki.h" -#include "bt_types.h" -#include "hidd_api.h" -#include "hiddefs.h" -#include "hidd_int.h" -#include "btu.h" -#include "btm_api.h" - - -/********************************************************************************/ -/* L O C A L F U N C T I O N P R O T O T Y P E S */ -/********************************************************************************/ -static tHID_STATUS hidd_no_conn_proc_evt( UINT8 event, void *p_data ); -static tHID_STATUS hidd_connecting_proc_evt( UINT8 event, void *p_data ); -static tHID_STATUS hidd_connected_proc_evt( UINT8 event, void *p_data ); -static tHID_STATUS hidd_disc_ing_proc_evt( UINT8 event, void *p_data ); - - -/* State machine jump table. -*/ -tHIDD_MGMT_EVT_HDLR * const hidd_sm_proc_evt[] = -{ - hidd_no_conn_proc_evt, - hidd_connecting_proc_evt, - hidd_connected_proc_evt, - hidd_disc_ing_proc_evt -}; - -/* Main HID control block */ -#if HID_DYNAMIC_MEMORY == FALSE -tHIDDEV_CB hd_cb; -#endif - -/******************************************************************************* -** -** Function hidd_mgmt_process_evt -** -** Description This function is called by other modules to report an event -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS hidd_mgmt_process_evt( UINT8 event, void *p_data ) -{ - HIDD_TRACE_DEBUG3("hidd_mgmt_process_evt known: %d, s:%d, e:%d", - hd_cb.host_known, hd_cb.dev_state, event); - if( hd_cb.host_known ) - { - return ((hidd_sm_proc_evt[hd_cb.dev_state]) (event, p_data)); /* Event is passed to main State Machine */ - } - - if( event == HOST_CONN_OPEN ) - { - hd_cb.host_known = TRUE; - memcpy( hd_cb.host_addr, (BD_ADDR *) p_data, BD_ADDR_LEN ) ; - hd_cb.dev_state = HID_DEV_ST_CONNECTED ; - /* Call-Back the Application with this information */ - hd_cb.callback(HID_DEV_EVT_OPEN, 0, (tHID_DEV_CBACK_DATA *) hd_cb.host_addr ) ; - return( HID_SUCCESS ); - } - - return( HID_ERR_HOST_UNKNOWN ); -} - -/******************************************************************************* -** -** Function hidd_no_conn_proc_evt -** -** Description NO-CONN state event handler. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -static tHID_STATUS hidd_no_conn_proc_evt( UINT8 event, void *p_data ) -{ - tHID_STATUS st = HID_SUCCESS; - - switch( event ) - { - case HOST_CONN_OPEN: - hd_cb.dev_state = HID_DEV_ST_CONNECTED ; - hd_cb.callback(HID_DEV_EVT_OPEN, 0, (tHID_DEV_CBACK_DATA *) hd_cb.host_addr ) ; - break; - case HID_API_CONNECT: - hd_cb.conn_tries = 1; - hd_cb.dev_state = HID_DEV_ST_CONNECTING ; - if( (st = hidd_conn_initiate()) != HID_SUCCESS ) - { -#if HID_DEV_MAX_CONN_RETRY > 0 - btu_start_timer (&(hd_cb.conn.timer_entry), BTU_TTYPE_USER_FUNC, HID_DEV_REPAGE_WIN); - return HID_SUCCESS; -#else - hd_cb.dev_state = HID_DEV_ST_NO_CONN ; -#endif - } - break; - default: - st = HID_ERR_NO_CONNECTION; - } - - return st; -} - -/******************************************************************************* -** -** Function hidd_proc_repage_timeout -** -** Description function to handle timeout. -** -** Returns void -** -*******************************************************************************/ -void hidd_proc_repage_timeout (TIMER_LIST_ENT *p_tle) -{ - HIDD_TRACE_DEBUG0 ("hidd_proc_repage_timeout"); - hd_cb.conn_tries++; - if( hidd_conn_initiate() != HID_SUCCESS ) - { - if( hd_cb.conn_tries > HID_DEV_MAX_CONN_RETRY ) - { - hd_cb.dev_state = HID_DEV_ST_NO_CONN ; - hd_cb.callback(HID_DEV_EVT_CLOSE, 0, NULL ); - } - else - btu_start_timer (&(hd_cb.conn.timer_entry), BTU_TTYPE_USER_FUNC, HID_DEV_REPAGE_WIN); - } - else - hd_cb.callback( HID_DEV_EVT_RETRYING, hd_cb.conn_tries, NULL ); -} - -/******************************************************************************* -** -** Function hidd_connecting_proc_evt -** -** Description CONNECTING state event handler -** -** Returns tHID_STATUS -** -*******************************************************************************/ -static tHID_STATUS hidd_connecting_proc_evt( UINT8 event, void *p_data ) -{ - switch( event ) - { - case HOST_CONN_OPEN: - hd_cb.dev_state = HID_DEV_ST_CONNECTED ; - hd_cb.callback(HID_DEV_EVT_OPEN, 0, (tHID_DEV_CBACK_DATA *) hd_cb.host_addr ) ; - break; - - case HOST_CONN_FAIL: - if( hd_cb.conn_tries > HID_DEV_MAX_CONN_RETRY ) - { - UINT16 reason = *( (UINT16 *) p_data); - - hd_cb.dev_state = HID_DEV_ST_NO_CONN; - hd_cb.callback(HID_DEV_EVT_CLOSE, reason, NULL ); - } -#if HID_DEV_MAX_CONN_RETRY > 0 - else - { - btu_start_timer (&(hd_cb.conn.timer_entry), BTU_TTYPE_USER_FUNC, HID_DEV_REPAGE_WIN); - } -#endif - break; - - case HOST_CONN_CLOSE: - case HOST_CONN_LOST: - hd_cb.dev_state = HID_DEV_ST_NO_CONN; - hd_cb.callback(HID_DEV_EVT_CLOSE, *((UINT16 *) p_data), NULL ); - break; - - case HID_API_DISCONNECT: - hd_cb.dev_state = HID_DEV_ST_NO_CONN ; - btu_stop_timer (&(hd_cb.conn.timer_entry)); - hidd_conn_disconnect(); - break; - - default: - return( HID_ERR_CONN_IN_PROCESS ) ; - } - - return (HID_SUCCESS); -} - -/******************************************************************************* -** -** Function hidd_mgmt_conn_closed -** -** Description Called when l2cap channels have been released -** -** Returns void -** -*******************************************************************************/ -void hidd_mgmt_conn_closed( UINT16 reason ) -{ - if( hd_cb.unplug_on ) - { - hd_cb.host_known = FALSE; /* This allows the device to accept connection from other hosts */ - } - - hd_cb.dev_state = HID_DEV_ST_NO_CONN; - hd_cb.callback(HID_DEV_EVT_CLOSE, reason, NULL ); -} - -/******************************************************************************* -** -** Function hidd_connected_proc_evt -** -** Description CONNECTED state event handler -** -** Returns tHID_STATUS -** -*******************************************************************************/ -static tHID_STATUS hidd_connected_proc_evt( UINT8 event, void *p_data ) -{ - switch( event ) - { - case HOST_CONN_LOST: -#if HID_DEV_RECONN_INITIATE == TRUE - hd_cb.dev_state = HID_DEV_ST_CONNECTING ; - hd_cb.conn_tries = 0; - btu_start_timer (&(hd_cb.conn.timer_entry), BTU_TTYPE_USER_FUNC, HID_DEV_REPAGE_WIN); -#else - hidd_mgmt_conn_closed( *((UINT16 *) p_data) ) ; -#endif - break; - case HOST_CONN_CLOSE: - hidd_mgmt_conn_closed( *((UINT16 *) p_data) ) ; - break; - case HID_API_DISCONNECT: - hd_cb.dev_state = HID_DEV_ST_DISC_ING ; - hidd_conn_disconnect(); - break; - case HID_API_SEND_DATA: /*Send Input reports, handshake or virtual-unplug */ - return hidd_conn_snd_data( (tHID_SND_DATA_PARAMS *) p_data ); - default: - return( HID_ERR_ALREADY_CONN ) ; - } - - return( HID_SUCCESS ); -} - -/******************************************************************************* -** -** Function hidd_disc_ing_proc_evt -** -** Description DISCONNECTING state event handler -** -** Returns tHID_STATUS -** -*******************************************************************************/ -static tHID_STATUS hidd_disc_ing_proc_evt( UINT8 event, void *p_data ) -{ - switch( event ) - { - case HOST_CONN_LOST: - case HOST_CONN_FAIL: - case HOST_CONN_CLOSE: - hidd_mgmt_conn_closed( *((UINT16 *) p_data) ) ; - break; - default: - return( HID_ERR_DISCONNECTING ) ; - } - - return( HID_SUCCESS ); -} - - diff --git a/stack/hid/hidd_pm.c b/stack/hid/hidd_pm.c deleted file mode 100644 index ff3cc22..0000000 --- a/stack/hid/hidd_pm.c +++ /dev/null @@ -1,288 +0,0 @@ -/*****************************************************************************/ -/* */ -/* Name: hidd_pm.c */ -/* */ -/* Description: this file contains the HID Device Power Management logic */ -/* */ -/* */ -/* Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved. */ -/* WIDCOMM Bluetooth Core. Proprietary and confidential. */ -/*****************************************************************************/ - - -#include "gki.h" -#include "bt_types.h" -#include "hiddefs.h" -#include "btm_api.h" -#include "string.h" - -#include "hiddefs.h" - -#include "hidd_api.h" -#include "hidd_int.h" -#include "btu.h" - -#if HID_DEV_PM_INCLUDED == TRUE - -/******************************************************************************* -** -** Function hidd_pm_init -** -** Description This function is called when connection is established. It -** initializes the control block for power management. -** -** Returns void -** -*******************************************************************************/ - -static const tHID_DEV_PM_PWR_MD pwr_modes[] = -{ - HID_DEV_BUSY_MODE_PARAMS, - HID_DEV_IDLE_MODE_PARAMS, - HID_DEV_SUSP_MODE_PARAMS -}; - -void hidd_pm_init( void ) -{ - int i; - - hd_cb.curr_pm.mode = HCI_MODE_ACTIVE ; - hd_cb.final_pm.mode = 0xff; - - for( i=0; i<3; i++ ) - memcpy( &hd_cb.pm_params[i], &pwr_modes[i], sizeof( tHID_DEV_PM_PWR_MD ) ) ; - - hd_cb.pm_ctrl_busy = FALSE; -} - -/******************************************************************************* -** -** Function hidd_pm_set_now -** -** Description This drives the BTM for power management settings. -** -** Returns TRUE if Success, FALSE otherwise -** -*******************************************************************************/ -BOOLEAN hidd_pm_set_now( tHID_DEV_PM_PWR_MD *p_req_mode) -{ - tHID_DEV_PM_PWR_MD act_pm = { 0, 0, 0, 0, HCI_MODE_ACTIVE } ; - UINT8 st = BTM_SUCCESS; - - /* Do nothing if already in required state or already performing a pm function */ - if( (hd_cb.pm_ctrl_busy) || - ((p_req_mode->mode == hd_cb.curr_pm.mode) && ( (p_req_mode->mode == HCI_MODE_ACTIVE) || - ((hd_cb.curr_pm.interval >= p_req_mode->min) && (hd_cb.curr_pm.interval <= p_req_mode->max)) )) ) - { - hd_cb.final_pm.mode = 0xff; - return TRUE; - } - - switch( p_req_mode->mode ) - { - case HCI_MODE_ACTIVE: - if( hd_cb.curr_pm.mode == HCI_MODE_SNIFF ) - { -#if BTM_PWR_MGR_INCLUDED == TRUE - st = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, hd_cb.host_addr, (tBTM_PM_PWR_MD *) &act_pm); -#else - st = BTM_CancelSniffMode (hd_cb.host_addr); -#endif - hd_cb.pm_ctrl_busy = TRUE; - } - else if( hd_cb.curr_pm.mode == HCI_MODE_PARK ) - { -#if BTM_PWR_MGR_INCLUDED == TRUE - st = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, hd_cb.host_addr, (tBTM_PM_PWR_MD *) &act_pm); -#else - st = BTM_CancelParkMode (hd_cb.host_addr); -#endif - hd_cb.pm_ctrl_busy = TRUE; - } - break; - - case HCI_MODE_SNIFF: - if( hd_cb.curr_pm.mode != HCI_MODE_ACTIVE ) /* Transition through active state required */ - hidd_pm_set_now (&act_pm); - else - { -#if BTM_PWR_MGR_INCLUDED == TRUE - st = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, hd_cb.host_addr, (tBTM_PM_PWR_MD *) p_req_mode); -#else - st = BTM_SetSniffMode (hd_cb.host_addr, p_req_mode->min, p_req_mode->max, p_req_mode->attempt, p_req_mode->timeout); -#endif - hd_cb.pm_ctrl_busy = TRUE; - } - break; - - case HCI_MODE_PARK: - if( hd_cb.curr_pm.mode != HCI_MODE_ACTIVE ) /* Transition through active state required */ - hidd_pm_set_now (&act_pm); - else - { -#if BTM_PWR_MGR_INCLUDED == TRUE - st = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, hd_cb.host_addr, (tBTM_PM_PWR_MD *) p_req_mode); -#else - st = BTM_SetParkMode (hd_cb.host_addr, p_req_mode->min, p_req_mode->max); -#endif - hd_cb.pm_ctrl_busy = TRUE; - } - break; - - default: - break; - } - - if( st == BTM_SUCCESS || st == BTM_CMD_STARTED ) - return TRUE; - else - { - st += HCI_ERR_MAX_ERR ; - if( hd_cb.callback ) - hd_cb.callback( HID_DEV_EVT_PM_FAILED, hd_cb.conn_substate, (tHID_DEV_CBACK_DATA *) &st ) ; - return FALSE; - } -} - -/******************************************************************************* -** -** Function hidd_pm_set_power_mode -** -** Description This stores the power management setting and calls fn to set -** the power. -** -** Returns TRUE if Success, FALSE otherwise -** -*******************************************************************************/ -BOOLEAN hidd_pm_set_power_mode( tHID_DEV_PM_PWR_MD *p_req_mode) -{ - memcpy( &hd_cb.final_pm, p_req_mode, sizeof( tHID_DEV_PM_PWR_MD ) ) ; - return hidd_pm_set_now( p_req_mode ) ; -} - - -/******************************************************************************* -** -** Function hidd_pm_proc_mode_change -** -** Description This is the callback function, when power mode changes. -** -** Returns void -** -*******************************************************************************/ -void hidd_pm_proc_mode_change( UINT8 hci_status, UINT8 mode, UINT16 interval ) -{ - if (!hd_cb.reg_flag ) - return; - - hd_cb.pm_ctrl_busy = FALSE; - - if( hci_status != HCI_SUCCESS ) - { - if( hd_cb.callback ) - hd_cb.callback( HID_DEV_EVT_PM_FAILED, hd_cb.conn_substate, (tHID_DEV_CBACK_DATA *) &hci_status ) ; - } - else - { - hd_cb.curr_pm.mode = mode; - hd_cb.curr_pm.interval = interval; - - if( hd_cb.final_pm.mode != 0xff ) - { - /* If we haven't reached the final power mode, set it now */ - if( (hd_cb.final_pm.mode != hd_cb.curr_pm.mode) || - ( (hd_cb.final_pm.mode != HCI_MODE_ACTIVE) && - ((hd_cb.curr_pm.interval < hd_cb.final_pm.min) || (hd_cb.curr_pm.interval > hd_cb.final_pm.max)) - ) ) - { - hidd_pm_set_now( &(hd_cb.final_pm) ) ; - } - else - hd_cb.final_pm.mode = 0xff; - } - else - { - if( hd_cb.curr_pm.mode == HCI_MODE_ACTIVE ) - hidd_pm_start(); - } - - if( hd_cb.callback ) - hd_cb.callback( HID_DEV_EVT_MODE_CHG, mode, (tHID_DEV_CBACK_DATA *) &interval) ; - } -} - - -/******************************************************************************* -** -** Function hidd_pm_inact_timeout -** -** Description Called when idle timer expires. -** -** Returns void -** -*******************************************************************************/ -void hidd_pm_inact_timeout (TIMER_LIST_ENT *p_tle) -{ - hidd_pm_set_power_mode ( &(hd_cb.pm_params[HID_DEV_IDLE_CONN_ST])); - hd_cb.conn_substate = HID_DEV_IDLE_CONN_ST; -} - -/******************************************************************************* -** -** Function hidd_pm_start -** -** Description Starts the power management function in a given state. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS hidd_pm_start( void ) -{ - hidd_pm_set_power_mode ( &(hd_cb.pm_params[HID_DEV_BUSY_CONN_ST]) ); - - hd_cb.conn_substate = HID_DEV_BUSY_CONN_ST; - - hd_cb.idle_tle.param = (UINT32) hidd_pm_inact_timeout; - btu_start_timer (&hd_cb.idle_tle, BTU_TTYPE_USER_FUNC, HID_DEV_INACT_TIMEOUT); - - return( HID_SUCCESS ); -} - -/******************************************************************************* -** -** Function hidd_pm_stop -** -** Description Stops the idle timer. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS hidd_pm_stop( void ) -{ - tHID_DEV_PM_PWR_MD p_md = { 0, 0, 0, 0, HCI_MODE_ACTIVE }; - - hidd_pm_set_power_mode( &p_md ); - btu_stop_timer( &hd_cb.idle_tle ) ; - return( HID_SUCCESS ); -} - - -/******************************************************************************* -** -** Function hidd_pm_suspend_evt -** -** Description Called when host suspends the device. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -tHID_STATUS hidd_pm_suspend_evt( void ) -{ - if( hd_cb.conn_substate == HID_DEV_BUSY_CONN_ST ) - btu_stop_timer( &hd_cb.idle_tle ) ; - - hidd_pm_set_power_mode ( &(hd_cb.pm_params[HID_DEV_SUSP_CONN_ST]) ); - hd_cb.conn_substate = HID_DEV_SUSP_CONN_ST; - return( HID_SUCCESS ); -} -#endif /* HID_DEV_PM_INCLUDED == TRUE */ diff --git a/stack/include/a2d_m12.h b/stack/include/a2d_m12.h deleted file mode 100644 index 2cc5ef9..0000000 --- a/stack/include/a2d_m12.h +++ /dev/null @@ -1,145 +0,0 @@ -/***************************************************************************** -** -** Name: a2d_m12.h -** -** Description:Interface to MPEG-1, 2 Audio -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef A2D_M12_H -#define A2D_M12_H - -/***************************************************************************** -** Constants -*****************************************************************************/ -/* the length of the MPEG_1, 2 Audio Media Payload header. */ -#define A2D_M12_MPL_HDR_LEN 4 - -/* the LOSC of MPEG_1, 2 Audio media codec capabilitiy */ -#define A2D_M12_INFO_LEN 6 - -/* for Codec Specific Information Element */ -#define A2D_M12_IE_LAYER_MSK 0xE0 /* b7-b5 layer */ -#define A2D_M12_IE_LAYER1 0x80 /* b7: layer1 (mp1) */ -#define A2D_M12_IE_LAYER2 0x40 /* b6: layer2 (mp2) */ -#define A2D_M12_IE_LAYER3 0x20 /* b5: layer3 (mp3) */ - -#define A2D_M12_IE_CRC_MSK 0x10 /* b4: CRC */ - -#define A2D_M12_IE_CH_MD_MSK 0x0F /* b3-b0 channel mode */ -#define A2D_M12_IE_CH_MD_MONO 0x08 /* b3: mono */ -#define A2D_M12_IE_CH_MD_DUAL 0x04 /* b2: dual */ -#define A2D_M12_IE_CH_MD_STEREO 0x02 /* b1: stereo */ -#define A2D_M12_IE_CH_MD_JOINT 0x01 /* b0: joint stereo */ - -#define A2D_M12_IE_MPF_MSK 0x40 /* b6: MPF */ - -#define A2D_M12_IE_SAMP_FREQ_MSK 0x3F /* b5-b0 sampling frequency */ -#define A2D_M12_IE_SAMP_FREQ_16 0x20 /* b5:16 kHz */ -#define A2D_M12_IE_SAMP_FREQ_22 0x10 /* b4:22.05kHz */ -#define A2D_M12_IE_SAMP_FREQ_24 0x08 /* b3:24 kHz */ -#define A2D_M12_IE_SAMP_FREQ_32 0x04 /* b2:32 kHz */ -#define A2D_M12_IE_SAMP_FREQ_44 0x02 /* b1:44.1kHz */ -#define A2D_M12_IE_SAMP_FREQ_48 0x01 /* b0:48 kHz */ - -#define A2D_M12_IE_VBR_MSK 0x80 /* b7: VBR */ - -#define A2D_M12_IE_BITRATE_MSK 0x7FFF /* b6-b0 of octect 2, all of octect3*/ -#define A2D_M12_IE_BITRATE_0 0x0001 /* 0000 */ -#define A2D_M12_IE_BITRATE_1 0x0002 /* 0001 */ -#define A2D_M12_IE_BITRATE_2 0x0004 /* 0010 */ -#define A2D_M12_IE_BITRATE_3 0x0008 /* 0011 */ -#define A2D_M12_IE_BITRATE_4 0x0010 /* 0100 */ -#define A2D_M12_IE_BITRATE_5 0x0020 /* 0101 */ -#define A2D_M12_IE_BITRATE_6 0x0040 /* 0110 */ -#define A2D_M12_IE_BITRATE_7 0x0080 /* 0111 */ -#define A2D_M12_IE_BITRATE_8 0x0100 /* 1000 */ -#define A2D_M12_IE_BITRATE_9 0x0200 /* 1001 */ -#define A2D_M12_IE_BITRATE_10 0x0400 /* 1010 */ -#define A2D_M12_IE_BITRATE_11 0x0800 /* 1011 */ -#define A2D_M12_IE_BITRATE_12 0x1000 /* 1100 */ -#define A2D_M12_IE_BITRATE_13 0x2000 /* 1101 */ -#define A2D_M12_IE_BITRATE_14 0x4000 /* 1110 */ - -#define A2D_BLD_M12_PML_HDR(p_dst,frag_offset) {UINT16_TO_BE_STREAM(p_dst, 0); \ - UINT16_TO_BE_STREAM(p_dst, frag_offset); } - -#define A2D_PARS_M12_PML_HDR(p_src,frag_offset) {BE_STREAM_TO_UINT16(frag_offset, p_src); \ - BE_STREAM_TO_UINT16(frag_offset, p_src); } - - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -/* data type for the MPEG-1, 2 Audio Codec Information Element*/ -typedef struct -{ - UINT8 layer; /* layers */ - BOOLEAN crc; /* Support of CRC protection or not */ - UINT8 ch_mode; /* Channel mode */ - UINT8 mpf; /* 1, if MPF-2 is supported. 0, otherwise */ - UINT8 samp_freq; /* Sampling frequency */ - BOOLEAN vbr; /* Variable Bit Rate */ - UINT16 bitrate; /* Bit rate index */ -} tA2D_M12_CIE; - -/***************************************************************************** -** External Function Declarations -*****************************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif -/****************************************************************************** -** -** Function A2D_BldM12Info -** -** Description This function is called by an application to build -** the MPEG-1, 2 Audio Media Codec Capabilities byte sequence -** beginning from the LOSC octet. -** Input Parameters: -** media_type: Indicates Audio, or Multimedia. -** -** p_ie: The MPEG-1, 2 Audio Codec Information Element -** information. -** -** Output Parameters: -** p_result: the resulting codec info byte sequence. -** -** Returns A2D_SUCCESS if function execution succeeded. -** Error status code, otherwise. -******************************************************************************/ -A2D_API extern tA2D_STATUS A2D_BldM12Info(UINT8 media_type, tA2D_M12_CIE *p_ie, - UINT8 *p_result); - -/****************************************************************************** -** -** Function A2D_ParsM12Info -** -** Description This function is called by an application to parse -** the MPEG-1, 2 Audio Media Codec Capabilities byte sequence -** beginning from the LOSC octet. -** Input Parameters: -** p_info: the byte sequence to parse. -** -** for_caps: TRUE, if the byte sequence is for get capabilities -** response. -** -** Output Parameters: -** p_ie: The MPEG-1, 2 Audio Codec Information Element -** information. -** -** Returns A2D_SUCCESS if function execution succeeded. -** Error status code, otherwise. -******************************************************************************/ -A2D_API extern tA2D_STATUS A2D_ParsM12Info(tA2D_M12_CIE *p_ie, UINT8 *p_info, - BOOLEAN for_caps); - -#ifdef __cplusplus -} -#endif - -#endif /* A2D_M12_H */ diff --git a/stack/include/a2d_m24.h b/stack/include/a2d_m24.h deleted file mode 100644 index 0417a57..0000000 --- a/stack/include/a2d_m24.h +++ /dev/null @@ -1,122 +0,0 @@ -/***************************************************************************** -** -** Name: a2d_m24.h -** -** Description:Interface to MPEG-2, 4 Aac -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef A2D_M24_H -#define A2D_M24_H - -/***************************************************************************** -** Constants -*****************************************************************************/ - -/* the LOSC of MPEG_2, 4 AAC media codec capabilitiy */ -#define A2D_M24_INFO_LEN 8 - -/* for Codec Specific Information Element */ -#define A2D_M24_IE_OBJ_MSK 0xF0 /* b7-b4 object type. b3-b0 is RFA,not used */ -#define A2D_M24_IE_OBJ_2LC 0x80 /* b7: MPEG-2 AAC LC */ -#define A2D_M24_IE_OBJ_4LC 0x40 /* b6: MPEG-4 AAC LC */ -#define A2D_M24_IE_OBJ_4LTP 0x20 /* b5: MPEG-4 AAC LTP */ -#define A2D_M24_IE_OBJ_4S 0x10 /* b4: MPEG-4 AAC scalable */ - -#define A2D_M24_IE_SAMP_FREQ_MSK 0xFFF0 /* sampling frequency */ -#define A2D_M24_IE_SAMP_FREQ_8 0x8000 /* b7:8 kHz */ -#define A2D_M24_IE_SAMP_FREQ_11 0x4000 /* b6:11 kHz */ -#define A2D_M24_IE_SAMP_FREQ_12 0x2000 /* b5:12 kHz */ -#define A2D_M24_IE_SAMP_FREQ_16 0x1000 /* b4:16 kHz */ -#define A2D_M24_IE_SAMP_FREQ_22 0x0800 /* b3:22.05kHz */ -#define A2D_M24_IE_SAMP_FREQ_24 0x0400 /* b2:24 kHz */ -#define A2D_M24_IE_SAMP_FREQ_32 0x0200 /* b1:32 kHz */ -#define A2D_M24_IE_SAMP_FREQ_44 0x0100 /* b0:44.1kHz */ -#define A2D_M24_IE_SAMP_FREQ_48 0x0080 /* b7:48 kHz */ -#define A2D_M24_IE_SAMP_FREQ_64 0x0040 /* b6:64 kHz */ -#define A2D_M24_IE_SAMP_FREQ_88 0x0020 /* b5:88 kHz */ -#define A2D_M24_IE_SAMP_FREQ_96 0x0010 /* b4:96 kHz */ - -#define A2D_M24_IE_CHNL_MSK 0x0C /* b3-b2 channels */ -#define A2D_M24_IE_CHNL_1 0x08 /* b3: 1 channel */ -#define A2D_M24_IE_CHNL_2 0x04 /* b2: 2 channels */ - -#define A2D_M24_IE_VBR_MSK 0x80 /* b7: VBR */ - -#define A2D_M24_IE_BITRATE3_MSK 0x7F0000 /* octect3*/ -#define A2D_M24_IE_BITRATE45_MSK 0x00FFFF /* octect4, 5*/ -#define A2D_M24_IE_BITRATE_MSK 0x7FFFFF /* b7-b0 of octect 3, all of octect4, 5*/ - - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -/* data type for the MPEG-2, 4 AAC Codec Information Element*/ -typedef struct -{ - UINT8 obj_type; /* Object type */ - UINT16 samp_freq; /* Sampling frequency */ - UINT8 chnl; /* Channel mode */ - BOOLEAN vbr; /* Variable Bit Rate */ - UINT32 bitrate; /* Bit rate index */ -} tA2D_M24_CIE; - -/***************************************************************************** -** External Function Declarations -*****************************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif -/****************************************************************************** -** -** Function A2D_BldM24Info -** -** Description This function is called by an application to build -** the MPEG-2, 4 AAC Media Codec Capabilities byte sequence -** beginning from the LOSC octet. -** Input Parameters: -** media_type: Indicates Audio, or Multimedia. -** -** p_ie: MPEG-2, 4 AAC Codec Information Element information. -** -** Output Parameters: -** p_result: the resulting codec info byte sequence. -** -** Returns A2D_SUCCESS if function execution succeeded. -** Error status code, otherwise. -******************************************************************************/ -A2D_API extern tA2D_STATUS A2D_BldM24Info(UINT8 media_type, tA2D_M24_CIE *p_ie, - UINT8 *p_result); - -/****************************************************************************** -** -** Function A2D_ParsM24Info -** -** Description This function is called by an application to parse -** the MPEG-2, 4 AAC Media Codec Capabilities byte sequence -** beginning from the LOSC octet. -** Input Parameters: -** p_info: the byte sequence to parse. -** -** for_caps: TRUE, if the byte sequence is for get -** capabilities response. -** -** Output Parameters: -** p_ie: MPEG-2, 4 AAC Codec Information Element information. -** -** Returns A2D_SUCCESS if function execution succeeded. -** Error status code, otherwise. -******************************************************************************/ -A2D_API extern tA2D_STATUS A2D_ParsM24Info(tA2D_M24_CIE *p_ie, UINT8 *p_info, - BOOLEAN for_caps); - -#ifdef __cplusplus -} -#endif - -#endif /* A2D_M24_H */ - diff --git a/stack/include/avrc_defs.h b/stack/include/avrc_defs.h index 188f5a4..b902bff 100644 --- a/stack/include/avrc_defs.h +++ b/stack/include/avrc_defs.h @@ -825,13 +825,8 @@ typedef union /* macros */ #define AVRC_IS_VALID_CAP_ID(a) (((a == AVRC_CAP_COMPANY_ID) || (a == AVRC_CAP_EVENTS_SUPPORTED)) ? TRUE : FALSE) -#if (AVRC_ADV_CTRL_INCLUDED == TRUE) -#define AVRC_IS_VALID_EVENT_ID(a) (((a >= AVRC_EVT_PLAY_STATUS_CHANGE) && \ - (a <= AVRC_EVT_VOLUME_CHANGE)) ? TRUE : FALSE) -#else /* AVRCP 1.3 */ #define AVRC_IS_VALID_EVENT_ID(a) (((a >= AVRC_EVT_PLAY_STATUS_CHANGE) && \ (a <= AVRC_EVT_APP_SETTING_CHANGE)) ? TRUE : FALSE) -#endif #define AVRC_IS_VALID_ATTRIBUTE(a) (((((a > 0) && a <= AVRC_PLAYER_SETTING_SCAN)) || \ ((a >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) && \ diff --git a/stack/include/dun_api.h b/stack/include/dun_api.h deleted file mode 100644 index 2b3679f..0000000 --- a/stack/include/dun_api.h +++ /dev/null @@ -1,201 +0,0 @@ -/************************************************************************************ -** -** Name: dun_api.h -** -** Description: this file contains the DUN API declaration -** -** -** Copyright (c) 1999-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -*************************************************************************************/ -#ifndef DUN_API_H -#define DUN_API_H - -#include "bt_target.h" -#include "btm_api.h" -#include "sdp_api.h" -#include "port_api.h" - -/***************************************************************************** -** Constants -*****************************************************************************/ - -/* API function return values */ -#define DUN_SUCCESS 0 -#define DUN_FAIL 1 - -/* Values for the options parameter. It is an integer bit mask that -** contains information used in the DUN or Fax SDP record. These values -** can be or'ed together to indicate more than one option. Fax class options -** are not allowed for the DUN profile. -*/ -#define DUN_OPTIONS_AUDIO (1<<0) /* Audio feedback supported */ -#define DUN_OPTIONS_CLASS1 (1<<1) /* Fax class 1 supported */ -#define DUN_OPTIONS_CLASS20 (1<<2) /* Fax class 2.0 supported */ -#define DUN_OPTIONS_CLASS2 (1<<3) /* Fax class 2 supported */ - -/***************************************************************************** -** Type definitions -*****************************************************************************/ - -/* This callback function returns service discovery information to the -** application after the DUN_FindService() API function is called. The -** implementation of this callback function must copy the p_name parameter -** passed to it as it is not guaranteed to remain after the callback -** function exits. -*/ -typedef void (tDUN_FIND_CBACK)(BOOLEAN found, UINT8 scn, char* p_name, - UINT16 name_len, UINT16 options); - - -/***************************************************************************** -** External Function Declarations -*****************************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif - -/****************************************************************************** -** -** Function DUN_Listen -** -** Description This function opens a DUN or Fax connection in server mode. -** It configures the security settings for the connection, -** opens an RFCOMM connection in server mode, and sets the -** class of device as required by the profile. It returns -** the handle for the RFCOMM connection. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -DUN_API extern UINT8 DUN_Listen(UINT16 service_uuid, char *p_service_name, - UINT8 scn, UINT16 mtu, UINT8 security_mask, - UINT16 *p_handle, tPORT_CALLBACK *p_cback); - -/****************************************************************************** -** -** Function DUN_Connect -** -** Description This function opens a DUN or Fax client connection. -** It configures the security settings for the connection -** and opens an RFCOMM connection in server mode. -** It returns the handle for the RFCOMM connection. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -DUN_API extern UINT8 DUN_Connect(UINT16 service_uuid, BD_ADDR bd_addr, UINT8 scn, - UINT16 mtu, UINT8 security_mask, UINT16 *p_handle, - tPORT_CALLBACK *p_cback); - -/****************************************************************************** -** -** Function DUN_Close -** -** Description This function closes a DUN or Fax client connection -** previously opened with DUN_Connect(). -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -DUN_API extern UINT8 DUN_Close(UINT16 handle); - -/****************************************************************************** -** -** Function DUN_Shutdown -** -** Description This function closes a DUN or Fax server connection -** previously opened with DUN_Listen(). It is called if -** the application wishes to close the DUN or Fax server -** connection at any time. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -DUN_API extern UINT8 DUN_Shutdown(UINT16 handle); - -/****************************************************************************** -** -** Function DUN_AddRecord -** -** Description This function is called by a server application to add -** DUN or Fax information to an SDP record. Prior to -** calling this function the application must call -** SDP_CreateRecord() to create an SDP record. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -DUN_API extern UINT8 DUN_AddRecord(UINT16 service_uuid, char *p_service_name, - UINT8 scn, UINT16 options, UINT32 sdp_handle); - -/****************************************************************************** -** -** Function DUN_FindService -** -** Description This function is called by a client application to -** perform service discovery and retrieve DUN or Fax SDP -** record information from a server. Information is -** returned for the first service record found on the -** server that matches the service UUID. The callback -** function will be executed when service discovery is -** complete. There can only be one outstanding call to -** DUN_FindService() at a time; the application must wait -** for the callback before it makes another call to -** the function. -** -** Returns DUN_SUCCESS if function execution succeeded, -** DUN_FAIL if function execution failed. -** -******************************************************************************/ -DUN_API extern UINT8 DUN_FindService(UINT16 service_uuid, BD_ADDR bd_addr, - tSDP_DISCOVERY_DB *p_db, UINT32 db_len, - tDUN_FIND_CBACK *p_cback); - -/****************************************************************************** -** -** Function DUN_SetTraceLevel -** -** Description Sets the trace level for DUN. If 0xff is passed, the -** current trace level is returned. -** -** Input Parameters: -** new_level: The level to set the DUN tracing to: -** 0xff-returns the current setting. -** 0-turns off tracing. -** >= 1-Errors. -** >= 2-Warnings. -** >= 3-APIs. -** >= 4-Events. -** >= 5-Debug. -** -** Returns The new trace level or current trace level if -** the input parameter is 0xff. -** -******************************************************************************/ -DUN_API extern UINT8 DUN_SetTraceLevel (UINT8 new_level); - -/******************************************************************************* -** -** Function DUN_Init -** -** Description This function is called before accessing the DUN APIs in order -** to initialize the control block. -** -** Returns void -** -*******************************************************************************/ -DUN_API extern void DUN_Init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* DUN_API_H */ - diff --git a/stack/include/goep_util.h b/stack/include/goep_util.h deleted file mode 100644 index 600c6d0..0000000 --- a/stack/include/goep_util.h +++ /dev/null @@ -1,265 +0,0 @@ -/***************************************************************************** -** -** Name: goep_util.h -** -** File: Generic Object Exchange Profile utility API -** -** Copyright (c) 2000-2008, Broadcom Corp., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef GOEP_UTIL_H -#define GOEP_UTIL_H - -#include "bt_target.h" -#include "sdp_api.h" /* for tSDP_DISC_REC */ - - -/***************************************************************************** -** Constants -*****************************************************************************/ - -#define GOEP_ENHANCED_VERSION 0x0102 -#define GOEP_LEGACY_VERSION 0x0100 - - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -/*** Define goep error codes ***/ -enum -{ - GOEP_SUCCESS = 0, /* success */ - GOEP_ERROR, /* general failure */ - GOEP_RESOURCES, /* resources not available */ - GOEP_INVALID_PARAM /* bad parameter(s) */ -} ; -typedef UINT8 tGOEP_ERRORS; - - - - - -/***************************************************************************** -** External Function Declarations -*****************************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif - -/*** GOEP utility functions ***/ -/***************************************************************************** -** -** Function GOEP_SetSecurityLevel() -** -** Description Register security & encryption level for GOEP server. -** This is not to be used for the GOEP command server. -** -** Returns TRUE if OK, FALSE if a bad parameter -** -*****************************************************************************/ -GOEP_API extern BOOLEAN GOEP_SetSecurityLevel (BOOLEAN b_orig, - char *p_sz_name, - UINT32 service, - UINT8 sec, - UINT8 scn); - -/***************************************************************************** -** -** Function GOEP_SetTraceLevel -** -** Description This function changes the trace level (debugging levels) -** -** Returns void -** -*****************************************************************************/ -GOEP_API extern void GOEP_SetTraceLevel(UINT8 level); - -/******************************************************************************* -** -** Function GOEP_FreeBuf -** -** Description free memory for specified packet -** -** Returns void -** -*******************************************************************************/ -GOEP_API extern void GOEP_FreeBuf (void **p_buf); - -/******************************************************************************* -** -** Function GOEP_SendMsg -** -** Description send a message to BTU task -** -** Returns void -** -*******************************************************************************/ -GOEP_API extern void GOEP_SendMsg (void *p_msg); - -/******************************************************************************* -** -** Function GOEP_Init -** -** Description This function is called once at stack startup to allocate -** (if using dynamic memory) and initialize the -** control block, and initializes the -** debug tracing level. -** -** Returns void -** -*******************************************************************************/ -GOEP_API extern void GOEP_Init(void); - - - -/*** GOEP Service functions ***/ - - -/***************************************************************************** -** -** Function: GOEP_Register() -** -** Purpose: Register an OBEX profile with SDP -** -** Parameters: -** -** char *p_name service name; optional (may be NULL) -** UINT32 *phSDP handle to the created record; cannot be NULL -** UINT8 scn scn desired for the service; must be > 0 -** UINT16 version version of the service; optional (may be 0) -** -** Returns: (tGOEP_ERRORS) GOEP_SUCCESS if ok; GOEP_ERROR on error -** -** Notes: -** -** -** Preconditions: -** - phSDP must be set (to return the SDP record handle) -** - scn must be set -** -** Postconditions: -** - -** -*****************************************************************************/ -GOEP_API extern tGOEP_ERRORS GOEP_Register (char *p_name, - UINT32 *p_sdp_handle, - UINT8 scn, - UINT8 num_srv_class, - UINT16 *p_service_class, - UINT16 profile_id, - UINT16 version); -/***************************************************************************** -** -** Function: GOEP_Register2() -** -** Purpose: Register an OBEX 1.5 profile with SDP -** -** Parameters: -** -** char *p_name service name; optional (may be NULL) -** UINT32 *phSDP handle to the created record; cannot be NULL -** UINT16 psm psm desired for the service; must be an legal L2CAP dynamic PSM -** UINT16 version version of the service; optional (may be 0) -** -** Returns: (tGOEP_ERRORS) GOEP_SUCCESS if ok; GOEP_ERROR on error -** -** Notes: -** -** -** Preconditions: -** - phSDP must be set (to return the SDP record handle) -** - psm must be set -** -** Postconditions: -** - -** -*****************************************************************************/ -GOEP_API extern tGOEP_ERRORS GOEP_Register2 (char *p_name, - UINT32 *phSDP, - UINT16 psm, - UINT8 num_srv_class, - UINT16 *p_service_class, - UINT16 profile_id, - UINT16 version); - -/***************************************************************************** -** -** Function: GOEP_AddProtoLists() -** -** Purpose: Add the AdditionalProtocolDescriptorLists attribute -** to a SDP record -** -** Parameters: -** -** UINT32 sdp_hdl the SDP record handle -** UINT8 scn scn desired for the service; must be > 0 -** -** Returns: (tGOEP_ERRORS) GOEP_SUCCESS if ok; GOEP_ERROR on error -** -** Notes: -** -** -** Preconditions: -** - sdp_hdl must be set (to the SDP record handle from GOEP_Register()) -** - scn must be set -** -** Postconditions: -** - -** -*****************************************************************************/ -GOEP_API extern tGOEP_ERRORS GOEP_AddProtoLists ( UINT32 sdp_hdl, UINT8 scn); - - - -/*** Debug Tracing support ***/ -#if BT_USE_TRACES == TRUE - -GOEP_API extern char *GOEP_ErrorName (tGOEP_ERRORS error); -GOEP_API extern void GOEP_TraceSupportedDataTypes(UINT8 data_types, UINT8 *p_data_types); -#else -#ifndef BTE_SIM_APP -/* define these trace functions out */ -#define GOEP_CodeName(_x) "" -#define GOEP_ErrorName(_x) "" -#endif -#define GOEP_TraceSupportedDataTypes(x, y) -#endif - - -/***************************************************************************** -** -** Design notes: -** -** The responsibilities handle by this module include: -** -** a) Function signatures which assure the proper header fields are -** set for the GOEP connection establishment, GOEP put, and GOEP get. -** Required fields / headers are filled in through the API function -** parameters. Extensions beyond the required fields / headers -** must be set through the tOBEX_HEADERS *p_headers parameter. -** -** b) Debug error checking for required fields and prohibited fields -** for the GOEP connection establishment, GOEP put, and GOEP get. -** With debugging on, non-optional headers set in the p_headers -** parameter will generate a Widcomm assertion error. -** -** c) Does NOT include checks of any kind on the contents of the -** authentication or authentication response headers. In fact, -** the logic for encoding, decoding, validating, and calculating -** authentication data is outside the scope of GOEP and OBEX. -** Refer to IrOBEX v1.2 sections 2.2.13, 2.2.14, and 3.5. -** -** d) Does NOT include checks of any kind on the contents of the -** data (body headers) sent or received. -** -** -*****************************************************************************/ - -#ifdef __cplusplus -} -#endif - -#endif /* GOEP_UTIL_H */ diff --git a/stack/include/hidd_api.h b/stack/include/hidd_api.h deleted file mode 100644 index 180dc3e..0000000 --- a/stack/include/hidd_api.h +++ /dev/null @@ -1,241 +0,0 @@ -/**************************************************************************** -** -** Name: hidd_api.h -** -** Function: this file contains HID DEVICE side API definitions -** -** -** Copyright (c) 2002-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef HIDD_API_H -#define HIDD_API_H - -#include "hiddefs.h" - - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -/* Define the structures that the HID Device function should use to register -** callbacks with HID. -*/ - -typedef struct -{ - FLOW_SPEC ctrl_ch; - FLOW_SPEC int_ch; - FLOW_SPEC hci; -} tHID_DEV_QOS_INFO; - -typedef struct rep_data -{ - UINT8 rep_type; - UINT8 rep_id; -} tHID_DEV_GET_REP_DATA; - -/* HID-Device Callback Events -*/ -enum -{ - HID_DEV_EVT_OPEN, /*Connected to host with Interrupt and Control Data = 1 if Virtual Cable - Channels in OPEN state. pdata = Host BD-Addr.*/ - - HID_DEV_EVT_CLOSE, /*Connection with host is closed. Data=Reason Code. */ - HID_DEV_EVT_RETRYING, /*Lost connection is being re-connected. Data=Retrial number */ - HID_DEV_EVT_MODE_CHG, /*Device changed power mode. Data=new power mode */ - HID_DEV_EVT_PM_FAILED, - HID_DEV_EVT_CONTROL, /*Host sent HID_CONTROL Data=Control Operation */ - HID_DEV_EVT_GET_REPORT,/*Host sent GET_REPORT Data=Length pdata=structure - having details of get-report.*/ - HID_DEV_EVT_SET_REPORT,/*Host sent SET_REPORT Data=Length pdata=details.*/ - HID_DEV_EVT_GET_PROTO, /*Host sent GET_PROTOCOL Data=NA*/ - HID_DEV_EVT_SET_PROTO, /*Host sent SET_PROTOCOL Data=1 for Report, 0 for Boot*/ - HID_DEV_EVT_GET_IDLE, /*Host sent GET_IDLE Data=NA */ - HID_DEV_EVT_SET_IDLE, /*Host sent SET_IDLE Data=Idle Rate */ - HID_DEV_EVT_DATA, - HID_DEV_EVT_DATC, - - HID_DEV_EVT_L2CAP_CONGEST /* L2CAP channel congested */ -}; - -/* Define the possible states of the HID Device power manager. -*/ -enum -{ - HID_DEV_BUSY_CONN_ST, - HID_DEV_IDLE_CONN_ST, - HID_DEV_SUSP_CONN_ST -}; - -typedef union { - BD_ADDR host_bdaddr; - BT_HDR *buffer; - tHID_DEV_GET_REP_DATA get_rep; - UINT8 pm_err_code; - UINT16 pm_interval; -} tHID_DEV_CBACK_DATA; - -typedef void (tHID_DEV_CALLBACK) (UINT8 event, /* Event from HID-DEVICE. */ - UINT32 data, /* Integer data corresponding to the event. */ - tHID_DEV_CBACK_DATA *pdata ); /* Pointer data corresponding to the event.*/ - -typedef struct -{ - BD_ADDR host_addr;/* Host BD-ADDR */ - tHID_DEV_QOS_INFO *qos_info; /* This info is used only if HID_DEV_USE_GLB_QOS is set to FALSE.*/ - tHID_DEV_CALLBACK *app_cback; -} tHID_DEV_REG_INFO; - -typedef struct pwr_md -{ - UINT16 max; - UINT16 min; - UINT16 attempt; - UINT16 timeout; - UINT8 mode; -} tHID_DEV_PM_PWR_MD; - - -/***************************************************************************** -** External Function Declarations -*****************************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif - -/******************************************************************************* -** -** Function HID_DevSetSDPRecord -** -** Description This function should be called at startup to create the -** device SDP record -** -** Returns 0 if error else sdp handle for the record. -** -*******************************************************************************/ -HID_API extern UINT32 HID_DevSetSDPRecord (tHID_DEV_SDP_INFO *p_sdp_info); - -/******************************************************************************* -** -** Function HID_DevRegister -** -** Description This function must be called at startup so the device receive -** HID related events and call other HID API Calls. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevRegister(tHID_DEV_REG_INFO *pHID_DEVRegInfo ); - -/******************************************************************************* -** -** Function HID_DevDeregister -** -** Description This function may be used to remove HID service records and -** deregister from L2CAP. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevDeregister(void); - -/******************************************************************************* -** -** Function HID_DevConnect -** -** Description This function may be used to initiate a connection to the host.. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevConnect(void); - -/******************************************************************************* -** -** Function HID_DevDisconnect -** -** Description This function may be used to disconnect from the host. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevDisconnect(void); - -/******************************************************************************* -** -** Function HID_DevHandShake -** -** Description This function may be used to send HAND-SHAKE to host. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevHandShake(UINT8 res_code ); - -/******************************************************************************* -** -** Function HID_DevVirtualUnplug -** -** Description This function may be used to send VIRTUAL-UNPLUG to host. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevVirtualUnplug (void); - -/******************************************************************************* -** -** Function HID_DevSendData -** -** Description This function may be used to send input reports to host. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevSendData (BOOLEAN control_ch, UINT8 rep_type, - BT_HDR *data_buf ); - -/******************************************************************************* -** -** Function HID_DevSetPowerMgmtParams -** -** Description This function may be used to change power mgmt parameters. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevSetPowerMgmtParams(UINT8 conn_substate, - tHID_DEV_PM_PWR_MD pm_params ); - -/******************************************************************************* -** -** Function HID_DevInit -** -** Description This function initializes the control block and trace variable -** -** Returns void -** -*******************************************************************************/ -HID_API extern void HID_DevInit(void); - -/******************************************************************************* -** -** Function HID_DevSetSecurityLevel -** -** Description This function set security level for the Hid Device service. -** -** Returns tHID_STATUS -** -*******************************************************************************/ -HID_API extern tHID_STATUS HID_DevSetSecurityLevel( char serv_name[], UINT8 sec_lvl ); - - -#ifdef __cplusplus -} -#endif - -#endif /* HIDD_API_H */ diff --git a/stack/include/xml_bld_api.h b/stack/include/xml_bld_api.h deleted file mode 100644 index 2d788e0..0000000 --- a/stack/include/xml_bld_api.h +++ /dev/null @@ -1,113 +0,0 @@ -/***************************************************************************** -** -** Name: xml_bld_api.h -** -** File: XML Builder API -** -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef XML_BLD_API_H -#define XML_BLD_API_H - -#include "data_types.h" - - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -enum -{ - XML_BLD_SUCCESS, - XML_BLD_ERROR -}; -typedef UINT16 tXML_BLD_RESULT; - - -enum -{ - XML_ATTR_CONT = FALSE, /* not the end of attribute list. add quote(') */ - XML_ATTR_LAST = TRUE, /* the last one of the attribute list. add quote('), greater_than(>), and line_feed(\n) */ - XML_ATTR_ETAG = 2 /* the end of the element. add quote('), end_mark(/), greater_than(>), and line_feed(\n) */ -}; -typedef UINT8 tXML_ATTR_END; - - -/***************************************************************************** -** External Function Declarations -*****************************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif - - - -/***************************************************************************** -** -** Function: XML_BufAddTag -** -** Purpose: Write a start or end tag and optional prefix. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** GOEP_WriteStore. -** const UINT8* prefix tag prefix (namespace) -** const UINT8* tag tag name -** BOOLEAN start_tag TRUE = start tag, FALSE = end tag -** BOOLEAN has_attr TRUE if the tag contains attributes -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddTag (UINT8 **pp_buf, - const UINT8 *prefix, - const UINT8 *tag, - BOOLEAN start_tag, - BOOLEAN has_attr); - - -/***************************************************************************** -** -** Function: XML_BufAddAttribute -** -** Purpose: Write an attribute and optional prefix. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** const UINT8* prefix attribute prefix (namespace) -** const UINT8* attr_name attribute name -** const UINT8* attr_value attribute value -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddAttribute (UINT8 **pp_buf, - const UINT8 *prefix, - const UINT8 *attr_name, - const UINT8 *attr_value, - tXML_ATTR_END last_attr); - -/***************************************************************************** -** -** Function: XML_BufAddCharData -** -** Purpose: Write the element content. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** const UINT8* content element content -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddCharData (UINT8 **pp_buf, const UINT8 *charData); - -#ifdef __cplusplus -} -#endif - -#endif /* ifndef XML_BLD_API_H */ diff --git a/stack/include/xml_erp_api.h b/stack/include/xml_erp_api.h deleted file mode 100644 index fa2b33a..0000000 --- a/stack/include/xml_erp_api.h +++ /dev/null @@ -1,145 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_erp_api.h - ** $Id: - ** - ** Description: This module contains xml parser of MAP event report - ** - ** Copyright (c) 2004-2005, Broadcom Corporation, All Rights Reserved. - ** WIDCOMM Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#ifndef XML_ERP_API_H -#define XML_ERP_API_H - -#include "bt_target.h" -#include "gki.h" -#include "xml_pars_api.h" - - -#ifndef XML_EVT_RPT_CARRY_OVER_LEN -#define XML_EVT_RPT_CARRY_OVER_LEN 512 /* number of bytes we can store in case we did not yet find the > */ -#endif - -/**********************************************************************************/ - -typedef struct -{ - UINT16 type_len; - UINT16 handle_len; - UINT16 folder_len; - UINT16 old_folder_len; - UINT16 msg_type_len; - UINT8 *type; - UINT8 *handle; - UINT8 *folder; - UINT8 *old_folder; - UINT8 *msg_type; -} tXML_EVT_RPT_ENTRY; - -/**********************************************************************************/ - -enum -{ - XML_EVT_RPT_OK, /* parsing is ok, operation is ok */ - XML_EVT_RPT_PENDING, /* parsing is ok but not enough data */ - XML_EVT_RPT_END_LIST, /* found </MAP-event-report> */ - XML_EVT_RPT_OUT_FULL, /* output buffer full /MAP-event-report not reached! data is dumped */ - XML_EVT_RPT_ERROR, /* some parsing error occured */ - XML_EVT_RPT_NO_RES, /* ran out of resources (memory) */ - XML_EVT_RPT_DST_NO_RES /* ran out of destination data buffer */ -} ; -typedef UINT8 tXML_EVT_RPT_RES; - - -typedef struct -{ - tXML_EVT_RPT_ENTRY *p_entry; /* point to parser_cb->ilist.evt_rpt */ - tXML_PROP *p_prop; /* GKI_BUF3_SIZE */ - - tXML_PROP *offset_prop; /* current filling property */ - UINT16 prop_num; /* number of properties left to be filled in */ - - INT16 current_entry; - INT16 max_name_len; /* maximum length of name length of entry - XML parser limits to 196 bytes i think. */ - UINT16 max_entry; - BOOLEAN ended; - UINT16 prop_index; - UINT16 max_num_prop; - UINT8 obj; /* the XML object - (tFTC_XML_OBJ + 1)*/ -} tXML_EVT_RPT_STATE; - -typedef struct -{ - tXML_MUL_STATE xml; - tXML_EVT_RPT_STATE xml_user_data; -} tXML_EVT_RPT_PARSER; - -/* only this value is of significance, if not ok frame is dropped by parser */ -#define XML_EVT_RPT_ENTRY_OK 0 - -typedef UINT8 tXML_EVT_RPT_STATUS; - - -typedef struct -{ - UINT8 *data; - UINT16 len; - BOOLEAN final; /* If TRUE, entry is last of the series */ - tXML_EVT_RPT_STATUS status; /* Fields are valid when status is BTA_FTC_OK */ -} tXML_EVT_RPT_LIST; /* clone of tBTA_FTC_LIST */ - - -/************************************************************************************** -** Function XML_EvtRptInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of parser structure, allocate an additional space -** of size XML_EVT_RPT_CARRY_OVER_LEN right after p_xml_state -** to hold carry over data. -** p_entry : points start of output directory entry. caller needs do free this memory -** max_entry : max is 16 bit integer value which is the maximum number of folder entries. - -** -** Returns void -**************************************************************************************/ -MCE_API void XML_EvtRptInit( tXML_EVT_RPT_PARSER *p_xml_state, - tXML_EVT_RPT_ENTRY *p_entry, - const UINT16 max_entry ); - - -/************************************************************************************** -** Function XML_EvtRptParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_FolderInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. -** When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: length of the dst_data buffer, its carry out value is the number -** of bytes of available buffer remains. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_EVT_RPT_RES (see xml_flp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_EVT_RPT_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_EVT_RPT_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -MCE_API extern tXML_EVT_RPT_RES XML_EvtRptParse( tXML_EVT_RPT_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ); - - -#endif diff --git a/stack/include/xml_flp_api.h b/stack/include/xml_flp_api.h deleted file mode 100644 index fddb839..0000000 --- a/stack/include/xml_flp_api.h +++ /dev/null @@ -1,162 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_flp.h - ** $Id: xml_flp.h,v 1.2 2004/11/15 14:07:47 rlenden Exp - ** - ** Description: This module contains xml parser of obex folder listing - ** - ** Copyright (c) 2004-2005, Broadcom Corporation, All Rights Reserved. - ** WIDCOMM Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#ifndef XML_FLP_H -#define XML_FLP_H - -#include "bt_target.h" -#include "gki.h" -#include "xml_pars_api.h" - -/**********************************************************************************/ -#ifndef XML_OBX_FOLDER -#define XML_OBX_FOLDER 0 -#endif -#ifndef XML_OBX_FILE -#define XML_OBX_FILE 1 -#endif - -#define XML_PERM_READ_B 0x01 -#define XML_PERM_WRITE_B 0x02 -#define XML_PERM_DELETE_B 0x04 - -typedef UINT8 XML_PERM_MASK ; - -#ifndef XML_OBX_FILE_MAX -#define XML_OBX_FILE_MAX 100 -#endif - -#ifndef XML_FOLDER_CARRY_OVER_LEN -#define XML_FOLDER_CARRY_OVER_LEN 512 /* number of bytes we can store in case we did not yet find the > */ -#endif - - -#ifndef XML_PARENT_FOLDER -#define XML_PARENT_FOLDER ".." /* <parent-folder/> is represented as .. */ -#endif - - -typedef struct -{ - - UINT8 *data; - UINT32 size; /* size of file or folder in bytes */ - UINT16 len; - UINT8 type; - XML_PERM_MASK user_perm; -} tXML_FOLDER_ENTRY; - -/**********************************************************************************/ - -typedef enum -{ - XML_FOLDER_OK, /* parsing is ok, operation is ok */ - XML_FOLDER_PENDING, /* parsing is ok but not enough data */ - XML_FOLDER_END_LIST, /* found </folder-listing> */ - XML_FOLDER_OUT_FULL, /* output buffer full /folder-listing not reached! data is dumped */ - XML_FOLDER_ERROR, /* some parsing error occured */ - XML_FOLDER_NO_RES, /* ran out of resources (memory) */ - XML_FOLDER_DST_NO_RES /* ran out of destination data buffer */ -} txml_folder_res; -typedef UINT8 tXML_FOLDER_RES; - - -typedef struct -{ - tXML_FOLDER_ENTRY *p_entry; - tXML_PROP *p_prop; - - tXML_PROP *offset_prop; /* current filling property */ - UINT16 prop_num; /* number of properties left to be filled in */ - - INT16 current_entry; - INT16 max_name_len; /* maximum length of name length of entry - XML parser limits to 196 bytes i think. */ - UINT16 max_entry; - BOOLEAN ended; - UINT16 prop_index; - UINT16 max_num_prop; - UINT8 obj; /* the XML object - (tFTC_XML_OBJ + 1)*/ -} tXML_FOLDER_STATE; - -typedef struct -{ - tXML_MUL_STATE xml; - tXML_FOLDER_STATE xml_user_data; -} tXML_FOLDER_PARSER; - -/* only this value is of significance, if not ok frame is dropped by parser */ -#define XML_FOLDER_ENTRY_OK 0 - -typedef UINT8 tXML_FOLDER_STATUS; - - -typedef struct -{ - UINT8 *data; - UINT16 len; - BOOLEAN final; /* If TRUE, entry is last of the series */ - tXML_FOLDER_STATUS status; /* Fields are valid when status is BTA_FTC_OK */ -} tXML_FOLDER_LIST; /* clone of tBTA_FTC_LIST */ - - -/************************************************************************************** -** Function XML_FolderInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of parser structure, allocate an additional space -** of size XML_FOLDER_CARRY_OVER_LEN right after p_xml_state -** to hold carry over data. -** p_entry : points start of output directory entry. caller needs do free this memory -** max_entry : max is 16 bit integer value which is the maximum number of folder entries. - -** -** Returns void -**************************************************************************************/ -FTP_API void XML_FolderInit( tXML_FOLDER_PARSER *p_xml_state, - tXML_FOLDER_ENTRY *p_entry, - const UINT16 max_entry ); - - -/************************************************************************************** -** Function XML_FolderParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_FolderInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. -** When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: length of the dst_data buffer, its carry out value is the number -** of bytes of available buffer remains. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_FOLDER_RES (see xml_flp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_FOLDER_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_FOLDER_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -FTP_API extern tXML_FOLDER_RES XML_FolderParse( tXML_FOLDER_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ); - - -#endif diff --git a/stack/include/xml_mlp_api.h b/stack/include/xml_mlp_api.h deleted file mode 100644 index eabbfbd..0000000 --- a/stack/include/xml_mlp_api.h +++ /dev/null @@ -1,169 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_mlp_api.h - ** $Id: - ** - ** Description: This module contains xml parser of MAP message list object - ** - ** Copyright (c) 2004-2005, Broadcom Corporation, All Rights Reserved. - ** WIDCOMM Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#ifndef XML_MLP_API_H -#define XML_MLP_API_H - -#include "bt_target.h" -#include "gki.h" -#include "xml_pars_api.h" - - -#ifndef XML_ML_CARRY_OVER_LEN -#define XML_ML_CARRY_OVER_LEN 512 /* number of bytes we can store in case we did not yet find the > */ -#endif - -/**********************************************************************************/ - -typedef struct -{ - UINT16 msg_handle_len; - UINT16 subject_len; - UINT16 datetime_len; - UINT16 sender_name_len; - UINT16 sender_addressing_len; - UINT16 replyto_addressing_len; - UINT16 recipient_name_len; - UINT16 recipient_addressing_len; - UINT16 type_len; - UINT16 org_msg_size_len; - UINT16 text_len; - UINT16 reception_status_len; - UINT16 attachment_size_len; - UINT16 priority_status_len; - UINT16 read_len; - UINT16 sent_len; - UINT16 is_protected_len; - UINT8 *msg_handle; - UINT8 *subject; - UINT8 *datetime; - UINT8 *sender_name; - UINT8 *sender_addressing; - UINT8 *replyto_addressing; - UINT8 *recipient_name; - UINT8 *recipient_addressing; - UINT8 *type; - UINT8 *org_msg_size; - UINT8 *text; - UINT8 *reception_status; - UINT8 *attachment_size; - UINT8 *priority_status; - UINT8 *read; - UINT8 *sent; - UINT8 *is_protected; -} tXML_ML_ENTRY; - -/**********************************************************************************/ - -enum -{ - XML_ML_OK, /* parsing is ok, operation is ok */ - XML_ML_PENDING, /* parsing is ok but not enough data */ - XML_ML_END_LIST, /* found </MAP-msg-listing> */ - XML_ML_OUT_FULL, /* output buffer full /MAP-msg-listing not reached! data is dumped */ - XML_ML_ERROR, /* some parsing error occured */ - XML_ML_NO_RES, /* ran out of resources (memory) */ - XML_ML_DST_NO_RES /* ran out of destination data buffer */ -}; -typedef UINT8 tXML_ML_RES; - - -typedef struct -{ - tXML_ML_ENTRY *p_entry; /* point to parser_cb->mlist.evt_rpt */ - tXML_PROP *p_prop; /* GKI_BUF3_SIZE */ - - tXML_PROP *offset_prop; /* current filling property */ - UINT16 prop_num; /* number of properties left to be filled in */ - - INT16 current_entry; - INT16 max_name_len; /* maximum length of name length of entry - XML parser limits to 196 bytes i think. */ - UINT16 max_entry; - BOOLEAN ended; - UINT16 prop_index; - UINT16 max_num_prop; - UINT8 obj; /* the XML object - (tFTC_XML_OBJ + 1)*/ -} tXML_ML_STATE; - -typedef struct -{ - tXML_MUL_STATE xml; - tXML_ML_STATE xml_user_data; -} tXML_ML_PARSER; - -/* only this value is of significance, if not ok frame is dropped by parser */ -#define XML_ML_ENTRY_OK 0 - -typedef UINT8 tXML_ML_STATUS; - - -typedef struct -{ - UINT8 *data; - UINT16 len; - BOOLEAN final; /* If TRUE, entry is last of the series */ - tXML_ML_STATUS status; /* Fields are valid when status is BTA_FTC_OK */ -} tXML_ML_LIST; /* clone of tBTA_FTC_LIST */ - - -/************************************************************************************** -** Function XML_MlInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of parser structure, allocate an additional space -** of size XML_ML_CARRY_OVER_LEN right after p_xml_state -** to hold carry over data. -** p_entry : points start of output directory entry. caller needs do free this memory -** max_entry : max is 16 bit integer value which is the maximum number of folder entries. - -** -** Returns void -**************************************************************************************/ -MCE_API void XML_MlInit( tXML_ML_PARSER *p_xml_state, - tXML_ML_ENTRY *p_entry, - const UINT16 max_entry ); - - -/************************************************************************************** -** Function XML_MLParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_FolderInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. -** When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: length of the dst_data buffer, its carry out value is the number -** of bytes of available buffer remains. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_ML_RES (see xml_flp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_ML_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_ML_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -MCE_API extern tXML_ML_RES XML_MlParse( tXML_ML_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ); - - -#endif diff --git a/stack/include/xml_pars_api.h b/stack/include/xml_pars_api.h deleted file mode 100644 index d29645a..0000000 --- a/stack/include/xml_pars_api.h +++ /dev/null @@ -1,358 +0,0 @@ -/***************************************************************************** -** -** Name: xml_pars_api.h -** -** File: XML Parser -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef XML_PARS_API_H -#define XML_PARS_API_H - -#include "data_types.h" - -#define XML_STACK_SIZE 7 - -#ifndef XML_UI_ENTRY_MAX_NAME_LEN -#define XML_UI_ENTRY_MAX_NAME_LEN 256 -#endif - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -/* Definition of XML events */ -enum -{ - XML_XMLDECL, - XML_TAG, /* 1 For STag (Start Tag) and EmptyElemTag */ - XML_TAG_END, /* 2 When STag or EmptyElemTag ends */ - XML_ATTRIBUTE, /* 3 */ - XML_CHARDATA, /* 4 */ - XML_ETAG, /* 5 For End Tag */ - XML_PARTIAL, /* 6 notify XML user that the parse does not end properly */ - XML_COPY, /* 7 notify XML user to copy till end of a token */ - XML_QUERY, /* 8 query if the XML object has ended */ - XML_TOP /* 9 */ -}; -typedef UINT16 tXML_EVENT; -#define XML_LAST_XE XML_ETAG - -enum -{ - XML_SUCCESS, - XML_WARNING, - XML_OBJ_ST_EMPTY, - XML_NO_MEM, /* no p_last_bfr, and the tXML_MUL_STATE is not in init */ - XML_NO_PROP, /* run out of tXML_PROP */ - XML_ERR, /* generic error */ - XML_NO_END /* to be continued */ -}; -typedef UINT16 tXML_RESULT; - -/* Definitions of different event data */ -typedef struct -{ - UINT8 *p_version; - UINT8 *p_enc_name; - BOOLEAN *p_standalone; /* NULL if no standalone decl was found */ -} tXML_DECL; - - - -/* for parser that expand multi-sessions */ -/* tag stack */ -typedef struct -{ - UINT8 stack[XML_STACK_SIZE]; - UINT8 top; - tXML_EVENT event; /* last XML event */ -} tXML_STACK; - -typedef struct -{ - UINT8 *p; - UINT16 len; -} tXML_STR; - -typedef struct -{ - tXML_STACK stack; - tXML_STR prefix; - tXML_STR name; - UINT8 *p_last_stm; -} tXML_MTAG; - -typedef struct -{ - tXML_STACK stack; - BOOLEAN end; /* true if end of EmptyElemTag */ - /* false if end of STag */ -} tXML_MTAG_END; - - - -typedef struct -{ - tXML_STACK stack; - tXML_STR prefix; - tXML_STR name; - tXML_STR value; -} tXML_MATTR; - - -/* There may be several XML_CHARDATA events dispatched for one CHARDATA -** string in the XML document. In each XML_CHARDATA only a segment of the -** total string is provided. For the last segement the field last is true. -*/ -typedef struct -{ - tXML_STACK stack; - tXML_STR value; - BOOLEAN last; -} tXML_MCH_DATA; - - -typedef struct -{ - tXML_STACK stack; - tXML_STR prefix; - tXML_STR name; -} tXML_METAG; - -typedef struct -{ - tXML_STACK stack; - UINT8 *p_begin; - tXML_STR last; -} tXML_MCOPY; - -typedef struct -{ - tXML_STACK stack; - tXML_RESULT parse; - UINT8 *p_keep; -} tXML_MPART; - -typedef union -{ - tXML_STACK stack; - tXML_DECL decl; - tXML_MTAG tag; - tXML_MTAG_END empty_elem; - tXML_MATTR attr; - tXML_MCH_DATA ch_data; - tXML_METAG etag; - tXML_MCOPY copy; - tXML_MPART part; -} tXML_MEVT_DATA; - -typedef struct -{ - UINT8 *p_data; /* Pointer to property data. */ - UINT16 len; /* Length of data. */ - UINT8 prefix; /* Property prefix. */ - UINT8 name; /* Property name. */ - UINT8 level; /* 0 as top level */ -} tXML_PROP; - -/* Definitions of different error actions. -** At present there is only one. -*/ -enum -{ - XML_NEXT_TAG /* tries to find beginning of next tag */ -}; -typedef UINT16 tXML_ERR_ACTION; - - - -enum -{ - XML_STS_INIT, - XML_STS_1STM, /* got the first < */ - XML_STS_1TAG, /* got the first tag element */ - XML_STS_DONE -}; -typedef UINT8 tXML_STATUS; - -typedef struct -{ - UINT8 *p_hdr; /* the beginning of GKI buffer */ - UINT8 *p_begin;/* the beginning of XML data */ - UINT8 *p_end; /* the end of XML data */ -} tXML_OS; - - -/***************************************************************************** -** -** Callback tXML_CBACK -** -** Description -** Called repeatedly from the XML parser for each XML construct parsed. -** The parsed XML construct is reported as an XML event in the event -** in-parameter. The parser provides event data specific for each event -** in the callback through the p_event_data param which should be casted -** to the proper type by the user implemented tXML_CBACK function. -** The p_event_data should be casted to a pointer of a type with the same -** name as the event but prefixed with t. For example when the event is -** XML_TAG, p_event_data should be casted to tXML_TAG*. Alternatively, -** p_event_data can be casted to a tEVENT_DATA* (pointer to union) type -** for all events. The memory behind the p_event_data is provided by the -** parser and is only valid during the callback, i.e. the memory is not -** valid after the callback. No pointer inside the event structures may -** be NULL unless explicitly stated so above for some specific event. -** The p_usr_data parameter is the same p_usr_data pointer the -** API user passed in the XML_Parse. It is only declared as a mean for -** the API user to pass any user data to its callback function. -** -** -** Parameters -** event (in) : the XML event or XML contruct just parsed, -** p_event_data (in) : data, i.e. names values etc, found in the XML -** construct. The data is specific for the XML -** construct and should be casted to the -** proper type as descibed above. May not be NULL. -** p_usr_data (in) : Same p_usr_data as passed in XML_Parse. -** -** Returns -** TRUE : if parsing should continue -** FALSE : if parsing should stop -** -*****************************************************************************/ - -typedef BOOLEAN (*tXML_CBACK)(tXML_EVENT event, void *p_event_data, - void *p_usr_data); - -typedef struct -{ - - UINT8 p[512]; - UINT16 len; -} tXML_STR_PARTIAL; - -typedef struct -{ - tXML_STR_PARTIAL last_bfr; - UINT16 used_last_bfr; - tXML_MEVT_DATA event_data; -} -tXML_PARTIAL; - -/* tXML_STATE stores state during the XML_Parse call not between -** XML_Parse calls. It is used in most static functions in this file -** and passed in as first parameter to these. -*/ -typedef struct -{ - /* input from XML_Parse caller */ - tXML_OS xml_os; - UINT8 *p_cur; - tXML_CBACK cback; - void *p_usr_data; - tXML_MEVT_DATA event_data; - - /* handling of data buffers for prefix, name and value */ - UINT8 *p_data_bfr; - UINT8 *p_last_stm; /* last '<' */ - UINT8 *p_copy; - tXML_STR last_bfr; - tXML_STR value; - tXML_STR prefix; - tXML_STR name; - - /* token and result handling */ - INT16 curr_res; - tXML_RESULT pars_res; - UINT8 next_token; - BOOLEAN skip_next_nl; - - UINT16 used_last_bfr; /* the actual data size in p_last_bfr */ - tXML_STATUS status; - - /* structure used to store partial data */ - tXML_PARTIAL partial_st; -} tXML_MUL_STATE; - -/***************************************************************************** -** External Function Declarations -*****************************************************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif - -/***************************************************************************** -** -** Function XML_Parse -** -** Description -** Parses an XML message/document in utf8. The message is read from -** an object store which must have been initialised and an object -** (file) must have been opened so the parser can start directly with -** reading the first byte using the GOEP_Read function and passing -** the h_obj_store in-param. -** The parser will call the xml_cback callback for each basic -** XML-construct parsed. If the parser encounters an error it will -** try to act according to the err_action in-param and report any -** errors through the err_handle. The parser is non-validating. -** -** Parameters -** h_obj_store (in) : a handle to an opened object (file) in -** the Object Store. The object must be -** ready for reading. -** xml_cback (in) : the user provided function to call back -** for each XML-construct (XML event) parsed. -** err_action (in) : the action the parser will try if it finds -** an error. -** err_handle (in) : a handle to some error recording object to -** which the parser may report errors. This is -** a place holder to connect any type of error -** recording object. -** p_usr_data (in) : any user data that will be passed on -** unchanged to the callback function. -** -** Returns -** 0 if the parsing was successfull without errors -** non-zero error or warning code otherwise -** -*****************************************************************************/ - -tXML_RESULT XML_Parse(tXML_OS *p_os, tXML_CBACK xml_cback, - tXML_ERR_ACTION err_action, UINT32 err_handle, - void *p_usr_data); - -/***************************************************************************** -** -** Function XML_MulParse -** -** Description Initialize XML parser state machine. -** -** Parameters -** p_st (in) : xml state machine. -** p_os (in) : xml data storage -** -*****************************************************************************/ -tXML_RESULT XML_MulParse(tXML_MUL_STATE *p_st, tXML_OS *p_os); - -/***************************************************************************** -** -** Function XML_InitPars -** -** Description Initialize XML parser state machine. -** -** Parameters -** p_st (in) : xml state machine. -** xml_cback (in) : the user provided function to call back -** p_usr_data : user defined data. -** -*****************************************************************************/ -void XML_InitPars(tXML_MUL_STATE *p_st, tXML_CBACK xml_cback, void *p_usr_data); - -#ifdef __cplusplus -} -#endif - -#endif /* ifndef XML_PARS_API_H */ diff --git a/stack/include/xml_vlist_api.h b/stack/include/xml_vlist_api.h deleted file mode 100644 index 362432a..0000000 --- a/stack/include/xml_vlist_api.h +++ /dev/null @@ -1,136 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_vlist_api.h - ** - ** Description: This module contains xml parser of obex vcard listing - ** - ** Copyright (c) 2004-2005, Broadcom Corporation, All Rights Reserved. - ** WIDCOMM Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#ifndef XML_VLIST_API_H -#define XML_VLIST_API_H - -#include "bt_target.h" -#include "gki.h" -#include "xml_pars_api.h" - -/**********************************************************************************/ -#ifndef XML_VLIST_CARRY_OVER_LEN -#define XML_VLIST_CARRY_OVER_LEN 512 /* number of bytes we can store in case we did not yet find the > */ -#endif - -typedef struct -{ - UINT16 handle_len; - UINT8 *handle; - UINT16 name_len; - UINT8 *name; -} tXML_VLIST_ENTRY; - -/**********************************************************************************/ - -typedef enum -{ - XML_VLIST_OK, /* parsing is ok, operation is ok */ - XML_VLIST_PENDING, /* parsing is ok but not enough data */ - XML_VLIST_END_LIST, /* found </vCard-listing> */ - XML_VLIST_OUT_FULL, /* output buffer full /vCard-listing not reached! data is dumped */ - XML_VLIST_ERROR, /* some parsing error occured */ - XML_VLIST_NO_RES, /* ran out of resources (memory) */ - XML_VLIST_DST_NO_RES /* ran out of destination data buffer */ -} txml_vlist_res; -typedef UINT8 tXML_VLIST_RES; - - -typedef struct -{ - tXML_VLIST_ENTRY *p_entry; - tXML_PROP *p_prop; - - tXML_PROP *offset_prop; /* current filling property */ - UINT16 prop_num; /* number of properties left to be filled in */ - - INT16 current_entry; - INT16 max_name_len; /* maximum length of name length of entry - XML parser limits to 64 bytes i think. */ - UINT16 max_entry; - BOOLEAN ended; - UINT16 prop_index; - UINT16 max_num_prop; - UINT8 obj; /* the XML object */ -} tXML_VLIST_STATE; - -typedef struct -{ - tXML_MUL_STATE xml; - tXML_VLIST_STATE xml_user_data; -} tXML_VLIST_PARSER; - -/* only this value is of significance, if not ok frame is dropped by parser */ -#define XML_VLIST_ENTRY_OK 0 - -typedef UINT8 tXML_VLIST_STATUS; - - -typedef struct -{ - UINT8 *data; - UINT16 len; - BOOLEAN final; /* If TRUE, entry is last of the series */ - tXML_VLIST_STATUS status; /* Fields are valid when status is BTA_FTC_OK */ -} tXML_VLIST_LIST; /* clone of tBTA_FTC_LIST */ - - -/************************************************************************************** -** Function XML_VlistInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of parser structure, allocate an additional space -** of size XML_VLIST_CARRY_OVER_LEN right after p_xml_state -** to hold carry over data. -** p_entry : points start of output vlist entry. caller needs do free this memory -** max_entry : max is 16 bit integer value which is the maximum number of vlist entries. - -** -** Returns void -**************************************************************************************/ -BT_API void XML_VlistInit(tXML_VLIST_PARSER *p_xml_state, - tXML_VLIST_ENTRY *p_entry, - const UINT16 max_entry ); - - -/************************************************************************************** -** Function XML_VlistParse -** -** Description This function is called to parse the xml data received from OBEX -** into vlist entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_VlistInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted vlist entry name and handle. -** When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: length of the dst_data buffer, its carry out value is the number -** of bytes of available buffer remains. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_VLIST_RES (see xml_vlist_api.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /vCard-listing but no final flag detected -** XML_VLIST_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_VLIST_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -BT_API extern tXML_VLIST_RES XML_VlistParse( tXML_VLIST_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ); - - -#endif diff --git a/stack/obx/hdrs/obx_dauth.c b/stack/obx/hdrs/obx_dauth.c deleted file mode 100644 index 91d4bd7..0000000 --- a/stack/obx/hdrs/obx_dauth.c +++ /dev/null @@ -1,149 +0,0 @@ -/***************************************************************************** -** -** Name: obx_dauth.c -** -** File: OBEX Authentication related functions -** -** Copyright (c) 2003-2008, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include "bt_target.h" -#include "obx_api.h" - - - - - -#if (OBX_CLIENT_INCLUDED == TRUE) - -/******************************************************************************* -** -** Function OBX_ReadChallenge -** -** Description This function is called by the client to read the Realm and -** options of the Authentication Challenge Header in the -** given OBEX packet ( from an OBX_PASSWORD_EVT event). -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadChallenge(BT_HDR *p_pkt, tOBX_CHARSET *p_charset, - UINT8 **p_realm, UINT8 *p_len, - tOBX_AUTH_OPT *p_option) -{ - BOOLEAN status; - tOBX_TRIPLET triplet[OBX_MAX_NUM_AUTH_TRIPLET]; - UINT8 num_trip = OBX_MAX_NUM_AUTH_TRIPLET; - UINT8 xx; - - /* The coverity complaints on this function is not correct. - * The value in triplet[] is set/initialized by OBX_ReadTriplet if it returns TRUE. - * leave this unnecessary memset here */ - memset( triplet, 0, sizeof(triplet )); - - *p_len = 0; - *p_option = OBX_AO_NONE; - *p_realm = NULL; - *p_charset = OBX_RCS_ASCII; /* 0 */ - status = OBX_ReadTriplet(p_pkt, OBX_HI_CHALLENGE, triplet, &num_trip); - if(status) - { - for(xx=0; xx<num_trip; xx++) - { - switch(triplet[xx].tag) - { - case OBX_OPTIONS_CHLNG_TAG: - *p_option = triplet[xx].p_array[0]; - break; - case OBX_REALM_CHLNG_TAG: - *p_charset = triplet[xx].p_array[0]; - *p_len = triplet[xx].len - 1; - *p_realm = &(triplet[xx].p_array[1]); - break; - /* The user does not need to know the nonce value - case OBX_NONCE_CHLNG_TAG: - break; - */ - } - } - } - - return status; -} -#endif - - - -#if (OBX_SERVER_INCLUDED == TRUE) -/******************************************************************************* -** -** Function OBX_ReadAuthParams -** -** Description This function is called by the server to read the User ID of -** the Authentication Response Header in the given OBEX packet -** ( from an OBX_PASSWORD_EVT event). -** This function also -** checks if the authentication challenge header exists and -** checks the authentication challenge options. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadAuthParams(BT_HDR *p_pkt, UINT8 **p_userid, UINT8 *p_len, - BOOLEAN *is_challenged, tOBX_AUTH_OPT *p_option) -{ - BOOLEAN status; - tOBX_TRIPLET triplet[OBX_MAX_NUM_AUTH_TRIPLET]; - UINT8 num_trip = OBX_MAX_NUM_AUTH_TRIPLET; - UINT8 xx; - - /* The coverity complaints on this function is not correct. - * The value in triplet[] is set/initialized by OBX_ReadTriplet if it returns TRUE. - * leave this unnecessary memset here */ - memset( triplet, 0, sizeof(triplet )); - - *p_userid = NULL; - *p_len = 0; - *is_challenged = FALSE; - *p_option = OBX_AO_NONE; - status = OBX_ReadTriplet(p_pkt, OBX_HI_AUTH_RSP, triplet, &num_trip); - if(status) - { - /* found authentication response, but we do not know if it has user id. - * assume no user id */ - *p_len = 0; - for(xx=0; xx<num_trip; xx++) - { - if(triplet[xx].tag == OBX_USERID_RSP_TAG) - { - *p_len = triplet[xx].len; - *p_userid = triplet[xx].p_array; - break; - } - } - - /* read the authentication challenge header, - * only if the authentication response header exists */ - if( OBX_ReadTriplet(p_pkt, OBX_HI_CHALLENGE, triplet, &num_trip) == TRUE) - { - *is_challenged = TRUE; - for(xx=0; xx<num_trip; xx++) - { - if(triplet[xx].tag == OBX_OPTIONS_CHLNG_TAG) - { - *p_option = triplet[xx].p_array[0]; - break; - } - } - } - } - return status; -} -#endif - - - diff --git a/stack/obx/hdrs/obx_dbtp.c b/stack/obx/hdrs/obx_dbtp.c deleted file mode 100644 index fbf473d..0000000 --- a/stack/obx/hdrs/obx_dbtp.c +++ /dev/null @@ -1,189 +0,0 @@ -/***************************************************************************** -** -** Name: obx_dbtp.c -** -** File: OBEX Headers Decode Utility functions -** - for current Bluetooth profiles -** -** Copyright (c) 2003-2008, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include "bt_target.h" -#include "obx_api.h" -#include "obx_int.h" - - - - -/******************************************************************************* -** -** Function OBX_ReadTypeHdr -** -** Description This function is called to get the Type Header in the given -** OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadTypeHdr(BT_HDR *p_pkt, UINT8 **p_type, UINT16 *p_len) -{ - return OBX_ReadByteStrHdr(p_pkt, OBX_HI_TYPE, p_type, p_len, 0); -} - -/******************************************************************************* -** -** Function OBX_ReadLengthHdr -** -** Description This function is called to get the Length Header in the given -** OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadLengthHdr(BT_HDR *p_pkt, UINT32 *p_len) -{ - return OBX_Read4ByteHdr(p_pkt, OBX_HI_LENGTH, p_len); -} - -/******************************************************************************* -** -** Function OBX_ReadTargetHdr -** -** Description This function is called to get the Target Header in the -** given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadTargetHdr(BT_HDR *p_pkt, UINT8 **p_target, UINT16 *p_len, UINT8 next) -{ - return OBX_ReadByteStrHdr(p_pkt, OBX_HI_TARGET, p_target, p_len, next); -} - -/******************************************************************************* -** -** Function OBX_ReadBodyHdr -** -** Description This function is called to get the Body Header in the -** given OBEX packet. -** -** Returns 1, if a single header is in the OBEX packet. -** 2, if a end of body header is in the OBEX packet. -** 0, (FALSE) otherwise. -** -*******************************************************************************/ -UINT8 OBX_ReadBodyHdr(BT_HDR *p_pkt, UINT8 **p_body, UINT16 *p_len, BOOLEAN *p_end) -{ - BOOLEAN status; - UINT8 *p_body2; - UINT16 len2; - UINT8 num; - - *p_end = FALSE; - num = OBX_ReadByteStrHdr(p_pkt, OBX_HI_BODY, p_body, p_len, 0); - status = OBX_ReadByteStrHdr(p_pkt, OBX_HI_BODY_END, &p_body2, &len2, 0); - if(num == FALSE && status == TRUE) - { - *p_body = p_body2; - *p_len = len2; - *p_end = TRUE; - } - num += status; - - return num; -} - -/******************************************************************************* -** -** Function OBX_ReadWhoHdr -** -** Description This function is called to get the Who Header in the -** given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadWhoHdr(BT_HDR *p_pkt, UINT8 **p_who, UINT16 *p_len) -{ - return OBX_ReadByteStrHdr(p_pkt, OBX_HI_WHO, p_who, p_len, 0); -} - -/******************************************************************************* -** -** Function OBX_ReadAppParamHdr -** -** Description This function is called to get the Application Parameter Header -** in the given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadAppParamHdr(BT_HDR *p_pkt, UINT8 *p_tag, UINT8 **p_app_param, UINT8 *p_len, UINT8 next) -{ - BOOLEAN status; - tOBX_TRIPLET triplet[OBX_MAX_TRIPLET]; - UINT8 num = OBX_MAX_TRIPLET; - - /* The coverity complaints on this function is not correct. - * The value in triplet[] is set/initialized by OBX_ReadTriplet if it returns TRUE. - * leave this unnecessary memset here */ - memset( triplet, 0, sizeof(triplet )); - - status = OBX_ReadTriplet(p_pkt, OBX_HI_APP_PARMS, triplet, &num); - if(status == TRUE) - { - if(next >= num) - { - status = FALSE; - } - else - { - *p_tag = triplet[next].tag; - *p_app_param = triplet[next].p_array; - *p_len = triplet[next].len; - OBX_TRACE_DEBUG3( "OBX_ReadAppParamHdr: next: %d, tag: %x, len: %d", - next, *p_tag, *p_len); - } - } - return status; -} - -/******************************************************************************* -** -** Function OBX_ReadPermissionHdr -** -** Description This function is called to get the Application Parameter Header -** in the given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadPermissionHdr(BT_HDR *p_pkt, UINT8 *p_user, UINT8 *p_group, UINT8 *p_other) -{ - UINT32 permission; - BOOLEAN status = FALSE; - - if (OBX_Read4ByteHdr(p_pkt, OBX_HI_PERMISSION, &permission)) - { - *p_other = (permission & 0xFF); - permission >>= 8; - *p_group = (permission & 0xFF); - permission >>= 8; - *p_user = (permission & 0xFF); - status = TRUE; - } - - return status; -} - - - - diff --git a/stack/obx/hdrs/obx_dopt.c b/stack/obx/hdrs/obx_dopt.c deleted file mode 100644 index e3d0d27..0000000 --- a/stack/obx/hdrs/obx_dopt.c +++ /dev/null @@ -1,52 +0,0 @@ -/***************************************************************************** -** -** Name: obx_dopt.c -** -** File: OBEX Headers Decode Utility functions -** - optional functions -** -** Copyright (c) 2003-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "obx_api.h" - - - - - - -/******************************************************************************* -** -** Function OBX_ReadTimeHdr -** -** Description This function is called to get the Time Header in the given -** OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadTimeHdr(BT_HDR *p_pkt, UINT8 **p_time, UINT16 *p_len) -{ - return OBX_ReadByteStrHdr(p_pkt, OBX_HI_TIME, p_time, p_len, 0); -} - - -/******************************************************************************* -** -** Function OBX_ReadHttpHdr -** -** Description This function is called to get the HTTP Header in the -** given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadHttpHdr(BT_HDR *p_pkt, UINT8 **p_http, UINT16 *p_len, UINT8 next) -{ - return OBX_ReadByteStrHdr(p_pkt, OBX_HI_HTTP, p_http, p_len, next); -} - diff --git a/stack/obx/hdrs/obx_dunic.c b/stack/obx/hdrs/obx_dunic.c deleted file mode 100644 index c8f6b12..0000000 --- a/stack/obx/hdrs/obx_dunic.c +++ /dev/null @@ -1,64 +0,0 @@ -/***************************************************************************** -** -** Name: obx_dunic.c -** -** File: OBEX Headers Decode Utility functions -** - Unicode functions -** -** Copyright (c) 2003-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "obx_api.h" - - - - -/******************************************************************************* -** -** Function OBX_ReadNameHdr -** -** Description This function is called to get the Name Header in the given -** OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadNameHdr(BT_HDR *p_pkt, UINT16 *p_name, UINT16 *p_len) -{ - return OBX_ReadUnicodeHdr(p_pkt, OBX_HI_NAME, p_name, p_len); -} - -/******************************************************************************* -** -** Function OBX_ReadDescrHdr -** -** Description This function is called to get the Description Header in the -** given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadDescrHdr(BT_HDR *p_pkt, UINT16 *p_descr, UINT16 *p_len) -{ - return OBX_ReadUnicodeHdr(p_pkt, OBX_HI_DESCRIPTION, p_descr, p_len); -} - -/******************************************************************************* -** -** Function OBX_ReadDestNameHdr -** -** Description This function is called to get the DestName Header in the -** given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadDestNameHdr(BT_HDR *p_pkt, UINT16 *p_dest, UINT16 *p_len) -{ - return OBX_ReadUnicodeHdr(p_pkt, OBX_HI_DEST_NAME, p_dest, p_len); -} diff --git a/stack/obx/hdrs/obx_dutf.c b/stack/obx/hdrs/obx_dutf.c deleted file mode 100644 index a800428..0000000 --- a/stack/obx/hdrs/obx_dutf.c +++ /dev/null @@ -1,91 +0,0 @@ -/***************************************************************************** -** -** Name: obx_dutf.c -** -** File: OBEX Headers Decode Utility functions -** - Unicode conversion functions -** -** Copyright (c) 2003-2009, Broadcom Corp., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "gki.h" -#include "obx_api.h" - - -/******************************************************************************* -** -** Function OBX_ReadUtf8NameHdr -** -** Description This function is called to get the Name Header in the given -** OBEX packet. If Name header exists in the given OBEX packet, -** it is converted to UTF8 format and copied into p_name. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadUtf8NameHdr(BT_HDR *p_pkt, UINT8 *p_name, UINT16 max_len) -{ - BOOLEAN status; - UINT16 *p_unicode = (UINT16 *)GKI_getbuf((UINT16)((max_len + 1) * 2)); - UINT16 len = max_len; - - status = OBX_ReadUnicodeHdr(p_pkt, OBX_HI_NAME, p_unicode, &len); - utfc_16_to_8(p_name, max_len, p_unicode, len); - GKI_freebuf(p_unicode); - return status; -} - - - -/******************************************************************************* -** -** Function OBX_ReadUtf8DescrHdr -** -** Description This function is called to get the Description Header in the -** given OBEX packet. If Description header exists in the given -** OBEX packet, it is converted to UTF8 format and copied into -** p_descr. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadUtf8DescrHdr(BT_HDR *p_pkt, UINT8 *p_descr, UINT16 max_len) -{ - BOOLEAN status; - UINT16 *p_unicode = (UINT16 *)GKI_getbuf((UINT16)((max_len + 1) * 2)); - UINT16 len = max_len; - - status = OBX_ReadUnicodeHdr(p_pkt, OBX_HI_DESCRIPTION, p_unicode, &len); - utfc_16_to_8(p_descr, max_len, p_unicode, len); - GKI_freebuf(p_unicode); - return status; -} - -/******************************************************************************* -** -** Function OBX_ReadUtf8DestNameHdr -** -** Description This function is called to get the DestName Header in the -** given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadUtf8DestNameHdr(BT_HDR *p_pkt, UINT8 *p_dest, UINT16 max_len) -{ - BOOLEAN status; - UINT16 *p_unicode = (UINT16 *)GKI_getbuf((UINT16)((max_len + 1) * 2)); - UINT16 len = max_len; - - status = OBX_ReadUnicodeHdr(p_pkt, OBX_HI_DEST_NAME, p_unicode, &len); - utfc_16_to_8(p_dest, max_len, p_unicode, len); - GKI_freebuf(p_unicode); - return status; -} - - diff --git a/stack/obx/hdrs/obx_dwchar.c b/stack/obx/hdrs/obx_dwchar.c deleted file mode 100644 index 2aa5ebd..0000000 --- a/stack/obx/hdrs/obx_dwchar.c +++ /dev/null @@ -1,91 +0,0 @@ -/***************************************************************************** -** -** Name: obx_dwchar.c -** -** File: OBEX Headers Decode Utility functions -** - Unicode conversion functions -** -** Copyright (c) 2003-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "gki.h" -#include "obx_api.h" - - -/******************************************************************************* -** -** Function OBX_ReadAsciiNameHdr -** -** Description This function is called to get the Name Header in the given -** OBEX packet. If Name header exists in the given OBEX packet, -** it is converted to ASCII format and copied into p_name. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadAsciiNameHdr(BT_HDR *p_pkt, char *p_name, UINT16 max_len) -{ - BOOLEAN status; - UINT16 *p_unicode = (UINT16 *)GKI_getbuf((UINT16)((max_len + 1) * 2)); - UINT16 len = max_len; - - status = OBX_ReadUnicodeHdr(p_pkt, OBX_HI_NAME, p_unicode, &len); - OBX_WcharToChar(p_name, p_unicode, max_len); - GKI_freebuf(p_unicode); - return status; -} - - - -/******************************************************************************* -** -** Function OBX_ReadAsciiDescrHdr -** -** Description This function is called to get the Description Header in the -** given OBEX packet. If Description header exists in the given -** OBEX packet, it is converted to ASCII format and copied into -** p_descr. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadAsciiDescrHdr(BT_HDR *p_pkt, char *p_descr, UINT16 max_len) -{ - BOOLEAN status; - UINT16 *p_unicode = (UINT16 *)GKI_getbuf((UINT16)((max_len + 1) * 2)); - UINT16 len = max_len; - - status = OBX_ReadUnicodeHdr(p_pkt, OBX_HI_DESCRIPTION, p_unicode, &len); - OBX_WcharToChar(p_descr, p_unicode, max_len); - GKI_freebuf(p_unicode); - return status; -} - -/******************************************************************************* -** -** Function OBX_ReadAsciiDestNameHdr -** -** Description This function is called to get the DestName Header in the -** given OBEX packet. If DestName header exists in the given -** OBEX packet, it is converted to ASCII format and copied into -** p_descr. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadAsciiDestNameHdr(BT_HDR *p_pkt, char *p_dest, UINT16 max_len) -{ - BOOLEAN status; - UINT16 *p_unicode = (UINT16 *)GKI_getbuf((UINT16)((max_len + 1) * 2)); - UINT16 len = max_len; - - status = OBX_ReadUnicodeHdr(p_pkt, OBX_HI_DEST_NAME, p_unicode, &len); - OBX_WcharToChar(p_dest, p_unicode, max_len); - GKI_freebuf(p_unicode); - return status; -} diff --git a/stack/obx/hdrs/obx_ebtp.c b/stack/obx/hdrs/obx_ebtp.c deleted file mode 100644 index 93dd988..0000000 --- a/stack/obx/hdrs/obx_ebtp.c +++ /dev/null @@ -1,177 +0,0 @@ -/***************************************************************************** -** -** Name: obx_ebtp.c -** -** File: OBEX Headers Encode Utility functions -** - for current Bluetooth profiles -** -** Copyright (c) 2003-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "bt_target.h" -#include "obx_api.h" - - - -/******************************************************************************* -** -** Function OBX_AddTypeHdr -** -** Description This function is called to add an OBEX Type header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddTypeHdr(BT_HDR *p_pkt, char *p_type) -{ - return OBX_AddByteStrHdr(p_pkt, OBX_HI_TYPE, (UINT8*)p_type, (UINT16)(strlen(p_type)+1)); -} - -/******************************************************************************* -** -** Function OBX_AddLengthHdr -** -** Description This function is called to add an OBEX Length header to an OBEX -** packet. The Length header describes the total length in bytes of -** the object. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddLengthHdr(BT_HDR *p_pkt, UINT32 len) -{ - return OBX_Add4ByteHdr(p_pkt, OBX_HI_LENGTH, len); -} - -/******************************************************************************* -** -** Function OBX_AddTargetHdr -** -** Description This function is called to add an OBEX Target header to an OBEX -** packet. This header is most commonly used in Connect packets. -** -** NOTE: The target header must be the first header in an OBEX message. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddTargetHdr(BT_HDR *p_pkt, UINT8 *p_target, UINT16 len) -{ - BOOLEAN add = FALSE; - UINT8 *p; - - if (p_pkt->len == 0) - { - add = TRUE; - } - else if (p_pkt->len == 2) - { - p = (UINT8 *)(p_pkt+1)+p_pkt->offset; - if ((*p) == OBX_HI_SESSION_SN) - add = TRUE; - - } - /* allow SSN to preceed target header */ - if (add) - return OBX_AddByteStrHdr(p_pkt, OBX_HI_TARGET, p_target, len); - else - { - BT_ERROR_TRACE_1(TRACE_LAYER_OBEX, "Target header must be the first:%d", p_pkt->len) ; - return FALSE; - } -} - -/******************************************************************************* -** -** Function OBX_AddBodyHdr -** -** Description This function is called to add an OBEX body header -** to an OBEX packet. -** -** NOTE: The body header must be the last header in an OBEX message. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddBodyHdr(BT_HDR *p_pkt, UINT8 *p_body, UINT16 len, BOOLEAN end) -{ - UINT8 id = (end)?OBX_HI_BODY_END:OBX_HI_BODY; - return OBX_AddByteStrHdr(p_pkt, id, p_body, len); -} - - -/******************************************************************************* -** -** Function OBX_AddWhoHdr -** -** Description This function is called to add an OBEX Who header to an OBEX -** packet. -** -** Note: Who header is typically used in an OBEX CONNECT response packet -** to indicate the UUID of the service that has accepted the -** directed connection. If the server calls OBX_StartServer() with -** specified target header, this OBEX implementation automatically -** adds this WHO header to the CONNECT response packet. If -** OBX_StartServer() is called with target header length as 0, the -** OBEX API user is responsible to add the WHO header. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddWhoHdr(BT_HDR *p_pkt, UINT8 *p_who, UINT16 len) -{ - return OBX_AddByteStrHdr(p_pkt, OBX_HI_WHO, p_who, len); -} - -/******************************************************************************* -** -** Function OBX_AddAppParamHdr -** -** Description This function is called to add an OBEX Application Parameter -** header to an OBEX packet. This header is used by the application -** layer above OBEX to convey application specific information. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddAppParamHdr(BT_HDR *p_pkt, tOBX_TRIPLET *p_triplet, UINT8 num) -{ - return OBX_AddTriplet(p_pkt, OBX_HI_APP_PARMS, p_triplet, num); -} - -/******************************************************************************* -** -** Function OBX_AddPermissionHdr -** -** Description This function is called to add an OBEX Permission header to an OBEX -** packet. -** bit 0 is set for read permission -** bit 1 is set for write permission -** bit 2 is set for delete permission -** bit 7 is set for modify permission -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddPermissionHdr(BT_HDR *p_pkt, UINT8 user, UINT8 group, UINT8 other) -{ - UINT32 permission = user; - permission <<= 8; - permission |= group; - permission <<= 8; - permission |= other; - return OBX_Add4ByteHdr(p_pkt, OBX_HI_PERMISSION, permission); -} - - diff --git a/stack/obx/hdrs/obx_eopt.c b/stack/obx/hdrs/obx_eopt.c deleted file mode 100644 index e0b0487..0000000 --- a/stack/obx/hdrs/obx_eopt.c +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************** -** -** Name: obx_eopt.c -** -** File: OBEX Headers Encode Utility functions -** - optional functions -** -** Copyright (c) 2003-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include "bt_target.h" -#include "obx_api.h" - - - -/******************************************************************************* -** -** Function OBX_AddTimeHdr -** -** Description This function is called to add an OBEX Time header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddTimeHdr(BT_HDR *p_pkt, char *p_time) -{ - return OBX_AddByteStrHdr(p_pkt, OBX_HI_TIME, (UINT8 *)p_time, (UINT16)strlen(p_time)); -} - - -/******************************************************************************* -** -** Function OBX_AddHttpHdr -** -** Description This function is called to add an OBEX HTTP header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddHttpHdr(BT_HDR *p_pkt, UINT8 *p_http, UINT16 len) -{ - return OBX_AddByteStrHdr(p_pkt, OBX_HI_HTTP, p_http, len); -} - - diff --git a/stack/obx/hdrs/obx_eunic.c b/stack/obx/hdrs/obx_eunic.c deleted file mode 100644 index 6b5cb29..0000000 --- a/stack/obx/hdrs/obx_eunic.c +++ /dev/null @@ -1,64 +0,0 @@ -/***************************************************************************** -** -** Name: obx_eunic.c -** -** File: OBEX Headers Encode Utility functions -** - Unicode functions -** -** Copyright (c) 2003-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "obx_api.h" - - -/******************************************************************************* -** -** Function OBX_AddNameHdr -** -** Description This function is called to add an OBEX Name header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddNameHdr(BT_HDR *p_pkt, UINT16 *p_name, UINT16 len) -{ - return OBX_AddUnicodeHdr(p_pkt, OBX_HI_NAME, p_name, len); -} - -/******************************************************************************* -** -** Function OBX_AddDescrHdr -** -** Description This function is called to add an OBEX Description header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddDescrHdr(BT_HDR *p_pkt, UINT16 *p_descr, UINT16 len) -{ - return OBX_AddUnicodeHdr(p_pkt, OBX_HI_DESCRIPTION, p_descr, len); -} - -/******************************************************************************* -** -** Function OBX_AddDestNameHdr -** -** Description This function is called to add an OBEX DestName header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddDestNameHdr(BT_HDR *p_pkt, UINT16 *p_dest, UINT16 len) -{ - return OBX_AddUnicodeHdr(p_pkt, OBX_HI_DEST_NAME, p_dest, len); -} - - diff --git a/stack/obx/hdrs/obx_eutf.c b/stack/obx/hdrs/obx_eutf.c deleted file mode 100644 index b298500..0000000 --- a/stack/obx/hdrs/obx_eutf.c +++ /dev/null @@ -1,111 +0,0 @@ -/***************************************************************************** -** -** Name: obx_eutf.c -** -** File: OBEX Headers Encode Utility functions -** - Unicode conversion functions -** -** Copyright (c) 2003-2005, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include "bt_target.h" -#include "gki.h" -#include "obx_api.h" - - -/******************************************************************************* -** -** Function OBX_AddUtf8NameHdr -** -** Description This function is called to add an OBEX Name header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddUtf8NameHdr(BT_HDR *p_pkt, UINT8 *p_name) -{ - BOOLEAN status = FALSE; - UINT16 utf16_len = 0; - UINT16 *p_utf16 = NULL; - - if (p_name) - { - utf16_len = strlen((char *)p_name) * 2 + 2; - p_utf16 = (UINT16 *)GKI_getbuf(utf16_len); - } - - if (p_utf16) - utf16_len = utfc_8_to_16(p_utf16, utf16_len, p_name); - else - utf16_len = 0; - - status = OBX_AddUnicodeHdr(p_pkt, OBX_HI_NAME, p_utf16, utf16_len); - - if (p_utf16) - GKI_freebuf(p_utf16); - - return status; -} - -/******************************************************************************* -** -** Function OBX_AddUtf8DescrHdr -** -** Description This function is called to add an OBEX Description header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddUtf8DescrHdr(BT_HDR *p_pkt, UINT8 *p_descr) -{ - BOOLEAN status = FALSE; - UINT16 utf16_len; - UINT16 *p_utf16; - - utf16_len = strlen((char *)p_descr) * 2 + 2; - p_utf16 = (UINT16 *)GKI_getbuf(utf16_len); - if(p_utf16) - { - utf16_len = utfc_8_to_16(p_utf16, utf16_len, p_descr); - status = OBX_AddUnicodeHdr(p_pkt, OBX_HI_DESCRIPTION, p_utf16, utf16_len); - GKI_freebuf(p_utf16); - } - return status; -} - -/******************************************************************************* -** -** Function OBX_AddUtf8DestNameHdr -** -** Description This function is called to add an OBEX DestName header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddUtf8DestNameHdr(BT_HDR *p_pkt, UINT8 *p_dest) -{ - BOOLEAN status = FALSE; - UINT16 utf16_len; - UINT16 *p_utf16; - - utf16_len = strlen((char *)p_dest) * 2 + 2; - p_utf16 = (UINT16 *)GKI_getbuf(utf16_len); - if(p_utf16) - { - utf16_len = utfc_8_to_16(p_utf16, utf16_len, p_dest); - status = OBX_AddUnicodeHdr(p_pkt, OBX_HI_DEST_NAME, p_utf16, utf16_len); - GKI_freebuf(p_utf16); - } - return status; -} - - - diff --git a/stack/obx/hdrs/obx_ewchar.c b/stack/obx/hdrs/obx_ewchar.c deleted file mode 100644 index 2025baa..0000000 --- a/stack/obx/hdrs/obx_ewchar.c +++ /dev/null @@ -1,100 +0,0 @@ -/***************************************************************************** -** -** Name: obx_ewchar.c -** -** File: OBEX Headers Encode Utility functions -** - Unicode conversion functions -** -** Copyright (c) 2003-2005, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include "bt_target.h" -#include "gki.h" -#include "obx_api.h" - -/******************************************************************************* -** -** Function OBX_AddAsciiNameHdr -** -** Description This function is called to add an OBEX Name header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddAsciiNameHdr(BT_HDR *p_pkt, char *p_name) -{ - BOOLEAN status; - UINT16 len = 0; - UINT16 *p_unicode = NULL; - - if(p_name) - { - len = strlen(p_name) + 1; - p_unicode = (UINT16 *)GKI_getbuf((UINT16)(len*2)); - } - - if(p_unicode) - len = OBX_CharToWchar(p_unicode, p_name, len); - else - len = 0; - - status = OBX_AddUnicodeHdr(p_pkt, OBX_HI_NAME, p_unicode, len); - - if(p_unicode) - GKI_freebuf(p_unicode); - return status; -} - - -/******************************************************************************* -** -** Function OBX_AddAsciiDescrHdr -** -** Description This function is called to add an OBEX Description header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddAsciiDescrHdr(BT_HDR *p_pkt, char *p_descr) -{ - BOOLEAN status; - UINT16 len = strlen(p_descr) + 1; - UINT16 *p_unicode = (UINT16 *)GKI_getbuf((UINT16)(len*2)); - - len = OBX_CharToWchar(p_unicode, p_descr, len); - status = OBX_AddUnicodeHdr(p_pkt, OBX_HI_DESCRIPTION, p_unicode, len); - GKI_freebuf(p_unicode); - return status; -} - -/******************************************************************************* -** -** Function OBX_AddAsciiDestNameHdr -** -** Description This function is called to add an OBEX DestName header -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddAsciiDestNameHdr(BT_HDR *p_pkt, char *p_dest) -{ - BOOLEAN status; - UINT16 len = strlen(p_dest) + 1; - UINT16 *p_unicode = (UINT16 *)GKI_getbuf((UINT16)(len*2)); - - len = OBX_CharToWchar(p_unicode, p_dest, len); - status = OBX_AddUnicodeHdr(p_pkt, OBX_HI_DEST_NAME, p_unicode, len); - GKI_freebuf(p_unicode); - return status; -} - - - diff --git a/stack/obx/hdrs/obx_gen.c b/stack/obx/hdrs/obx_gen.c deleted file mode 100644 index 9b25e04..0000000 --- a/stack/obx/hdrs/obx_gen.c +++ /dev/null @@ -1,896 +0,0 @@ -/***************************************************************************** -** -** Name: obx_gen.c -** -** File: OBEX Headers Utility functions -** - common/generic functions -** -** Copyright (c) 2003-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "bt_target.h" -#include "wcassert.h" -#include "obx_api.h" -#include "gki.h" -#include "obx_int.h" - -const UINT8 obx_hdr_start_offset[] = -{ - OBX_CONN_HDRS_OFFSET, /* OBX_CONNECT_REQ_EVT */ - OBX_SESS_HDRS_OFFSET, /* OBX_SESSION_REQ_EVT */ - OBX_DISCON_HDRS_OFFSET, /* OBX_DISCONNECT_REQ_EVT */ - OBX_PUT_HDRS_OFFSET, /* OBX_PUT_REQ_EVT */ - OBX_GET_HDRS_OFFSET, /* OBX_GET_REQ_EVT */ - OBX_SETPATH_REQ_HDRS_OFFSET,/* OBX_SETPATH_REQ_EVT */ - OBX_ABORT_HDRS_OFFSET, /* OBX_ABORT_REQ_EVT */ - OBX_ACTION_HDRS_OFFSET, /* OBX_ACTION_REQ_EVT */ - OBX_CONN_HDRS_OFFSET, /* OBX_CONNECT_RSP_EVT */ - OBX_RESPONSE_HDRS_OFFSET, /* OBX_SESSION_RSP_EVT */ - OBX_RESPONSE_HDRS_OFFSET, /* OBX_DISCONNECT_RSP_EVT */ - OBX_RESPONSE_HDRS_OFFSET, /* OBX_PUT_RSP_EVT */ - OBX_RESPONSE_HDRS_OFFSET, /* OBX_GET_RSP_EVT */ - OBX_RESPONSE_HDRS_OFFSET, /* OBX_SETPATH_RSP_EVT */ - OBX_RESPONSE_HDRS_OFFSET, /* OBX_ABORT_RSP_EVT */ - OBX_RESPONSE_HDRS_OFFSET /* OBX_ACTION_RSP_EVT */ -}; - -/******************************************************************************* -** -** Function obx_access_rsp_code -** -** Description This function is used to read/change response code -** -** Returns void. -** -*******************************************************************************/ -void obx_access_rsp_code(BT_HDR *p_pkt, UINT8 *p_rsp_code) -{ - UINT8 *p = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - if(*p_rsp_code == OBX_RSP_DEFAULT) - *p_rsp_code = *p; - else - *p = *p_rsp_code; -} - -/******************************************************************************* -** -** Function obx_adjust_packet_len -** -** Description Adjust the packet length in the OBEX packet -** -** Returns void. -** -*******************************************************************************/ -void obx_adjust_packet_len(BT_HDR *p_pkt) -{ - UINT8 *p = (UINT8 *)(p_pkt + 1) + p_pkt->offset + 1; - UINT16_TO_BE_STREAM(p, p_pkt->len); -} - -/******************************************************************************* -** -** Function obx_read_header_len -** -** Description ph is the beginning of an OBEX header -** -** Returns total length of the header -** -*******************************************************************************/ -UINT16 obx_read_header_len(UINT8 *ph) -{ - UINT16 len = 0; - - /* - OBX_TRACE_DEBUG1( "obx_read_header_len: 0x%x", *ph); - */ - switch(*ph&OBX_HI_TYPE_MASK) - { - case OBX_HI_TYPE_BYTE: - len = 2; - break; - case OBX_HI_TYPE_INT: - len = 5; - break; - case OBX_HI_TYPE_ARRAY: - case OBX_HI_TYPE_UNIC: - ph++; - BE_STREAM_TO_UINT16(len, ph); - break; - } - /* - OBX_TRACE_DEBUG1( "len:%d", len); - */ - return len; -} - -/******************************************************************************* -** -** Function obx_dup_pkt -** -** Description This function duplicate the OBEX message -** -** Returns BT_HDR *. -** -*******************************************************************************/ -BT_HDR * obx_dup_pkt(BT_HDR *p_pkt) -{ - BT_HDR *p_new; - UINT16 size = p_pkt->len + p_pkt->offset + BT_HDR_SIZE; - - if (size < GKI_MAX_BUF_SIZE) - { - /* Use the largest general pool to allow challenge tags appendage */ - p_new = (BT_HDR *)GKI_getbuf(GKI_MAX_BUF_SIZE); - } - else - { - p_new = (BT_HDR *) GKI_getpoolbuf(OBX_LRG_DATA_POOL_ID); - } - - if (p_new) - memcpy(p_new, p_pkt, size ); - - return p_new; -} - - -/******************************************************************************* -** -** Function OBX_HdrInit -** -** Description This function is called to initialize an OBEX packet. This -** function takes a GKI buffer and sets the offset in BT_HDR as -** OBX_HDR_OFFSET, the len as 0. The layer_specific is set to the -** length still available. This function compares the given -** (pkt_size - BT_HDR_SIZE) with the peer MTU to get the lesser -** of the two and set the layer_specific to -** (lesser_size - OBX_HDR_OFFSET). -** If composing a header for the CONNECT request (there is no -** client handle yet), use OBX_HANDLE_NULL as the handle. -** -** If the pkt_size is larger than the largest public pool size, -** GKI_MAX_BUF_SIZE, then an attempt to grab a buffer from the reserved OBX -** data pool will be made. -** Returns BT_HDR *. -** -*******************************************************************************/ -BT_HDR *OBX_HdrInit(tOBX_HANDLE handle, UINT16 pkt_size) -{ - UINT16 mtu = OBX_HandleToMtu(handle); - BT_HDR *p_pkt = NULL; - UINT16 buf_size; -#if (BT_USE_TRACES == TRUE) - UINT16 req_size = pkt_size; -#endif - - WC_ASSERT(pkt_size > (BT_HDR_SIZE + OBX_HDR_OFFSET)); - - pkt_size -= BT_HDR_SIZE; - if(pkt_size > mtu ) - pkt_size = mtu; - pkt_size += (BT_HDR_SIZE + OBX_HDR_OFFSET); - - OBX_TRACE_DEBUG4( "OBX_HdrInit: checking req_size %d, pkt_size:%d, max:%d, offset:%d", - req_size, pkt_size, GKI_MAX_BUF_SIZE, OBX_HDR_OFFSET); - /* See if packet will fit in regular public pool */ - if ((pkt_size) < GKI_MAX_BUF_SIZE) - { - p_pkt = (BT_HDR *) GKI_getbuf(pkt_size); - } - else /* Must use the reserved OBX buffer pool */ - { - p_pkt = (BT_HDR *) GKI_getpoolbuf(OBX_LRG_DATA_POOL_ID); - if (!p_pkt) - { - OBX_TRACE_DEBUG1( "Out of Large buffers. Trying pkt_size:%d", GKI_MAX_BUF_SIZE); - p_pkt = (BT_HDR *) GKI_getbuf(GKI_MAX_BUF_SIZE); - } - } - - if(p_pkt) - { - buf_size = GKI_get_buf_size(p_pkt); - buf_size -= BT_HDR_SIZE; - if(buf_size > mtu) - buf_size = mtu; - - OBX_TRACE_DEBUG4( "OBX_HdrInit: req_size %d, pkt_size = %d, gki_size %d, buf_size %d", - req_size, pkt_size, GKI_get_buf_size(p_pkt), buf_size); - - p_pkt->offset = OBX_HDR_OFFSET; - p_pkt->len = 0; - p_pkt->event = 0; - - /* layer specific contains remaining space in packet */ - p_pkt->layer_specific = buf_size - OBX_HDR_OFFSET ; - p_pkt->layer_specific -= 2; - - OBX_TRACE_DEBUG2( "buf size: %d, ls:%d", buf_size, p_pkt->layer_specific); - } - else - { - OBX_TRACE_ERROR1("OBX_HdrInit: No buffers for size (%d)", pkt_size); - } - - return p_pkt; -} - - -/******************************************************************************* -** -** Function OBX_Add1ByteHdr -** -** Description This function is called to add a header with type as UINT8 -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_Add1ByteHdr(BT_HDR *p_pkt, UINT8 id, UINT8 data) -{ - UINT8 *p; - BOOLEAN status = FALSE; - UINT16 size = 2; /* total length added by this header - 1/hi & 1/hv */ - - if(p_pkt) - { - p = (UINT8 *)(p_pkt+1)+p_pkt->offset+p_pkt->len; - /* verify that the HI is of correct type and the remaining length in the packet is good */ - if( ((id & OBX_HI_TYPE_MASK) == OBX_HI_TYPE_BYTE) && (p_pkt->layer_specific >= size) ) - { - *p++ = id; - *p++ = data; - - p_pkt->len += size; - p_pkt->layer_specific -= size; - status = TRUE; - } - } - - return status; -} - -/******************************************************************************* -** -** Function OBX_Add4ByteHdr -** -** Description This function is called to add a header with type as UINT32 -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_Add4ByteHdr(BT_HDR *p_pkt, UINT8 id, UINT32 data) -{ - UINT8 *p; - BOOLEAN status = FALSE; - UINT16 size = 5; /* total length added by this header - 1/hi & 4/hv */ - - if(p_pkt) - { - p = (UINT8 *)(p_pkt+1)+p_pkt->offset+p_pkt->len; - /* verify that the HI is of correct type and the remaining length in the packet is good */ - if( ((id & OBX_HI_TYPE_MASK) == OBX_HI_TYPE_INT) && (p_pkt->layer_specific >= size) ) - { - *p++ = id; - UINT32_TO_BE_STREAM(p, data); - - p_pkt->len += size; - p_pkt->layer_specific -= size; - status = TRUE; - } - } - - return status; -} - -/******************************************************************************* -** -** Function OBX_AddByteStrStart -** -** Description This function is called to get the address to the beginning of -** the byte sequence for an OBEX header in an OBEX packet. -** -** Returns The address to add the byte sequence. -** -*******************************************************************************/ -UINT8 *OBX_AddByteStrStart(BT_HDR *p_pkt, UINT16 *p_len) -{ - UINT8 *p = (UINT8 *)(p_pkt + 1) + p_pkt->offset + p_pkt->len + 3; - - WC_ASSERT(p_len); - - if(*p_len > (p_pkt->layer_specific - 3) || *p_len == 0) - *p_len = p_pkt->layer_specific - 3; - return p; -} - -/******************************************************************************* -** -** Function OBX_AddByteStrHdr -** -** Description This function is called to add a header with type as byte sequence -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddByteStrHdr(BT_HDR *p_pkt, UINT8 id, UINT8 *p_data, UINT16 len) -{ - UINT8 *p; - BOOLEAN status = FALSE; - UINT16 size = (len+3); /* total length added by this header - 1/hi & len+2/hv */ - - if(p_pkt) - { - p = (UINT8 *)(p_pkt+1)+p_pkt->offset+p_pkt->len; - /* verify that the HI is of correct type and the remaining length in the packet is good */ - if( ((id & OBX_HI_TYPE_MASK) == OBX_HI_TYPE_ARRAY) && (p_pkt->layer_specific >= size) ) - { - *p++ = id; - UINT16_TO_BE_STREAM(p, size); - if(p_data) - memcpy(p, p_data, len); - - p_pkt->len += size; - p_pkt->layer_specific -= size; - status = TRUE; - } - } - - return status; -} - -/******************************************************************************* -** -** Function OBX_AddUnicodeHdr -** -** Description This function is called to add a header with type as Unicode string -** to an OBEX packet. -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddUnicodeHdr(BT_HDR *p_pkt, UINT8 id, UINT16 *p_data, UINT16 len) -{ - UINT8 *p; - BOOLEAN status = FALSE; - UINT16 size, xx; - - if(p_pkt) - { - p = (UINT8 *)(p_pkt+1)+p_pkt->offset+p_pkt->len; - size = (len*OBX_UNICODE_SIZE + 3); /* total length added by this header - 1/hi & len*OBX_UNICODE_SIZE+2/hv */ - OBX_TRACE_DEBUG4( "OBX_AddUnicodeHdr len: %d, size: %d, left: %d, id: 0x%x", - len, size, p_pkt->layer_specific, id ); - - /* verify that the HI is of correct type and the remaining length in the packet is good */ - if( ((id & OBX_HI_TYPE_MASK) == OBX_HI_TYPE_UNIC) && (p_pkt->layer_specific >= size) ) - { - *p++ = id; - UINT16_TO_BE_STREAM(p, size); - for(xx=0; xx<len; xx++) - { - UINT16_TO_BE_STREAM(p, *p_data); - p_data++; - } - - p_pkt->len += size; - p_pkt->layer_specific -= size; - status = TRUE; - } - } - - return status; -} - -/* Alternate Body header functions: for non-blocking scenario */ -/******************************************************************************* -** -** Function OBX_AddBodyStart -** -** Description This function is called to get the address to the beginning of -** the byte sequence for an OBEX body header in an OBEX packet. -** -** Returns The address to add body content. -** -*******************************************************************************/ -UINT8 *OBX_AddBodyStart(BT_HDR *p_pkt, UINT16 *p_len) -{ - UINT8 *p = (UINT8 *)(p_pkt + 1) + p_pkt->offset + p_pkt->len + 3; - - WC_ASSERT(p_len); - - if(*p_len > (p_pkt->layer_specific - 3) || *p_len == 0) - *p_len = p_pkt->layer_specific - 3; - return p; -} - -/******************************************************************************* -** -** Function OBX_AddBodyEnd -** -** Description This function is called to add the HI and the length of HV of an -** OBEX body header to an OBEX packet. If end is TRUE, HI is -** OBX_HI_BODY_END. If FALSE, HI is OBX_HI_BODY. It is assumed that -** the actual value of the body has been copied into the OBEX packet. -** -** Returns void -** -*******************************************************************************/ -void OBX_AddBodyEnd(BT_HDR *p_pkt, UINT8 *p, UINT16 len, BOOLEAN end) -{ - UINT8 id = (end)?OBX_HI_BODY_END:OBX_HI_BODY; - UINT8 *pb = (UINT8 *)(p_pkt + 1) + p_pkt->offset + p_pkt->len; - *pb++ = id; - len += 3; /* 1/hi, 2/hv_len */ - UINT16_TO_BE_STREAM(pb, len); - p_pkt->layer_specific -= len; - p_pkt->len += len; -} - -/******************************************************************************* -** -** Function OBX_AddTriplet -** -** Description This function is called to add a header with type as byte sequence -** to an OBEX packet. -** -** Note: The byte sequence uses a Tag-Length-Value encoding scheme -** These headers include: Application Parameters header -** Authenticate Challenge header -** Authenticate Response header -** -** Returns TRUE, if the header is added successfully. -** FALSE, if the operation failed. p_pkt is not altered. -** -*******************************************************************************/ -BOOLEAN OBX_AddTriplet(BT_HDR *p_pkt, UINT8 id, tOBX_TRIPLET *p_triplet, UINT8 num) -{ - UINT8 *p = (UINT8 *)(p_pkt+1)+p_pkt->offset+p_pkt->len; - BOOLEAN status = FALSE; - UINT16 size = 3;/* 1/hi & len+2/hv */ - UINT8 xx; - - /* calculate the total length added by this header */ - for(xx=0; xx< num; xx++) - size += (p_triplet[xx].len + 2); - - /* verify that the HI is of correct type and the remaining length in the packet is good */ - if( ((id & OBX_HI_TYPE_MASK) == OBX_HI_TYPE_ARRAY) && (p_pkt->layer_specific >= size) ) - { - *p++ = id; - UINT16_TO_BE_STREAM(p, size); - for(xx=0; xx< num; xx++) - { - *p++ = p_triplet[xx].tag; - *p++ = p_triplet[xx].len; - memcpy(p, p_triplet[xx].p_array, p_triplet[xx].len); - p += p_triplet[xx].len; - } - p_pkt->len += size; - p_pkt->layer_specific -= size; - status = TRUE; - } - - return status; -} - - -/******************************************************************************* -** -** Function OBX_CheckNext -** -** Description This function is called to check if the given OBEX packet -** contains the specified header. -** -** Returns NULL, if the header is not in the OBEX packet. -** The pointer to the specified header beginning from HI. -** -*******************************************************************************/ -UINT8 * OBX_CheckNext(BT_HDR *p_pkt, UINT8 *p_start, UINT8 id) -{ - UINT8 *p; - UINT8 *p_res = NULL; - UINT16 len, start, skip; - int remain; - - if(p_pkt != NULL && p_start != NULL) - { - p = (UINT8 *)(p_pkt+1)+p_pkt->offset; - if(p_pkt->event <= OBX_MAX_OFFSET_IND) - { - start = obx_hdr_start_offset[p_pkt->event-1]; - p++; - BE_STREAM_TO_UINT16(len, p); - remain = len - start; - p = p - 3 + start; - - while(remain >0) - { - if(*p != id || p < p_start) - { - skip = obx_read_header_len(p); - p += skip; - /* Just in case this is a bad packet, make sure that remain is >= 0 */ - if(skip && (remain > skip)) - remain -= skip; - else - remain = 0; - } - else - { - p_res = p; - break; - } - } - } - } - - if (p_pkt) - { - OBX_TRACE_DEBUG2( "OBX_CheckNext: remain: %d len:%d", remain, p_pkt->len); - } - - return p_res; -} - - -/******************************************************************************* -** -** Function OBX_CheckHdr -** -** Description This function is called to check if the given OBEX packet -** contains the specified header. -** -** Returns NULL, if the header is not in the OBEX packet. -** The pointer to the specified header beginning from HI. -** -*******************************************************************************/ -UINT8 * OBX_CheckHdr(BT_HDR *p_pkt, UINT8 id) -{ - UINT8 *p; - UINT8 *p_res = NULL; - UINT16 len, start, skip; - int remain; - - if(p_pkt != NULL) - { - p = (UINT8 *)(p_pkt+1)+p_pkt->offset; - if(p_pkt->event <= OBX_MAX_OFFSET_IND) - { - start = obx_hdr_start_offset[p_pkt->event-1]; - p++; - BE_STREAM_TO_UINT16(len, p); - remain = len - start; - p = p - 3 + start; - - while(remain >0) - { - if(*p != id) - { - skip = obx_read_header_len(p); - p += skip; - /* Just in case this is a bad packet, make sure that remain is >= 0 */ - if(skip && (remain > skip)) - remain -= skip; - else - remain = 0; - } - else - { - p_res = p; - break; - } - } - } - } - - return p_res; -} - -/******************************************************************************* -** -** Function OBX_ReadNumHdrs -** -** Description This function is called to check the number of headers in the -** given OBEX packet -** -** Returns number of headers. -** -*******************************************************************************/ -UINT8 OBX_ReadNumHdrs(BT_HDR *p_pkt, UINT8 *p_num_body) -{ - UINT8 num_hdrs = 0, num_body = 0; - UINT8 *p; - UINT16 len, start, skip; - int remain = 0; - - if(p_pkt != NULL) - { - p = (UINT8 *)(p_pkt+1)+p_pkt->offset; - if(p_pkt->event == 0) - { - /* GKI buffer just went through OBX_HdrInit; not processed by the state machine yet */ - remain = len = p_pkt->len; - } - else if(p_pkt->event <= OBX_MAX_OFFSET_IND) - { - start = obx_hdr_start_offset[p_pkt->event-1]; - p++; - BE_STREAM_TO_UINT16(len, p); - remain = len - start; - p = p - 3 + start; - } - - while(remain >0) - { - num_hdrs++; - if(*p == OBX_HI_BODY || *p == OBX_HI_BODY_END) - num_body++; - - skip = obx_read_header_len(p); - p += skip; - /* Just in case this is a bad packet, make sure that remain is >= 0 */ - if(skip && (remain > skip)) - remain -= skip; - else - remain = 0; - - } - } - if (p_num_body) - *p_num_body = num_body; - return num_hdrs; -} - -/******************************************************************************* -** -** Function OBX_ReadHdrLen -** -** Description This function is called to check the length of the specified -** header in the given OBEX packet. -** -** Returns OBX_INVALID_HDR_LEN, if the header is not in the OBEX packet. -** Otherwise the actual length of the header. -** -*******************************************************************************/ -UINT16 OBX_ReadHdrLen(BT_HDR *p_pkt, UINT8 id) -{ - UINT8 *p; - UINT16 len = OBX_INVALID_HDR_LEN; - - if( (p = OBX_CheckHdr(p_pkt, id)) != NULL) - len = obx_read_header_len(p); - - return len; -} - -/******************************************************************************* -** -** Function OBX_Read1ByteHdr -** -** Description This function is called to get the UINT8 HV of the given HI -** in the given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_Read1ByteHdr(BT_HDR *p_pkt, UINT8 id, UINT8 *p_data) -{ - BOOLEAN status = FALSE; - UINT8 *p_start = OBX_CheckHdr(p_pkt, id); - - if(p_start) - { - *p_data = *(++p_start); - status = TRUE; - } - return status; -} - -/******************************************************************************* -** -** Function OBX_Read4ByteHdr -** -** Description This function is called to get the UINT32 HV of the given HI -** in the given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_Read4ByteHdr(BT_HDR *p_pkt, UINT8 id, UINT32 *p_data) -{ - BOOLEAN status = FALSE; - UINT8 *p_start = OBX_CheckHdr(p_pkt, id); - - if(p_start) - { - p_start++; - BE_STREAM_TO_UINT32(*p_data, p_start); - status = TRUE; - } - return status; -} - -/******************************************************************************* -** -** Function OBX_ReadByteStrHdr -** -** Description This function is called to get the byte sequence HV of the given -** HI in the given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadByteStrHdr(BT_HDR *p_pkt, UINT8 id, UINT8 **p_data, UINT16 *p_len, UINT8 next) -{ - BOOLEAN status = FALSE; - UINT8 *p_start = OBX_CheckHdr(p_pkt, id); - - if(p_start) - { - next += 1; - while(next && (id == *p_start++)) - { - next--; - BE_STREAM_TO_UINT16(*p_len, p_start); - if(next == 0) - { - status = TRUE; - *p_len -= 3; /* get rid of hi and hv_len */ - *p_data = p_start; - } - else - p_start = p_start + *p_len - 3; - } - } - else - { - *p_len = 0; - } - return status; -} - -/******************************************************************************* -** -** Function OBX_ReadUnicodeHdr -** -** Description This function is called to get the Unicode HV of the given -** HI in the given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadUnicodeHdr(BT_HDR *p_pkt, UINT8 id, UINT16 *p_data, UINT16 *p_len) -{ - BOOLEAN status = FALSE; - UINT16 len, xx, max_len; - UINT8 *p_start = OBX_CheckHdr(p_pkt, id); - - if(p_start) - { - max_len = *p_len; - p_start++; /* 1/hi*/ - BE_STREAM_TO_UINT16(len, p_start); - len -= 3; /* 1/hi, 2/hv_len */ - len /= OBX_UNICODE_SIZE; /* size in UINT16 */ - /* only conver the provided size */ - if( len > max_len) - len = max_len; - for(xx=0; xx<len; xx++) - { - BE_STREAM_TO_UINT16(*p_data, p_start); - p_data++; - } - *p_len = len; - status = TRUE; - max_len -= len; - while ( (p_start = OBX_CheckNext(p_pkt, p_start, id)) != NULL && (max_len > 0)) - { - p_start++; /* 1/hi*/ - BE_STREAM_TO_UINT16(len, p_start); - len -= 3; /* 1/hi, 2/hv_len */ - len /= OBX_UNICODE_SIZE; /* size in UINT16 */ - /* only conver the provided size */ - if( len > max_len) - len = max_len; - for(xx=0; xx<len; xx++) - { - BE_STREAM_TO_UINT16(*p_data, p_start); - p_data++; - } - *p_len += len; - max_len -= len; - } - } - else - { - *p_len = 0; - } - return status; -} - -/******************************************************************************* -** -** Function OBX_ReadTriplet -** -** Description This function is called to get the Triplet HV of the given -** HI in the given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadTriplet(BT_HDR *p_pkt, UINT8 id, tOBX_TRIPLET *p_triplet, UINT8 *p_num) -{ - BOOLEAN status = FALSE; - UINT8 *p_start = OBX_CheckHdr(p_pkt, id); - UINT16 len; - UINT8 count = 0; - - if(p_start) - { - p_start++; /* 1/hi*/ - BE_STREAM_TO_UINT16(len, p_start); - len -= 3; /* 1/hi, 2/hv_len */ - while(len && *p_num > count) - { - p_triplet[count].tag = *p_start++; - p_triplet[count].len = *p_start++; - OBX_TRACE_DEBUG3( "OBX_ReadTriplet: count: %d, tag: %x, len: %d", - count, p_triplet[count].tag, p_triplet[count].len); - p_triplet[count].p_array = p_start; - p_start += p_triplet[count].len; - if(len > (p_triplet[count].len + 2) ) - len -= (p_triplet[count].len + 2); - else - len = 0; - count++; - } - status = TRUE; - } - *p_num = count; - return status; -} - -/******************************************************************************* -** -** Function OBX_ReadActionIdHdr -** -** Description This function is called to get the HV of the Action ID header -** in the given OBEX packet. -** -** Returns TRUE, if the header is in the OBEX packet. -** FALSE, otherwise. -** -*******************************************************************************/ -BOOLEAN OBX_ReadActionIdHdr(BT_HDR *p_pkt, UINT8 *p_data) -{ - BOOLEAN status = FALSE; - UINT8 *p_start = OBX_CheckHdr(p_pkt, OBX_HI_ACTION_ID); - - if(p_start) - { - p_start++; - /* check for valid values: 0-2 */ - /* do not allow 0x80 - 0xFF (vendor extention) for now. */ - if (*p_start <= OBX_ACT_PERMISSION) - { - *p_data = *(p_start); - status = TRUE; - } - } - return status; -} diff --git a/stack/obx/hdrs/obx_wchar.c b/stack/obx/hdrs/obx_wchar.c deleted file mode 100644 index 5364210..0000000 --- a/stack/obx/hdrs/obx_wchar.c +++ /dev/null @@ -1,84 +0,0 @@ -/***************************************************************************** -** -** Name: obx_wchar.c -** -** File: OBEX Headers Encode conversion Utility functions -** -** Copyright (c) 2003-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "gki.h" -#include "obx_api.h" - -/******************************************************************************* -** -** Function OBX_CharToWchar -** -** Description This function is called to convert ASCII to Unicode (UINT16). -** -** Returns the length. -** -*******************************************************************************/ -UINT16 OBX_CharToWchar (UINT16 *w_str, char* a_str, UINT16 w_size) -{ - UINT16 result = 0; - int size = w_size; - - if (a_str == NULL || w_str == NULL) - return 0; - - while (size > 0 && *a_str != '\0') - { - w_str[result++] = (UINT16) *a_str; - a_str++; - size--; - } - - if (size > 0) - { - w_str[result] = 0; - } - - return (result+1); -} - -/******************************************************************************* -** -** Function OBX_WcharToChar -** -** Description This function is called to convert Unicode (UINT16) to ASCII. -** -** Returns void. -** -*******************************************************************************/ -void OBX_WcharToChar (char *a_str, UINT16* w_str, UINT16 a_size) -{ - UINT16 result = 0; - int size = a_size; - - if (w_str == NULL || a_str == NULL) - return; - - while (size > 0 && *w_str != 0) - { - if ((*w_str & ~0xff) != 0) - { - result = 0; - break; - } - - a_str[result++] = (char) *w_str; - ++(w_str); - --size; - } - - if(size) - a_str[result] = 0; - - return; - - -} - diff --git a/stack/obx/hdrs/utfc.c b/stack/obx/hdrs/utfc.c deleted file mode 100644 index d59733d..0000000 --- a/stack/obx/hdrs/utfc.c +++ /dev/null @@ -1,245 +0,0 @@ -/***************************************************************************** -** -** Name: utfc.c -** -** Description: UTF conversion utilities. -** -** Copyright (c) 2003-2004, WIDCOMM Inc., All Rights Reserved. -** -*****************************************************************************/ - -#include <string.h> -#include "bt_target.h" -#include "utfc.h" - -/* Based on code from Unicode, Inc: - * - * Copyright 2001-2003 Unicode, Inc. - * - * Limitations on Rights to Redistribute This Code - * - * Unicode, Inc. hereby grants the right to freely use the information - * supplied in this file in the creation of products supporting the - * Unicode Standard, and to make copies of this file in any form - * for internal or external distribution as long as this notice - * remains attached. - */ - -/******************************************************************************* -** Constants -*******************************************************************************/ - -#define UTFC_8_MASK 0xBF -#define UTFC_8_MARK 0x80 - -#define UTFC_SUR_HIGH_START 0xD800 -#define UTFC_SUR_HIGH_END 0xDBFF -#define UTFC_SUR_LOW_START 0xDC00 -#define UTFC_SUR_LOW_END 0xDFFF - -/* Lookup table for length of UTF-8 byte sequence based on upper four bits -** of first byte. Illegal values give length zero. -*/ -static const UINT8 utfc_8_seq_len[] = {1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 2, 2, 3, 4}; - -/* Magic values subtracted from a buffer value during UTF-8 conversion. -** This table contains as many values as there might be trailing bytes -** in a UTF-8 sequence. -**/ -static const UINT32 utfc_8_offset[] = {0x00000000, 0x00003080, - 0x000E2080, 0x03C82080}; - -static const UINT8 utfc_8_first_byte[] = {0x00, 0x00, 0xC0, 0xE0, 0xF0}; - -/******************************************************************************* -** -** Function utfc_16_to_8 -** -** Description Convert a UTF-16 array to a null-terminated UTF-8 string. -** Illegal characters are skipped. -** -** Returns Length of UTF-8 string in bytes. -** -*******************************************************************************/ -UINT16 utfc_16_to_8(UINT8 *p_utf8, UINT16 utf8_len, UINT16 *p_utf16, UINT16 utf16_len) -{ - UINT32 ch, ch2; - UINT16 len = 0; - UINT8 seq_len; - - /* sanity check destination buffer len */ - if (utf8_len == 0) - { - /* set null */ - *p_utf8 = 0; - return len; - } - - /* save space for null */ - utf8_len--; - - while (utf16_len-- > 0) - { - ch = (UINT32) *p_utf16++; - - /* if we have a surrogate pair, convert to UTF-32 first */ - if (ch >= UTFC_SUR_HIGH_START && ch <= UTFC_SUR_HIGH_END) - { - /* if not enough characters we're done */ - if (utf16_len == 0) - { - break; - } - - /* get next character */ - ch2 = *p_utf16++; - utf16_len--; - - /* if it's a low surrogate, convert to UTF-32 */ - if (ch2 >= UTFC_SUR_LOW_START && ch2 <= UTFC_SUR_LOW_END) - { - ch = ((ch - UTFC_SUR_HIGH_START) << 10) + - (ch2 - UTFC_SUR_LOW_START) + 0x00010000; - } - else - { - /* illegal UTF-16 sequence, skip it */ - continue; - } - } - - /* Figure out how many bytes the result will require */ - if (ch < 0x00000080) - seq_len = 1; - else if (ch < 0x00000800) - seq_len = 2; - else if (ch < 0x00010000) - seq_len = 3; - else - seq_len = 4; - - /* if sequence doesn't fit we're done */ - if (utf8_len < len + seq_len) - { - break; - } - - /* build UTF-8 sequence */ - switch (seq_len) - { /* note: everything falls through. */ - case 4: p_utf8[3] = (UINT8) ((ch | UTFC_8_MARK) & UTFC_8_MASK); ch >>= 6; - case 3: p_utf8[2] = (UINT8) ((ch | UTFC_8_MARK) & UTFC_8_MASK); ch >>= 6; - case 2: p_utf8[1] = (UINT8) ((ch | UTFC_8_MARK) & UTFC_8_MASK); ch >>= 6; - case 1: p_utf8[0] = (UINT8) (ch | utfc_8_first_byte[seq_len]); - } - - /* converted value is a null we're done */ - if (*p_utf8 == 0) - { - break; - } - - p_utf8 += seq_len; - len += seq_len; - } - - /* set null */ - *p_utf8 = 0; - - return len; -} - -/******************************************************************************* -** -** Function utfc_8_to_16 -** -** Description Convert a null-terminated UTF-8 string to a UTF-16 array. -** Illegal characters are skipped. The UTF-16 array is -** appended with a zero (null) character. -** -** Returns Length of UTF-16 array including null character. -** -*******************************************************************************/ -UINT16 utfc_8_to_16(UINT16 *p_utf16, UINT16 utf16_len, UINT8 *p_utf8) -{ - UINT32 ch; - UINT8 *p_end; - UINT16 *p; - UINT8 seq_len; - - /* sanity check destination buffer len */ - if (utf16_len == 0) - { - *p_utf16 = 0; - return 0; - } - - /* save space for null */ - utf16_len--; - - p = p_utf16; - p_end = (UINT8 *) p_utf8 + strlen((char *) p_utf8); - - while (*p_utf8) - { - /* get sequence length; skip if illegal */ - if ((seq_len = utfc_8_seq_len[*p_utf8 >> 4]) == 0) - { - p_utf8++; - continue; - } - - /* make sure sequence doesn't extend past end of UTF-8 buffer */ - if (p_utf8 + seq_len > p_end) - { - break; - } - - /* construct UTF-32 character from sequence */ - ch = 0; - switch (seq_len) - { /* note: everything falls through. */ - case 4: ch += *p_utf8++; ch <<= 6; - case 3: ch += *p_utf8++; ch <<= 6; - case 2: ch += *p_utf8++; ch <<= 6; - case 1: ch += *p_utf8++; - } - ch -= utfc_8_offset[seq_len - 1]; - - if (ch <= 0x0000FFFF) - { - /* UTF-16 surrogate values are illegal in UTF-32 */ - if (ch >= UTFC_SUR_HIGH_START && ch <= UTFC_SUR_LOW_END) - { - continue; - } - - /* make sure fits */ - if (p - p_utf16 == utf16_len) - { - break; - } - - *p++ = (UINT16) ch; - } - else if (ch < 0x0010FFFF) - { - /* make sure fits */ - if ((p - p_utf16) == (utf16_len - 1)) - { - break; - } - - ch -= 0x00010000; - *p++ = (UINT16) ((ch >> 10) + UTFC_SUR_HIGH_START); - *p++ = (UINT16) ((ch & 0x000003FF) + UTFC_SUR_LOW_START); - } - } - - /* set null */ - *p++ = 0; - - return (UINT16) (p - p_utf16); -} - diff --git a/stack/obx/obx_cact.c b/stack/obx/obx_cact.c deleted file mode 100644 index 62998bd..0000000 --- a/stack/obx/obx_cact.c +++ /dev/null @@ -1,1103 +0,0 @@ -/***************************************************************************** -** -** Name: obx_cact.c -** -** File: OBEX Client State Machine Action Functions -** -** Copyright (c) 2003-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include "bt_target.h" -#include "obx_int.h" -#include "btm_api.h" - -const tOBX_EVENT obx_cl_state_2_event_map[] = -{ - OBX_DISCONNECT_RSP_EVT, /* OBX_CS_NOT_CONNECTED */ - OBX_SESSION_RSP_EVT, /* OBX_CS_SESSION_REQ_SENT */ - OBX_CONNECT_RSP_EVT, /* OBX_CS_CONNECT_REQ_SENT */ - OBX_NULL_EVT, /* OBX_CS_UNAUTH */ - OBX_ABORT_RSP_EVT, /* OBX_CS_CONNECTED */ - OBX_DISCONNECT_RSP_EVT, /* OBX_CS_DISCNT_REQ_SENT */ - OBX_NULL_EVT, /* OBX_CS_OP_UNAUTH */ - OBX_SETPATH_RSP_EVT, /* OBX_CS_SETPATH_REQ_SENT */ - OBX_ACTION_RSP_EVT, /* OBX_CS_ACTION_REQ_SENT */ - OBX_ABORT_RSP_EVT, /* OBX_CS_ABORT_REQ_SENT */ - OBX_PUT_RSP_EVT, /* OBX_CS_PUT_REQ_SENT */ - OBX_GET_RSP_EVT, /* OBX_CS_GET_REQ_SENT */ - OBX_PUT_RSP_EVT, /* OBX_CS_PUT_TRANSACTION */ - OBX_GET_RSP_EVT, /* OBX_CS_GET_TRANSACTION */ - OBX_PUT_RSP_EVT, /* OBX_CS_PUT_SRM */ - OBX_GET_RSP_EVT /* OBX_CS_GET_SRM */ -}; - -/******************************************************************************* -** Function obx_ca_close_sess_req -** Description send close session request -*******************************************************************************/ -BT_HDR * obx_ca_close_sess_req(tOBX_CL_CB *p_cb) -{ - BT_HDR *p_req; - UINT8 *p; - UINT8 num_trip = 0; - tOBX_TRIPLET triplet[4]; - UINT8 data[2]; - - p_req = OBX_HdrInit(OBX_HANDLE_NULL, OBX_MIN_MTU); - p = (UINT8 *) (p_req + 1) + p_req->offset; - /* Session request packet always has the final bit set */ - *p++ = (OBX_REQ_SESSION | OBX_FINAL); - p_req->len = 3; - p = data; - - /* add session opcode */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_SESS_OP; - triplet[num_trip].len = OBX_LEN_SESS_PARAM_SESS_OP; - triplet[num_trip].p_array = p; - *p = OBX_SESS_OP_CLOSE; - p += OBX_LEN_SESS_PARAM_SESS_OP; - num_trip++; - - /* add session id */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_SESS_ID; - triplet[num_trip].len = OBX_SESSION_ID_SIZE; - triplet[num_trip].p_array = p_cb->sess_info; - num_trip++; - - OBX_AddTriplet(p_req, OBX_HI_SESSION_PARAM, triplet, num_trip); - /* adjust the packet len */ - p = (UINT8 *) (p_req + 1) + p_req->offset + 1; - UINT16_TO_BE_STREAM(p, p_req->len); - p_req->event = OBX_SESSION_REQ_EVT; - p_cb->sess_st = OBX_SESS_CLOSE; - OBX_TRACE_DEBUG2("obx_ca_close_sess_req shandle:0x%x, sess_st:%d", p_cb->ll_cb.comm.handle, p_cb->sess_st); - return p_req; -} - -/******************************************************************************* -** Function obx_ca_connect_req -** Description send connect request -*******************************************************************************/ -void obx_ca_connect_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - UINT8 msg[OBX_HDR_OFFSET + OBX_MAX_CONN_HDR_EXTRA]; - UINT8 *p = msg; - - /* Connect request packet always has the final bit set */ - *p++ = (OBX_REQ_CONNECT | OBX_FINAL); - p += OBX_PKT_LEN_SIZE; - - *p++ = OBX_VERSION; - *p++ = OBX_CONN_FLAGS; - UINT16_TO_BE_STREAM(p, p_cb->ll_cb.port.rx_mtu); - - /* add session sequence number, if session is active */ - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - *p++ = OBX_HI_SESSION_SN; - *p++ = p_cb->ssn; - } - if (p_cb->srm) - { - p_cb->srm = OBX_SRM_ENABLE; - } - - /* IrOBEX spec forbids connection ID in Connect Request */ - p_pkt = obx_cl_prepend_msg(p_cb, p_pkt, msg, (UINT16)(p - msg) ); - - p_pkt->event = OBX_CONNECT_REQ_EVT; - obx_csm_event(p_cb, OBX_CONNECT_REQ_CEVT, p_pkt); -} - -/******************************************************************************* -** Function obx_ca_state -** Description change state -*******************************************************************************/ -tOBX_CL_STATE obx_ca_state(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - /* p_pkt should be NULL here */ - return p_cb->next_state; -} - -/******************************************************************************* -** Function obx_ca_start_timer -** Description start timer -*******************************************************************************/ -tOBX_CL_STATE obx_ca_start_timer(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - if (p_pkt) - GKI_freebuf(p_pkt); - obx_start_timer(&p_cb->ll_cb.comm); - return OBX_CS_NULL; -} - -/******************************************************************************* -** Function obx_ca_connect_ok -** Description process the connect OK response from server -*******************************************************************************/ -tOBX_CL_STATE obx_ca_connect_ok(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - UINT8 *p; - tOBX_EVT_PARAM param; /* The event parameter. */ - - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - /* reliable session was established - need to report the session event first */ - p = &p_cb->sess_info[OBX_SESSION_INFO_ID_IDX]; - UINT32_TO_BE_STREAM(p, p_cb->conn_id); - param.sess.p_sess_info= p_cb->sess_info; - param.sess.sess_st = p_cb->sess_st; - param.sess.nssn = p_cb->ssn; - param.sess.obj_offset = 0; - p = &p_cb->sess_info[OBX_SESSION_INFO_MTU_IDX]; - UINT16_TO_BE_STREAM(p, p_cb->param.conn.mtu); - param.sess.sess_op = OBX_SESS_OP_CREATE; - (*p_cb->p_cback)(p_cb->ll_cb.comm.handle, OBX_SESSION_RSP_EVT, p_cb->rsp_code, param, NULL); - } - return obx_ca_notify(p_cb, p_pkt); -} - -/******************************************************************************* -** Function obx_ca_session_ok -** Description process the session OK response from server -*******************************************************************************/ -tOBX_CL_STATE obx_ca_session_ok(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_TRIPLET triplet[OBX_MAX_SESS_PARAM_TRIP]; - UINT8 num = OBX_MAX_SESS_PARAM_TRIP; - UINT8 *p_nonce = NULL, *p_addr = NULL, *p_sess_id = NULL; - UINT8 *p, *p_cl_nonce; - UINT8 ind, nonce_len = 0; - UINT8 ind_sess_id; - BD_ADDR cl_addr; - tOBX_STATUS status = OBX_SUCCESS; - UINT8 nssn; -#if (BT_USE_TRACES == TRUE) - tOBX_SESS_ST old_sess_st = p_cb->sess_st; -#endif - tOBX_SESS_OP sess_op = OBX_SESS_OP_SET_TIME; - tOBX_CL_STATE new_state = OBX_CS_NULL; - tOBX_CL_EVENT sm_evt = OBX_BAD_SM_EVT; - UINT32 obj_offset = p_cb->param.sess.obj_offset; - UINT32 timeout = p_cb->param.sess.timeout; - tOBX_EVT_PARAM param; /* The event parameter. */ - UINT8 dropped = 0; - - OBX_TRACE_DEBUG4("obx_ca_session_ok sess_st: %d ssn:%d obj_offset:%d prev_state:%d", p_cb->sess_st, p_cb->ssn, obj_offset, p_cb->prev_state); - OBX_ReadTriplet(p_pkt, OBX_HI_SESSION_PARAM, triplet, &num); - obx_read_timeout (triplet, num, &timeout, &p_cb->sess_info[OBX_SESSION_INFO_TO_IDX]); - p_cb->param.sess.timeout = timeout; - if (p_cb->sess_st == OBX_SESS_SUSPEND) - { - p_cb->sess_st = OBX_SESS_SUSPENDED; - sess_op = OBX_SESS_OP_SUSPEND; - p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX] = p_cb->srm; - nssn = p_cb->ssn; - /* send a tx_empty event to close port */ - sm_evt = OBX_TX_EMPTY_CEVT; - OBX_TRACE_DEBUG2("suspend saved st:%d, srm:0x%x", p_cb->sess_info[OBX_SESSION_INFO_ST_IDX], p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX]); - } - else if (p_cb->sess_st == OBX_SESS_CLOSE) - { - sess_op = OBX_SESS_OP_CLOSE; - p_cb->sess_st = OBX_SESS_NONE; - /* send a tx_empty event to close port */ - sm_evt = OBX_TX_EMPTY_CEVT; - } - else if (num) - { - ind_sess_id = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_SESS_ID); - if ((ind_sess_id != num) && (triplet[ind_sess_id].len == OBX_SESSION_ID_SIZE)) - { - p_sess_id = triplet[ind_sess_id].p_array; - } - switch (p_cb->sess_st) - { - case OBX_SESS_CREATE: - sess_op = OBX_SESS_OP_CREATE; - status = OBX_BAD_PARAMS; - ind = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_ADDR); - if ((ind != num) && (triplet[ind].len == BD_ADDR_LEN)) - { - p_addr = triplet[ind].p_array; - } - ind = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_NONCE); - if ((ind != num) && (triplet[ind].len >= OBX_MIN_NONCE_SIZE) && (triplet[ind].len <= OBX_NONCE_SIZE)) - { - p_nonce = triplet[ind].p_array; - nonce_len = triplet[ind].len; - } - - if (p_nonce && p_addr && p_sess_id) - { - OBX_TRACE_DEBUG0("verify session id"); - BTM_GetLocalDeviceAddr (cl_addr); - p_cl_nonce = &p_cb->sess_info[OBX_SESSION_ID_SIZE]; - p = p_cl_nonce; - UINT32_TO_BE_STREAM(p, p_cb->nonce); - /* calculate client copy of session id */ - obx_session_id (p_cb->sess_info, cl_addr, p_cl_nonce, OBX_LOCAL_NONCE_SIZE, p_addr, p_nonce, nonce_len); - obxu_dump_hex (p_cb->sess_info, "cl sess id", OBX_SESSION_ID_SIZE); - obxu_dump_hex (p_sess_id, "sr sess id", OBX_SESSION_ID_SIZE); - /* verify that the server copy is the same */ - if (memcmp (p_sess_id, p_cb->sess_info, OBX_SESSION_ID_SIZE) == 0) - { - p_cb->sess_st = OBX_SESS_ACTIVE; - p_cb->ssn = 0; - /* do we want a timer here */ - status = OBX_SUCCESS; - OBX_TRACE_DEBUG0("freeing received packet"); - GKI_freebuf (p_pkt) ; - p_pkt = p_cb->p_next_req; - p_cb->p_next_req = NULL; - obx_ca_connect_req (p_cb, p_pkt); - /* - p_cb->param.sess.p_sess_info= p_cb->sess_info; - p_cb->param.sess.sess_st = p_cb->sess_st; - p_cb->param.sess.nssn = p_cb->ssn; - p_cb->param.sess.sess_op = sess_op; - (*p_cb->p_cback)(p_cb->ll_cb.comm.handle, OBX_SESSION_RSP_EVT, p_cb->rsp_code, p_cb->param, NULL); - */ - return new_state; - } - } - break; - - case OBX_SESS_RESUME: - status = OBX_BAD_PARAMS; - dropped = p_cb->sess_info[OBX_SESSION_INFO_ST_IDX] & OBX_CL_STATE_DROP; - ind = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_NSEQNUM); - if ((ind == num) || (triplet[ind].len != 1)) - { - OBX_TRACE_ERROR0("RESUME:do not have valid NSSN tag"); - break; - } - - nssn = *(triplet[ind].p_array); - /* if SRM is enaged; make sure object offset TAG exists */ - if ((p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX] & OBX_SRM_ENGAGE) != 0) - { - obj_offset = obx_read_obj_offset(triplet, num); - OBX_TRACE_DEBUG2("RESUME:SRM is engaged and object offset:0x%x (0x%x)", - obj_offset, p_cb->param.sess.obj_offset); - - /* client always takes the offset and ssn from the response since adjustment was done at server side */ - p_cb->param.sess.obj_offset = obj_offset; - p_cb->ssn = nssn; - status = OBX_SUCCESS; - } - /* otherwise make sure NSSN from server is OK */ - else if (nssn == p_cb->ssn) - { - OBX_TRACE_DEBUG0("RESUME:nssn matches expected ssn"); - status = OBX_SUCCESS; - } - else if (dropped != 0) - { - OBX_TRACE_DEBUG2("RESUME:link drop suspend nssn:%d cb ssn:%d", nssn, p_cb->ssn); - if ((UINT8)(nssn+1) == p_cb->ssn) - { - OBX_TRACE_DEBUG0("RESUME:nssn matches expected(ssn-1)"); - p_cb->ssn -= 1; - status = OBX_SUCCESS; - } - else if (nssn == (UINT8)(p_cb->ssn+1)) - { - OBX_TRACE_DEBUG0("RESUME:nssn matches expected(ssn+1)"); - nssn -= 1; - status = OBX_SUCCESS; - } - } - else - { - OBX_TRACE_ERROR2("RESUME:bad NSSN:%d (%d)", nssn, p_cb->ssn); - break; - } - p_cb->sess_st = OBX_SESS_ACTIVE; - sess_op = OBX_SESS_OP_RESUME; - OBX_TRACE_DEBUG2("RESUME:info new_state:0x%x, srm:0x%x", p_cb->sess_info[OBX_SESSION_INFO_ST_IDX], p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX]); - p_cb->srm = p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX]; - p_cb->sess_info[OBX_SESSION_INFO_ST_IDX] &= ~OBX_CL_STATE_DROP; - if (p_cb->srm & OBX_SRM_ENGAGE) - { - new_state = p_cb->sess_info[OBX_SESSION_INFO_ST_IDX]; - if (new_state == OBX_CS_GET_SRM) - { - p_cb->srm |= OBX_SRM_WAIT_UL; - /* Adjust snn in the control block since it is off by one with nssn in resume request */ - p_cb->ssn--; - } - } - else - { - new_state = OBX_CS_CONNECTED; - p_cb->srmp |= OBX_SRMP_SESS_FST; - } - OBX_TRACE_DEBUG2("RESUME:new_state:%d, srm:0x%x", new_state, p_cb->srm); - break; - - default: - status = OBX_BAD_PARAMS; - } - } - else - { - status = OBX_BAD_PARAMS; - } - OBX_TRACE_DEBUG5("obx_ca_session_ok prev:%d, sess_st:%d->%d obj_offset:%d status:%d", p_cb->prev_state, old_sess_st, p_cb->sess_st, obj_offset, status); - - if (sess_op == OBX_SESS_OP_SET_TIME) - new_state = p_cb->prev_state; - - if (status != OBX_SUCCESS) - { - if (p_cb->sess_st == OBX_SESS_CLOSE) - p_cb->sess_st = OBX_SESS_NONE; - obx_csm_event(p_cb, OBX_TIMEOUT_CEVT, NULL); - return OBX_CS_NULL; - } - p_cb->param.sess.p_sess_info= p_cb->sess_info; - p_cb->param.sess.sess_st = p_cb->sess_st; - p_cb->param.sess.nssn = nssn; - p_cb->param.sess.ssn = nssn; - p_cb->param.sess.sess_op = sess_op; - p_cb->param.sess.obj_offset = obj_offset; - p_cb->param.sess.timeout = timeout; - (*p_cb->p_cback)(p_cb->ll_cb.comm.handle, OBX_SESSION_RSP_EVT, p_cb->rsp_code, p_cb->param, NULL); - - if ((sess_op == OBX_SESS_OP_RESUME) && (p_cb->sess_st == OBX_SESS_ACTIVE)) - { - param.conn.ssn = p_cb->ssn; - memcpy (param.conn.peer_addr, p_cb->peer_addr, BD_ADDR_LEN); - p = &p_cb->sess_info[OBX_SESSION_INFO_MTU_IDX]; - BE_STREAM_TO_UINT16(param.conn.mtu, p); - p_cb->ll_cb.comm.tx_mtu = param.conn.mtu; - param.conn.handle = p_cb->ll_cb.comm.handle; - OBX_TRACE_DEBUG1("RESUME: tx_mtu: %d", p_cb->ll_cb.comm.tx_mtu); - /* report OBX_CONNECT_RSP_EVT to let the client know the MTU */ - (*p_cb->p_cback)(p_cb->ll_cb.comm.handle, OBX_CONNECT_RSP_EVT, OBX_RSP_OK, param, NULL); - sm_evt = OBX_STATE_CEVT; - p_cb->next_state = OBX_CS_CONNECTED; - } - - if (sm_evt != OBX_BAD_SM_EVT) - { - /* send an event to csm */ - obx_csm_event(p_cb, sm_evt, NULL); - } - return new_state; -} - -/******************************************************************************* -** Function obx_ca_session_cont -** Description process the continue response from server for SRM after -** a suspend session request is sent -*******************************************************************************/ -tOBX_CL_STATE obx_ca_session_cont(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - BOOLEAN free = TRUE; - - OBX_TRACE_DEBUG3("obx_ca_session_cont sess_st:%d prev_state:%d, srm:0x%x", p_cb->sess_st, p_cb->prev_state, p_cb->srm); - if (p_cb->sess_st == OBX_SESS_SUSPEND) - { - if (p_cb->prev_state == OBX_CS_GET_SRM) - { - if ((p_cb->srm & OBX_SRM_WAIT_UL) == 0) - { - p_cb->srm |= OBX_SRM_WAIT_UL; - p_cb->api_evt = OBX_GET_RSP_EVT; - } - else - { - GKI_enqueue_head (&p_cb->ll_cb.comm.rx_q, p_pkt); - OBX_TRACE_DEBUG1("obx_ca_session_cont rx_q.count:%d", p_cb->ll_cb.comm.rx_q.count); - } - free = FALSE; - } - else if (p_cb->prev_state == OBX_CS_GET_REQ_SENT) - { - p_cb->api_evt = OBX_GET_RSP_EVT; - free = FALSE; - } - - } - if (free && p_pkt) - GKI_freebuf(p_pkt); - OBX_TRACE_DEBUG1("obx_ca_session_cont srm: 0x%x(e)", p_cb->srm ); - return OBX_CS_NULL; -} - -/******************************************************************************* -** Function obx_ca_session_get -** Description process the get req api for SRM after -** a suspend session request is sent (to clean out the received buffers) -*******************************************************************************/ -tOBX_CL_STATE obx_ca_session_get(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - OBX_TRACE_DEBUG3("obx_ca_session_get sess_st:%d prev_state: %d, srm:0x%x", p_cb->sess_st, p_cb->prev_state, p_cb->srm ); - if (p_cb->sess_st == OBX_SESS_SUSPEND && p_cb->prev_state == OBX_CS_GET_SRM) - return obx_ca_srm_get_req(p_cb, p_pkt); - return OBX_CS_NULL; -} - -/******************************************************************************* -** Function obx_ca_session_fail -** Description process the session failed response from server -*******************************************************************************/ -tOBX_CL_STATE obx_ca_session_fail(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SESS_ST old_sess_st = p_cb->sess_st; - - p_cb->sess_st = OBX_SESS_NONE; - OBX_TRACE_DEBUG2("obx_ca_session_fail, sess_st:%d->%d", old_sess_st, p_cb->sess_st); - if (old_sess_st == OBX_SESS_CREATE && p_cb->rsp_code != OBX_RSP_OK) - { - /* peer device does not support session. Continue with regular session */ - /* report session failure */ - (*p_cb->p_cback)(p_cb->ll_cb.comm.handle, OBX_SESSION_RSP_EVT, p_cb->rsp_code, p_cb->param, NULL); - OBX_TRACE_DEBUG0("freeing received packet"); - if (p_pkt) - GKI_freebuf (p_pkt) ; - p_pkt = p_cb->p_next_req; - p_cb->p_next_req = NULL; - obx_ca_connect_req (p_cb, p_pkt); - } - else - { - (*p_cb->p_cback)(p_cb->ll_cb.comm.handle, OBX_SESSION_RSP_EVT, OBX_RSP_FAILED, p_cb->param, NULL); - obx_ca_close_port (p_cb, p_pkt); - } - return OBX_CS_NULL; -} - -/******************************************************************************* -** Function obx_ca_abort -** Description process the abort request in connected state -*******************************************************************************/ -tOBX_CL_STATE obx_ca_abort(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - OBX_TRACE_DEBUG2("obx_ca_abort srm:0x%x srmp:0x%x", p_cb->srm, p_cb->srmp); - if ( p_cb->srmp & OBX_SRMP_SESS_FST) - { - /* the first request after a session is resume. - * We may need to abort the previous request */ - if (p_cb->sess_info[OBX_SESSION_INFO_ST_IDX] != OBX_CS_CONNECTED) - { - /* set the state here, just in case the result of obx_ca_snd_req is partial_sent */ - p_cb->state = OBX_CS_ABORT_REQ_SENT; - obx_ca_snd_req(p_cb, p_pkt); - return OBX_CS_NULL; - } - p_cb->srmp &= ~OBX_SRMP_SESS_FST; - } - obx_ca_notify (p_cb, p_pkt); - return OBX_CS_NULL; -} - -/******************************************************************************* -** Function obx_ca_snd_put_req -** Description send put request in connected state -*******************************************************************************/ -tOBX_CL_STATE obx_ca_snd_put_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_CS_NULL; - - OBX_TRACE_DEBUG1("obx_ca_snd_put_req, srm:0x%x", p_cb->srm); - state = obx_ca_snd_req (p_cb, p_pkt); - if (p_cb->srm & OBX_SRM_ENGAGE) - { - if (state == OBX_CS_PARTIAL_SENT) - { - p_cb->next_state = OBX_CS_PUT_SRM; - } - else - { - p_cb->state = OBX_CS_PUT_SRM; - if ((p_cb->srm & OBX_SRM_WAIT) == 0) - { - p_cb->rsp_code = OBX_RSP_CONTINUE; - p_cb->param.put.final = FALSE; - p_cb->param.put.type = OBX_PT_PUT; - p_cb->param.put.ssn = 0; - state = obx_ca_notify (p_cb, NULL); - } - } - } - return state; -} - -/******************************************************************************* -** Function obx_ca_snd_get_req -** Description send get request in connected state -*******************************************************************************/ -tOBX_CL_STATE obx_ca_snd_get_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state; - - OBX_TRACE_DEBUG1("obx_ca_snd_get_req srm:0x%x", p_cb->srm ); - state = obx_ca_snd_req (p_cb, p_pkt); - OBX_TRACE_DEBUG1("srm:0x%x", p_cb->srm ); - if (p_cb->srm & OBX_SRM_ENABLE) - { - if (state == OBX_CS_PARTIAL_SENT) - { - p_cb->next_state = OBX_CS_GET_SRM; - } - else - state = OBX_CS_GET_SRM; - p_cb->srm &= ~OBX_SRM_WAIT_UL; - } - OBX_TRACE_DEBUG1("srm:0x%x", p_cb->srm ); - return state; -} - -/******************************************************************************* -** Function obx_ca_srm_snd_req -** Description send Abort or Disconnect request -*******************************************************************************/ -tOBX_CL_STATE obx_ca_srm_snd_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state; - tOBX_COMM_CB *p_comm = &p_cb->ll_cb.comm; - - OBX_TRACE_DEBUG2("obx_ca_srm_snd_req rx_q.count: %d, srm:0x%x", p_comm->rx_q.count, p_cb->srm ); - p_cb->srm &= ~OBX_SRM_WAIT_UL; - state = obx_ca_snd_req (p_cb, p_pkt); - if ((p_pkt = (BT_HDR *)GKI_dequeue (&p_comm->rx_q)) != NULL) - { - GKI_freebuf(p_pkt); - } - OBX_TRACE_DEBUG2(" rx_q.count: %d, srm:0x%x", p_comm->rx_q.count, p_cb->srm ); - return state; -} - -/******************************************************************************* -** Function obx_ca_srm_put_req -** Description send a PUT request when SRM is engaged -*******************************************************************************/ -tOBX_CL_STATE obx_ca_srm_put_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state; - - OBX_TRACE_DEBUG1("obx_ca_srm_put_req srm:0x%x", p_cb->srm ); - state = obx_ca_snd_req (p_cb, p_pkt); - OBX_TRACE_DEBUG4("obx_ca_srm_put_req state:%d srm:0x%x, final:%d rsp_code:0x%x", state, p_cb->srm, p_cb->final, p_cb->rsp_code ); - if (state != OBX_CS_PARTIAL_SENT && p_cb->final != TRUE && (p_cb->srm & OBX_SRM_WAIT) == 0) - { - p_cb->rsp_code = OBX_RSP_CONTINUE; - state = obx_ca_notify (p_cb, NULL); - } - return state; -} - -/******************************************************************************* -** Function obx_ca_srm_get_req -** Description send a GET request when SRM is engaged -*******************************************************************************/ -tOBX_CL_STATE obx_ca_srm_get_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_CS_NULL; - tOBX_COMM_CB *p_comm = &p_cb->ll_cb.comm; - - OBX_TRACE_DEBUG3("obx_ca_srm_get_req rx_q.count: %d, srm:0x%x", p_cb->sess_st, p_comm->rx_q.count, p_cb->srm ); - - obx_start_timer(&p_cb->ll_cb.comm); - p_cb->srm &= ~OBX_SRM_WAIT_UL; - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - p_cb->ssn++; - } - if (p_pkt) - GKI_freebuf(p_pkt); - - if ((p_pkt = (BT_HDR *)GKI_dequeue (&p_comm->rx_q)) != NULL) - { - if (state != OBX_CS_NULL) - { - p_cb->prev_state = p_cb->state; - p_cb->state = state; - state = OBX_CS_NULL; - } - obx_cl_proc_pkt (p_cb, p_pkt); - obx_flow_control(p_comm); - OBX_TRACE_DEBUG1("obx_ca_srm_get_req rx_q.count: %d", p_cb->ll_cb.comm.rx_q.count ); - } - OBX_TRACE_DEBUG1("obx_ca_srm_get_req srm:0x%x", p_cb->srm ); - - return state; -} - -/******************************************************************************* -** Function obx_ca_srm_put_notify -** Description Notify the OBX user OBX_PUT_RSP_EVT (OBX is ready for next req) -*******************************************************************************/ -tOBX_CL_STATE obx_ca_srm_put_notify(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state; - - OBX_TRACE_DEBUG2("obx_ca_srm_put_notify srm: 0x%x, srmp: 0x%x", p_cb->srm, p_cb->srmp ); - - state = obx_ca_notify (p_cb, p_pkt); - return state; -} - -/******************************************************************************* -** Function obx_ca_srm_get_notify -** Description Notify the OBX user OBX_GET_RSP_EVT (OBX is ready for next req) -*******************************************************************************/ -tOBX_CL_STATE obx_ca_srm_get_notify(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_CS_NULL; - - OBX_TRACE_DEBUG1("obx_ca_srm_get_notify srm: 0x%x", p_cb->srm ); - /* do not allow SRMP for now */ - p_cb->srm &= ~OBX_SRM_WAIT; - - if (p_cb->srm & OBX_SRM_ENGAGE) - { - if ((p_cb->srm & OBX_SRM_WAIT_UL) == 0) - { - p_cb->srm |= OBX_SRM_WAIT_UL; - state = obx_ca_notify (p_cb, p_pkt); - } - else - { - GKI_enqueue_head (&p_cb->ll_cb.comm.rx_q, p_pkt); - OBX_TRACE_DEBUG1("obx_ca_srm_get_notify rx_q.count:%d", p_cb->ll_cb.comm.rx_q.count); - } - } - else - { - state = obx_ca_notify (p_cb, p_pkt); - if (state == OBX_CS_GET_SRM || state == OBX_CS_NULL) - state = OBX_CS_GET_TRANSACTION; - } - OBX_TRACE_DEBUG2("obx_ca_srm_get_notify srm: 0x%x(e) state:%s", p_cb->srm, obx_sr_get_state_name(state) ); - return state; -} - -/******************************************************************************* -** Function obx_ca_save_rsp -** Description save response in control block -*******************************************************************************/ -tOBX_CL_STATE obx_ca_save_rsp(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - GKI_enqueue (&p_cb->ll_cb.comm.rx_q, p_pkt); - return OBX_CS_NULL; -} - -/******************************************************************************* -** Function obx_ca_save_req -** Description save request in control block -*******************************************************************************/ -tOBX_CL_STATE obx_ca_save_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - if (p_cb->p_next_req) - { - /* this probably would not happen */ - /* this action only occurs when we are flow controlled by the peer - * and the client wants to abort the operation */ - /* Just in case that the user keeps calling abort request.... */ - OBX_TRACE_WARNING1("free next req: 0x%x", p_cb->p_next_req ); - GKI_freebuf(p_cb->p_next_req); - } - - p_cb->p_next_req = p_pkt; - - return OBX_CS_NULL; -} - - -/******************************************************************************* -** Function obx_ca_snd_req -** Description If (p_pkt), call p_send_fn() to send the message to the peer. -** Start timer. Return NULL state.If data is partially sent, return -** PART state. -*******************************************************************************/ -tOBX_CL_STATE obx_ca_snd_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_CS_NULL; - UINT8 rsp_code = OBX_RSP_DEFAULT; - - obx_access_rsp_code(p_pkt, &rsp_code); - p_cb->final = (rsp_code&OBX_FINAL) ? TRUE : FALSE; - OBX_TRACE_DEBUG2("obx_ca_snd_req rsp_code: 0x%x final:%d", rsp_code, p_cb->final ); - - /* save a copy of the request sent to the server */ - /* In case that we are challenged by the server, - * we can send the same request with authentication response again */ - if (p_cb->p_saved_req) - GKI_freebuf(p_cb->p_saved_req); - - p_cb->p_saved_req = obx_dup_pkt(p_pkt); - - OBX_TRACE_DEBUG3( "event p_saved_req:%d, pkt:%d, final: %d", p_cb->p_saved_req->event, p_pkt->event,p_cb->final); - - p_cb->ll_cb.comm.p_txmsg = p_pkt; - /* debug: obxu_dump_hex ((UINT8 *)(p_pkt + 1) + p_pkt->offset, "conn req", p_pkt->len); */ - - p_cb->srmp &= ~OBX_SRMP_SESS_FST; - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - p_cb->ssn++; - } - - if (p_cb->ll_cb.comm.p_send_fn(&p_cb->ll_cb) == FALSE) - { - p_cb->next_state = p_cb->state; - state = OBX_CS_PARTIAL_SENT; - } - - return state; -} - -/******************************************************************************* -** Function obx_ca_close_port -** Description Close the transport. Return NULL state. -*******************************************************************************/ -tOBX_CL_STATE obx_ca_close_port(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - if (p_pkt) - GKI_freebuf(p_pkt); - p_cb->ll_cb.comm.p_close_fn(p_cb->ll_cb.comm.id); - return OBX_CS_NULL; -} - -/******************************************************************************* -** Function obx_ca_snd_part -** Description Call p_send_fn() to send the left-over OBEX message to the peer. -** Start timer. If all the data is sent, call obx_csm_event() with -** STATE event to next_state in the port control block. -** If (p_next_req), call obx_csm_event() to process the saved request. -** Return NULL state. -*******************************************************************************/ -tOBX_CL_STATE obx_ca_snd_part(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_CL_STATE state = OBX_CS_NULL; - - OBX_TRACE_DEBUG1("obx_ca_snd_part sess_st:%d", p_cb->sess_st); - - /* p_pkt should be NULL here */ - if (p_cb->ll_cb.comm.p_send_fn(&p_cb->ll_cb) == TRUE) - { - /* data is all sent. change state to the appropriate state */ - obx_csm_event(p_cb, OBX_STATE_CEVT, NULL); - if (p_cb->p_next_req && (p_cb->sess_st != OBX_SESS_CREATE)) - { - /* abort request was issued - send it now */ - p_pkt = p_cb->p_next_req; - p_cb->p_next_req = NULL; - obx_csm_event(p_cb, (tOBX_CL_EVENT)(p_pkt->event-1), p_pkt); - } - - OBX_TRACE_DEBUG2("obx_ca_snd_part state:%d, srm:0x%x", p_cb->state, p_cb->srm); - if ((p_pkt = (BT_HDR *)GKI_dequeue (&p_cb->ll_cb.comm.rx_q)) != NULL) - { - obx_cl_proc_pkt (p_cb, p_pkt); - } - else if (p_cb->state == OBX_CS_PUT_SRM) - { - if (((p_cb->srm & OBX_SRM_WAIT) == 0) && (p_cb->final != TRUE)) - { - state = obx_ca_notify (p_cb, NULL); - } - } - } - return state; -} - -/******************************************************************************* -** Function obx_ca_connect_error -** Description Call callback function with OBX_CLOSE_IND_EVT. Free the client -** control block. Return NULL state. -*******************************************************************************/ -tOBX_CL_STATE obx_ca_connect_error(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_CL_CBACK *p_cback = p_cb->p_cback; - tOBX_HANDLE handle = p_cb->ll_cb.comm.handle; - tOBX_EVT_PARAM param = p_cb->param; - tOBX_SR_STATE save_state; - - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - /* The transport is interrupted while a reliable session is active: - * report a suspend event fot application to save the information in NV. - * The only time this is called is for port close evt /w next state as not_connected - * we need to use prev_state as the potential state to resume session - */ - save_state = p_cb->prev_state; - if (save_state == OBX_CS_PARTIAL_SENT) - save_state = p_cb->next_state; - /* marks link drop suspend only when SRM is not engaged */ - if ((p_cb->srm & OBX_SRM_ENGAGE) == 0) - save_state |= OBX_CL_STATE_DROP; - else if (save_state == OBX_CS_GET_SRM) - p_cb->srm &= ~OBX_SRM_WAIT_UL; - p_cb->sess_info[OBX_SESSION_INFO_ST_IDX] = save_state; - OBX_TRACE_DEBUG2("obx_ca_connect_error saved state:0x%x, srm:0x%x", save_state, p_cb->srm); - p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX] = p_cb->srm; - param.sess.p_sess_info = p_cb->sess_info; - param.sess.sess_op = OBX_SESS_OP_TRANSPORT; - param.sess.sess_st = p_cb->sess_st; - param.sess.nssn = p_cb->ssn; - param.sess.ssn = p_cb->ssn; - param.sess.obj_offset = 0; - param.sess.timeout = OBX_SESS_TIMEOUT_VALUE; - memcpy(param.sess.peer_addr, p_cb->peer_addr, BD_ADDR_LEN); - p_cb->sess_st = OBX_SESS_NONE; - (*p_cback)(handle, OBX_SESSION_INFO_EVT, OBX_RSP_OK, param, NULL); - } - - obx_cl_free_cb(p_cb); - (*p_cback)(handle, OBX_CLOSE_IND_EVT, OBX_RSP_DEFAULT, param, p_pkt); - return OBX_CS_NULL; -} - -/******************************************************************************* -** Function obx_ca_connect_fail -** Description If the response code is OBX_RSP_UNAUTHORIZED, save the OBEX -** message in the client control block and call callback function -** with OBX_PASSWORD_EVT. Return NULL state.Otherwise, call -** obx_csm_event() with OBX_DISCNT_REQ_CEVT. (We do not need to -** send disconnect request to the server, since we are not -** connected yet). Return NULL state. -*******************************************************************************/ -tOBX_CL_STATE obx_ca_connect_fail(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_CS_NULL; - - if ( p_cb->rsp_code == OBX_RSP_UNAUTHORIZED && - OBX_CheckHdr(p_pkt, OBX_HI_CHALLENGE) != NULL) - { - p_cb->api_evt = OBX_PASSWORD_EVT; - p_cb->p_auth = obx_dup_pkt(p_pkt); - } - else - { - /* Connect Request is rejected for reasons other than authentication - * or if the client challenges the server, but the server does nt return good digest - * - notify the user of the failure and .. */ - (*p_cb->p_cback)(p_cb->ll_cb.comm.handle, OBX_CONNECT_RSP_EVT, p_cb->rsp_code, p_cb->param, p_pkt); - p_cb->api_evt = OBX_NULL_EVT; - /* and close the RFCOMM port */ - obx_csm_event(p_cb, OBX_DISCNT_REQ_CEVT, NULL); - } - return state; -} - -/******************************************************************************* -** Function obx_ca_discnt_req -** Description OBX_DISCNT_REQ_CEVT event is received in OBX_CS_CONNECT_REQ_SENT -** state. In case that the server fails the authentication, client -** needs to send Disconnect Req. Otherwise, just close port. -*******************************************************************************/ -tOBX_CL_STATE obx_ca_discnt_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_CL_STATE state = OBX_CS_NOT_CONNECTED; - UINT8 msg[OBX_HDR_OFFSET]; - UINT8 *p = msg; - - if (p_cb->wait_auth == OBX_WAIT_AUTH_FAIL) - { - /* server thinks the connection is up. - * client needs to send disconnect req */ - state = OBX_CS_DISCNT_REQ_SENT; - /* Disconnect request always has the final bit set */ - *p++ = (OBX_REQ_DISCONNECT|OBX_FINAL); - p += OBX_PKT_LEN_SIZE; - - /* add session sequence number, if session is active */ - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - *p++ = OBX_HI_SESSION_SN; - *p++ = p_cb->ssn; - } - - /* add connection ID, if needed */ - if (p_cb->conn_id != OBX_INVALID_CONN_ID) - { - *p++ = OBX_HI_CONN_ID; - UINT32_TO_BE_STREAM(p, p_cb->conn_id); - } - - p_pkt = obx_cl_prepend_msg(p_cb, NULL, msg, (UINT16)(p - msg) ); - obx_ca_snd_req(p_cb, p_pkt); - } - else - { - /* connection is not officially up yet. - * just close the port */ - obx_ca_close_port(p_cb, p_pkt); - } - p_cb->wait_auth = FALSE; - - return state; -} - -/******************************************************************************* -** Function obx_ca_notify -** Description Use api_evt or look up the event according to the state. Fill -** the event parameter. Call callback function with the event. -** Return NULL state. -*******************************************************************************/ -tOBX_CL_STATE obx_ca_notify(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_CS_CONNECTED; - tOBX_EVENT event = obx_cl_state_2_event_map[p_cb->state - 1]; - BOOLEAN notify = FALSE; - tOBX_CL_EVENT sm_evt = OBX_BAD_SM_EVT; - BT_HDR *p_req = NULL; - - OBX_TRACE_DEBUG6( "obx_ca_notify state: %s, prev_state: %s, rsp:0x%x, sess_st:%d, event:%d srm:0x%x", - obx_cl_get_state_name( p_cb->state ), obx_cl_get_state_name(p_cb->prev_state), p_cb->rsp_code, p_cb->sess_st, event, p_cb->srm); - OBX_TRACE_DEBUG2( "ssn:0x%x/0x%x", p_cb->ssn, p_cb->param.ssn); - - if ( (p_cb->final == TRUE && p_cb->rsp_code == OBX_RSP_CONTINUE && p_cb->state == OBX_CS_PUT_TRANSACTION) || - (p_cb->final == FALSE && p_cb->rsp_code != OBX_RSP_CONTINUE) ) - { - /* final bit on the request mismatch the responde code --- Error!! */ - OBX_TRACE_ERROR2( "final:%d on the request mismatch the responde code:0x%x", - p_cb->final, p_cb->rsp_code) ; - /* change the state to not connected state */ - p_cb->next_state = OBX_CS_NOT_CONNECTED; - obx_csm_event(p_cb, OBX_STATE_CEVT, NULL); - notify = TRUE; - /* send a tx_empty event to close port */ - sm_evt = OBX_TX_EMPTY_CEVT; - } - - else if (event != OBX_NULL_EVT) - { - switch (p_cb->state) - { - case OBX_CS_PUT_TRANSACTION: - case OBX_CS_GET_TRANSACTION: - case OBX_CS_PUT_REQ_SENT: - case OBX_CS_GET_REQ_SENT: - case OBX_CS_PUT_SRM: - case OBX_CS_GET_SRM: - if (p_cb->rsp_code == OBX_RSP_CONTINUE ) - { - /* notify the event in this function. the new state stays the same */ - notify = TRUE; - - if (p_cb->srm & OBX_SRM_ENGAGE) - { - if (p_cb->state == OBX_CS_PUT_TRANSACTION) - { - p_cb->state = OBX_CS_PUT_SRM; - } - else if (p_cb->state == OBX_CS_GET_TRANSACTION) - { - p_cb->state = OBX_CS_GET_SRM; - } - else if (p_cb->state == OBX_CS_PUT_SRM && p_pkt && (p_cb->srm & OBX_SRM_WAIT) == 0) - { - OBX_TRACE_ERROR0 ("unexpected PUT response. disconnect now!!"); - notify = FALSE; - event = OBX_NULL_EVT; - obx_ca_close_port(p_cb, p_pkt); - } - /* clear the wait bit here to avoid the link being disconnected by accident */ - p_cb->srm &= ~OBX_SRM_WAIT; - if (p_cb->srmp) - { - p_cb->srmp = 0; - p_cb->srm |= OBX_SRM_WAIT; - } - } - } - /* else let obx_csm_event notify the event. the new state is OBX_CS_CONNECTED */ - else - { - /* dis-engage SRM */ - p_cb->srm &= OBX_SRM_ENABLE; - OBX_TRACE_DEBUG1( "disengage srm:0x%x", p_cb->srm); - } - break; - - case OBX_CS_NOT_CONNECTED: - if (p_cb->sess_st == OBX_SESS_ACTIVE && p_cb->prev_state == OBX_CS_DISCNT_REQ_SENT) - { - p_req = obx_ca_close_sess_req (p_cb); - sm_evt = OBX_SESSION_REQ_CEVT; - state = OBX_CS_NULL; - } - else - { - notify = TRUE; - /* send a tx_empty event to close port */ - sm_evt = OBX_TX_EMPTY_CEVT; - } - break; - - case OBX_CS_CONNECT_REQ_SENT: - if (p_cb->rsp_code == OBX_RSP_FAILED) - { - /* client challenged the server and the server does not return a good digest */ - notify = TRUE; - /* send a disconnect req event to close port */ - sm_evt = OBX_DISCNT_REQ_CEVT; - } - break; - - case OBX_CS_ABORT_REQ_SENT: - p_cb->srm &= OBX_SRM_ENABLE; - OBX_TRACE_DEBUG1( "(ab) disengage srm:0x%x", p_cb->srm); - break; - } - } - - if (notify == TRUE ) - { - (*p_cb->p_cback)(p_cb->ll_cb.comm.handle, event, p_cb->rsp_code, p_cb->param, p_pkt); - event = OBX_NULL_EVT; - } - - if (sm_evt != OBX_BAD_SM_EVT) - { - /* send an event to csm */ - obx_csm_event(p_cb, sm_evt, p_req); - } - - p_cb->api_evt = event; - if (event == OBX_NULL_EVT) - { - state = OBX_CS_NULL; - } - else - { - p_cb->ssn = p_cb->param.ssn; - OBX_TRACE_DEBUG1( "ssn:0x%x", p_cb->ssn); - } - - return state; -} - -/******************************************************************************* -** Function obx_ca_fail_rsp -** Description Save the OBEX message in control block.If the response code is -** OBX_RSP_UNAUTHORIZED, set api_evt to OBX_PASSWORD_EVT. Return -** OP_UNAUTH state.Otherwise, set api_evt according to the -** event/state table. Return CONN state. -*******************************************************************************/ -tOBX_CL_STATE obx_ca_fail_rsp(tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_CS_CONNECTED; - - p_cb->srm &= OBX_SRM_ENABLE; - - if ( p_cb->rsp_code == OBX_RSP_UNAUTHORIZED && - OBX_CheckHdr(p_pkt, OBX_HI_CHALLENGE) != NULL) - { - state = OBX_CS_OP_UNAUTH; - p_cb->api_evt = OBX_PASSWORD_EVT; - p_cb->p_auth = obx_dup_pkt(p_pkt); - } - else - p_cb->api_evt = obx_cl_state_2_event_map[p_cb->state - 1]; - - return state; -} diff --git a/stack/obx/obx_capi.c b/stack/obx/obx_capi.c deleted file mode 100644 index ea34aa1..0000000 --- a/stack/obx/obx_capi.c +++ /dev/null @@ -1,855 +0,0 @@ -/***************************************************************************** -** -** Name: obx_capi.c -** -** File: OBEX Client Application Programming Interface functions -** -** Copyright (c) 2003-2010, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "wcassert.h" -#include "obx_int.h" -#include "port_api.h" -#include "l2c_api.h" -#include "btm_api.h" - -/******************************************************************************* -** -** Function OBX_ConnectReq -** -** Description This function registers a client entity to OBEX and sends a -** CONNECT request to the server specified by the API parameters. -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if OBX does not resources -** -*******************************************************************************/ -tOBX_STATUS OBX_ConnectReq(BD_ADDR bd_addr, UINT8 scn, UINT16 mtu, - tOBX_CL_CBACK *p_cback, tOBX_HANDLE *p_handle, BT_HDR *p_pkt) -{ - tOBX_STATUS status = OBX_NO_RESOURCES; - UINT8 msg[OBX_HDR_OFFSET + OBX_MAX_CONN_HDR_EXTRA]; - UINT8 *p = msg; - tOBX_CL_CB *p_cb; - - WC_ASSERT(p_handle); - - p_cb = obx_cl_get_cb(*p_handle); - if (p_cb == NULL) - p_cb = obx_cl_alloc_cb(); - - if (p_cb) - { - if (p_cb->ll_cb.port.port_handle == 0) - { - WC_ASSERT(p_cback); - /* port is not open yet- open one - * this is the first CONNECT request */ - p_cb->ll_cb.comm.rx_mtu = mtu; - p_cb->p_cback = p_cback; - p_cb->state = OBX_CS_NOT_CONNECTED; - status = obx_open_port(&p_cb->ll_cb.port, bd_addr, scn); - *p_handle = p_cb->ll_cb.port.handle; - } - else - { - /* when called by other OBX functions */ - status = OBX_SUCCESS; - } - - if (status == OBX_SUCCESS) - { - /* Connect request packet always has the final bit set */ - *p++ = (OBX_REQ_CONNECT | OBX_FINAL); - p += OBX_PKT_LEN_SIZE; - - *p++ = OBX_VERSION; - *p++ = OBX_CONN_FLAGS; - UINT16_TO_BE_STREAM(p, p_cb->ll_cb.port.rx_mtu); - /* IrOBEX spec forbids connection ID in Connect Request */ - p_pkt = obx_cl_prepend_msg(p_cb, p_pkt, msg, (UINT16)(p - msg) ); - - p_pkt->event = OBX_CONNECT_REQ_EVT; - obx_csm_event(p_cb, OBX_CONNECT_REQ_CEVT, p_pkt); - } - else - { - OBX_TRACE_ERROR1("Error opening port for scn: %d", scn); - obx_cl_free_cb(p_cb); - } - } - return status; -} - -/******************************************************************************* -** -** Function OBX_AllocSession -** -** Description This function registers a client entity to OBEX. -** If p_session_info is not NULL, it tries to find an suspended session -** with matching session_info. -** If scn is not 0, it allocates a control block for this new session. -** Otherwise, it allocates a control block for the given PSM. -** The associated virtual PSM assigned by L2CAP is returned in p_psm -** The allocated OBEX handle is returned in p_handle. -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if OBX does not resources -** -*******************************************************************************/ -tOBX_STATUS OBX_AllocSession (UINT8 *p_session_info, UINT8 scn, UINT16 *p_psm, - tOBX_CL_CBACK *p_cback, tOBX_HANDLE *p_handle) -{ - tOBX_STATUS status = OBX_NO_RESOURCES; - tOBX_CL_CB *p_cb; - - WC_ASSERT(p_handle); - WC_ASSERT(p_cback); - - OBX_TRACE_API2("OBX_AllocSession scn: %d, psm:0x%x", scn, *p_psm); - - if (p_session_info) - { - p_cb = obx_cl_get_suspended_cb(p_handle, p_session_info); - if (p_cb) - { - p_cb->srm = p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX]; - status = OBX_SUCCESS; - } - } - else - { - p_cb = obx_cl_get_cb(*p_handle); - if (p_cb == NULL) - p_cb = obx_cl_alloc_cb(); - - - } - - if (p_cb) - { - p_cb->rsp_code = 0; - p_cb->psm = 0; - - if (p_cb->sess_st != OBX_SESS_SUSPENDED) - p_cb->sess_st = OBX_SESS_NONE; - - if (p_psm && L2C_IS_VALID_PSM(*p_psm)) - { - obx_register_l2c(p_cb, *p_psm); - /* obx_register_l2c puts the virtual psm in p_cb->psm */ - if (p_cb->psm) - { - *p_psm = p_cb->psm; - status = OBX_SUCCESS; - } - } - - /* check SCN only when a virtual PSM is not allocated */ - if (!p_cb->psm) - { - if (scn) - { - /* borrow this data member temporarily */ - p_cb->rsp_code = scn; - status = OBX_SUCCESS; - } - } - } - - if (status != OBX_SUCCESS) - { - obx_cl_free_cb(p_cb); - p_cb = NULL; - } - - if (p_cb) - { - *p_handle = p_cb->ll_cb.comm.handle; - p_cb->p_cback = p_cback; - p_cb->state = OBX_CS_NOT_CONNECTED; - } - return status; -} - -/******************************************************************************* -** -** Function OBX_CreateSession -** -** Description This function registers a client entity to OBEX. -** It may send a CreateSession request and wait for CreateSession response. -** It sends a CONNECT request to the server specified by the API parameters. -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if OBX does not resources -** -*******************************************************************************/ -tOBX_STATUS OBX_CreateSession (BD_ADDR bd_addr, UINT16 mtu, BOOLEAN srm, UINT32 nonce, - tOBX_HANDLE handle, BT_HDR *p_pkt) -{ - tOBX_STATUS status = OBX_NO_RESOURCES; - tOBX_CL_CB *p_cb; - UINT8 *p; - UINT8 *pn; - BT_HDR *p_req; - UINT8 data[20]; - tOBX_TRIPLET triplet[4]; - UINT8 num_trip = 0; - - OBX_TRACE_API1("OBX_CreateSession handle: 0x%x", handle); - p_cb = obx_cl_get_cb(handle); - - if (p_cb) - { - if (p_cb->state != OBX_CS_NOT_CONNECTED || p_cb->sess_st != OBX_SESS_NONE) - { - OBX_TRACE_ERROR2("bad state: %d, or sess_st:%d", p_cb->state, p_cb->sess_st); - return status; - } - - if (p_cb->ll_cb.comm.id == 0) - { - p_cb->ll_cb.comm.rx_mtu = mtu; - - OBX_TRACE_DEBUG2("scn: %d, psm:0x%x", p_cb->rsp_code, p_cb->psm); - - if (p_cb->psm) - { - /* L2CAP channel is not open yet- open one - * this is the first CONNECT request */ - status = obx_open_l2c(p_cb, bd_addr); - } - else if (p_cb->rsp_code) /* p_cb->rsp_code is used as the scn */ - { - /* port is not open yet- open one - * this is the first CONNECT request */ - status = obx_open_port(&p_cb->ll_cb.port, bd_addr, p_cb->rsp_code); - } - } - else - { - /* when called by other OBX functions */ - status = OBX_SUCCESS; - } - - if (status == OBX_SUCCESS) - { - /* OBEX 1.5 */ - p_cb->srm = OBX_SRM_NO; - if (srm) - p_cb->srm = OBX_SRM_ENABLE; - p_cb->nonce = nonce; - p_cb->sess_st = OBX_SESS_NONE; - if (nonce) - { - if ( (p_req = OBX_HdrInit(handle, OBX_MIN_MTU)) != NULL) - { - p = (UINT8 *) (p_req + 1) + p_req->offset; - /* Session request packet always has the final bit set */ - *p++ = (OBX_REQ_SESSION | OBX_FINAL); - p_req->len = 3; - p = data; - /* add session opcode */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_SESS_OP; - triplet[num_trip].len = OBX_LEN_SESS_PARAM_SESS_OP; - triplet[num_trip].p_array = p; - *p = OBX_SESS_OP_CREATE; - p += OBX_LEN_SESS_PARAM_SESS_OP; - num_trip++; - - /* add device addr */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_ADDR; - triplet[num_trip].len = BD_ADDR_LEN; - triplet[num_trip].p_array = p; - BTM_GetLocalDeviceAddr (p); - p += BD_ADDR_LEN; - num_trip++; - - /* add nonce 4 - 16 bytes */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_NONCE; - triplet[num_trip].len = OBX_LOCAL_NONCE_SIZE; - pn = &p_cb->sess_info[OBX_SESSION_ID_SIZE]; - triplet[num_trip].p_array = pn; - UINT32_TO_BE_STREAM(pn, nonce); - num_trip++; - - /* add timeout */ - triplet[num_trip].p_array = p; - if (obx_add_timeout (&triplet[num_trip], obx_cb.sess_tout_val, &p_cb->param.sess)) - { - num_trip ++; - p = &p_cb->sess_info[OBX_SESSION_INFO_TO_IDX]; - UINT32_TO_BE_STREAM(p, obx_cb.sess_tout_val); - p_cb->param.sess.timeout = obx_cb.sess_tout_val; - } - - OBX_AddTriplet(p_req, OBX_HI_SESSION_PARAM, triplet, num_trip); - if (p_pkt) - { - /* assume that these headers are to be added to the connect req */ - p_cb->p_next_req = p_pkt; - } - /* adjust the packet len */ - p = (UINT8 *) (p_req + 1) + p_req->offset + 1; - UINT16_TO_BE_STREAM(p, p_req->len); - p_req->event = OBX_SESSION_REQ_EVT; - p_cb->sess_st = OBX_SESS_CREATE; - obx_csm_event(p_cb, OBX_SESSION_REQ_CEVT, p_req); - } - else - status = OBX_NO_RESOURCES; - } - else /* legacy */ - { - obx_ca_connect_req (p_cb, p_pkt); - } - } - if (status != OBX_SUCCESS) - { - obx_cl_free_cb(p_cb); - } - } - return status; -} - -/******************************************************************************* -** -** Function OBX_ResumeSession -** -** Description This function registers a client entity to OBEX and resumes -** a previously interrupted reliable session. -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if OBX does not resources -** -*******************************************************************************/ -tOBX_STATUS OBX_ResumeSession (BD_ADDR bd_addr, UINT8 ssn, UINT32 offset, tOBX_HANDLE handle) -{ - tOBX_STATUS status = OBX_NO_RESOURCES; - UINT8 *p; - tOBX_CL_CB *p_cb; - BT_HDR *p_req; - tOBX_TRIPLET triplet[6]; - UINT8 data[13]; - UINT8 num_trip = 0; - UINT8 *pn; - - OBX_TRACE_API3("OBX_ResumeSession handle: 0x%x ssn:%d offset:%d", handle, ssn, offset); - p_cb = obx_cl_get_cb(handle); - - if (p_cb) - { - OBX_TRACE_DEBUG3("OBX_ResumeSession, sess_st:%d srm:0x%x, saved state:0x%x", p_cb->sess_st, - p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX], p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX]); - if (p_cb->sess_st == OBX_SESS_SUSPENDED) - { - if ((p_req = OBX_HdrInit(OBX_HANDLE_NULL, OBX_MIN_MTU)) != NULL) - { - p = (UINT8 *) (p_req + 1) + p_req->offset; - /* Session request packet always has the final bit set */ - *p++ = (OBX_REQ_SESSION | OBX_FINAL); - p_req->len = 3; - - /* add session opcode */ - p = data; - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_SESS_OP; - triplet[num_trip].len = OBX_LEN_SESS_PARAM_SESS_OP; - triplet[num_trip].p_array = p; - *p = OBX_SESS_OP_RESUME; - p += OBX_LEN_SESS_PARAM_SESS_OP; - num_trip++; - - /* add device addr */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_ADDR; - triplet[num_trip].len = BD_ADDR_LEN; - triplet[num_trip].p_array = p; - BTM_GetLocalDeviceAddr (p); - p += BD_ADDR_LEN; - num_trip++; - - /* add nonce 4 - 16 bytes */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_NONCE; - triplet[num_trip].len = OBX_LOCAL_NONCE_SIZE; - pn = &p_cb->sess_info[OBX_SESSION_ID_SIZE]; - triplet[num_trip].p_array = pn; - num_trip++; - - /* add session id */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_SESS_ID; - triplet[num_trip].len = OBX_SESSION_ID_SIZE; - triplet[num_trip].p_array = p_cb->sess_info; - num_trip++; - - if (p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX] & OBX_SRM_ENGAGE) - { - /* add ssn */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_NSEQNUM; - triplet[num_trip].len = 1; - triplet[num_trip].p_array = p; - *p++ = ssn; - num_trip++; - - if (offset) - { - /* add object offset */ - p_cb->param.sess.obj_offset = offset; - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_OBJ_OFF; - triplet[num_trip].len = OBX_LEN_SESS_PARAM_OBJ_OFF; - triplet[num_trip].p_array = p; - UINT32_TO_BE_STREAM(p, offset); - num_trip++; - } - } - - p_cb->sess_st = OBX_SESS_RESUME; - OBX_AddTriplet(p_req, OBX_HI_SESSION_PARAM, triplet, num_trip); - /* adjust the packet len */ - p = (UINT8 *) (p_req + 1) + p_req->offset + 1; - UINT16_TO_BE_STREAM(p, p_req->len); - p_req->event = OBX_SESSION_REQ_EVT; - status = OBX_SUCCESS; - - if (p_cb->ll_cb.comm.id == 0 || p_cb->ll_cb.comm.p_send_fn == 0) - { - /* the transport is closed. open it again */ - OBX_TRACE_DEBUG2("scn: %d, psm:0x%x", p_cb->rsp_code, p_cb->psm); - p_cb->ll_cb.comm.rx_mtu = OBX_MAX_MTU; - - if (p_cb->psm) - { - /* L2CAP channel is not open yet- open one - * this is the first CONNECT request */ - status = obx_open_l2c(p_cb, bd_addr); - } - else if (p_cb->rsp_code) /* p_cb->rsp_code is used as the scn */ - { - /* port is not open yet- open one - * this is the first CONNECT request */ - status = obx_open_port(&p_cb->ll_cb.port, bd_addr, p_cb->rsp_code); - } - } - - if (status == OBX_SUCCESS) - { - pn = &p_cb->sess_info[OBX_SESSION_INFO_ID_IDX]; - BE_STREAM_TO_UINT32(p_cb->conn_id, pn); - p_cb->ssn = ssn; - p_cb->param.sess.ssn = ssn; - obx_csm_event(p_cb, OBX_SESSION_REQ_CEVT, p_req); - } - } - } - else - { - OBX_TRACE_ERROR1("Handle is not in a right state: %d for RESUME", p_cb->sess_st); - status = OBX_BAD_HANDLE; - } - } - return status; -} - -/******************************************************************************* -** -** Function OBX_SessionReq -** -** Description This function is used to Suspend/Close a session or update the -** timeout value of the session. -** If timeout is 0, OBX_SESS_TIMEOUT_VALUE is the value used -** THe timeout value is not added for the CloseSession request -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if OBX does not resources -** -*******************************************************************************/ -tOBX_STATUS OBX_SessionReq (tOBX_HANDLE handle, tOBX_SESS_OP opcode, UINT32 timeout) -{ - tOBX_STATUS status = OBX_NO_RESOURCES; - UINT8 *p; - tOBX_CL_CB *p_cb; - BT_HDR *p_req; - tOBX_TRIPLET triplet[3]; - UINT8 data[12]; - UINT8 num_trip = 0; - tOBX_SESS_ST old_sess_st; - - p_cb = obx_cl_get_cb(handle); - - if (p_cb) - { - OBX_TRACE_API2("OBX_SessionReq st:%d opcode:%d", p_cb->sess_st, opcode); - old_sess_st = p_cb->sess_st; - if ((p_req = OBX_HdrInit(OBX_HANDLE_NULL, OBX_MIN_MTU)) != NULL) - { - status = OBX_SUCCESS; - p = (UINT8 *) (p_req + 1) + p_req->offset; - /* Session request packet always has the final bit set */ - *p++ = (OBX_REQ_SESSION | OBX_FINAL); - p_req->len = 3; - - /* add session opcode */ - p = data; - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_SESS_OP; - triplet[num_trip].len = OBX_LEN_SESS_PARAM_SESS_OP; - triplet[num_trip].p_array = p; - *p = opcode; - p += OBX_LEN_SESS_PARAM_SESS_OP; - num_trip++; - if (timeout == 0) - { - timeout = obx_cb.sess_tout_val; - if (p_cb->srm & OBX_SRM_ENABLE) - timeout += obx_cb.sess_tout_val; - } - triplet[num_trip].p_array = p; - switch (opcode) - { - case OBX_SESS_OP_CLOSE: - /* do not need any other session parameters */ - if (p_cb->sess_st != OBX_SESS_NONE) - p_cb->sess_st = OBX_SESS_CLOSE; - else - { - OBX_TRACE_ERROR1("Handle is not in a right state: %d for CLOSE", p_cb->sess_st); - status = OBX_BAD_HANDLE; - } - break; - - case OBX_SESS_OP_SUSPEND: - /* do not need any other session parameters */ - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - /* add timeout value */ - num_trip += obx_add_timeout (&triplet[num_trip], timeout, &p_cb->param.sess); - p_cb->sess_st = OBX_SESS_SUSPEND; - } - else - { - OBX_TRACE_ERROR1("Handle is not in a right state: %d for SUSPEND", p_cb->sess_st); - status = OBX_BAD_HANDLE; - } - break; - - case OBX_SESS_OP_SET_TIME: - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - /* add timeout value */ - num_trip += obx_add_timeout (&triplet[num_trip], timeout, &p_cb->param.sess); - p_cb->sess_st = OBX_SESS_TIMEOUT; - } - else - { - OBX_TRACE_ERROR1("Handle is not in a right state: %d for SET_TIME", p_cb->sess_st); - status = OBX_BAD_HANDLE; - } - break; - default: - OBX_TRACE_ERROR1("bad session opcode :%d", opcode); - status = OBX_BAD_PARAMS; - } - - OBX_TRACE_DEBUG4("OBX_SessionReq, sess_st:%d->%d opcode:%d status:%d", old_sess_st, p_cb->sess_st, opcode, status); - if (status != OBX_SUCCESS) - GKI_freebuf (p_req); - else - { - OBX_AddTriplet(p_req, OBX_HI_SESSION_PARAM, triplet, num_trip); - if (p_cb->sess_st == OBX_SESS_SUSPEND) - { - p_cb->sess_info[OBX_SESSION_INFO_ST_IDX] = p_cb->state; - if (p_cb->state == OBX_CS_PARTIAL_SENT) - p_cb->sess_info[OBX_SESSION_INFO_ST_IDX] = p_cb->prev_state; - p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX] = p_cb->srm; - OBX_TRACE_DEBUG2("suspend saved st:%d, srm:0x%x", p_cb->sess_info[OBX_SESSION_INFO_ST_IDX], p_cb->sess_info[OBX_SESSION_INFO_SRM_IDX]); - } - /* adjust the packet len */ - p = (UINT8 *) (p_req + 1) + p_req->offset + 1; - UINT16_TO_BE_STREAM(p, p_req->len); - p_req->event = OBX_SESSION_REQ_EVT; - obx_csm_event(p_cb, OBX_SESSION_REQ_CEVT, p_req); - } - } - } - return status; -} - -/******************************************************************************* -** -** Function OBX_GetPortHandle -** -** Description This function is called to get RFCOMM port handle for the obex connection. -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if no existing connection. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_GetPortHandle(tOBX_HANDLE handle, UINT16 *port_handle) -{ - BD_ADDR bd_addr; - UINT16 lcid; - tOBX_STATUS status = OBX_SUCCESS; - tOBX_CL_CB *p_cb = obx_cl_get_cb(handle); - - if (p_cb) - { - if (PORT_CheckConnection(p_cb->ll_cb.port.port_handle, bd_addr, &lcid) != PORT_SUCCESS) - { - status = OBX_NO_RESOURCES; - } - else - { - *port_handle = p_cb->ll_cb.port.port_handle; - } - } - else - status = OBX_BAD_HANDLE; - - return status; -} - -/******************************************************************************* -** -** Function OBX_SetPathReq -** -** Description This function sends a Set Path request to the connected server. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_SetPathReq(tOBX_HANDLE handle, UINT8 flags, BT_HDR *p_pkt) -{ - tOBX_CL_CB *p_cb = obx_cl_get_cb(handle); - tOBX_STATUS status = OBX_BAD_HANDLE; - UINT8 msg[OBX_HDR_OFFSET]; - UINT8 *p = msg; - UINT8 good_flags = (OBX_SPF_BACKUP | OBX_SPF_NO_CREATE); - - if (p_cb) - { - /* SetPath request packet always has the final bit set */ - *p++ = (OBX_REQ_SETPATH | OBX_FINAL); - p += OBX_PKT_LEN_SIZE; - *p++ = (flags & good_flags); /* send only good flags */ - *p++ = OBX_SETPATH_CONST; - - /* add session sequence number, if session is active */ - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - *p++ = OBX_HI_SESSION_SN; - *p++ = p_cb->ssn; - } - - /* add connection ID, if needed */ - if (p_cb->conn_id != OBX_INVALID_CONN_ID) - { - *p++ = OBX_HI_CONN_ID; - UINT32_TO_BE_STREAM(p, p_cb->conn_id); - } - p_pkt = obx_cl_prepend_msg(p_cb, p_pkt, msg, (UINT16)(p - msg) ); - p_pkt->event = OBX_SETPATH_REQ_EVT; - obx_csm_event(p_cb, OBX_SETPATH_REQ_CEVT, p_pkt); - status = OBX_SUCCESS; - } - return status; -} - -/******************************************************************************* -** -** Function obx_prepend_req_msg -** -** Description This function is called to add request code and connection ID -** to the given OBEX message -** Returns void -** -*******************************************************************************/ -tOBX_STATUS obx_prepend_req_msg(tOBX_HANDLE handle, tOBX_CL_EVENT event, UINT8 req_code, BT_HDR *p_pkt) -{ - tOBX_STATUS status = OBX_SUCCESS; - tOBX_CL_CB *p_cb = obx_cl_get_cb(handle); - UINT8 msg[OBX_HDR_OFFSET]; - UINT8 *p = msg; - UINT8 srm = 0; - UINT8 num_hdrs, num_body; - - if (p_cb) - { - *p++ = req_code; - p += OBX_PKT_LEN_SIZE; - - /* add session sequence number, if session is active */ - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - *p++ = OBX_HI_SESSION_SN; - *p++ = p_cb->ssn; - } - - req_code &= ~OBX_FINAL; - - /* add connection ID, if needed */ - if ((p_cb->conn_id != OBX_INVALID_CONN_ID) && - /* always use connection ID in CONNECTED state or being challenged on operation */ - ((p_cb->state == OBX_CS_CONNECTED) || (p_cb->state == OBX_CS_OP_UNAUTH) || - /* always use connection ID for abort and disconnect. they may be out of sequence */ - (req_code == OBX_REQ_ABORT) || (req_code == OBX_REQ_DISCONNECT))) - { - *p++ = OBX_HI_CONN_ID; - UINT32_TO_BE_STREAM(p, p_cb->conn_id); - } - - /* add SRM header, if SRM is enabled */ - if (p_cb->srm & OBX_SRM_ENABLE) - { - if (p_cb->state == OBX_CS_CONNECTED) - { - if(event == OBX_PUT_REQ_CEVT) - { - num_hdrs = OBX_ReadNumHdrs(p_pkt, &num_body); - OBX_TRACE_DEBUG2("num_hdrs:%d num_body:%d", num_hdrs, num_body); - if (num_hdrs == num_body) - { - OBX_TRACE_DEBUG0("it is left-over, drop it"); - if (p_pkt) - GKI_freebuf (p_pkt); - return OBX_BAD_PARAMS; - } - srm = OBX_SRM_REQING | OBX_SRM_WAIT; - } - else if (event == OBX_GET_REQ_CEVT) - { - srm = OBX_SRM_REQING; - } - - OBX_TRACE_DEBUG2("cb srm: 0x%x/0x%x", p_cb->srm, srm ); - if (srm) - { - p_cb->srm |= srm; - *p++ = OBX_HI_SRM; - *p++ = OBX_HV_SRM_ENABLE; - } - } - } - - p_pkt = obx_cl_prepend_msg(p_cb, p_pkt, msg, (UINT16)(p - msg) ); - p_pkt->event = obx_sm_evt_to_api_evt[event]; - obx_csm_event(p_cb, event, p_pkt); - } - else - status = OBX_BAD_HANDLE; - - return status; -} - -/******************************************************************************* -** -** Function OBX_PutReq -** -** Description This function sends a Put request to the connected server. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_PutReq(tOBX_HANDLE handle, BOOLEAN final, BT_HDR *p_pkt) -{ - UINT8 req_code = OBX_REQ_PUT; - if (final) - req_code |= OBX_FINAL; - return obx_prepend_req_msg(handle, OBX_PUT_REQ_CEVT, req_code, p_pkt); - -} - - -/******************************************************************************* -** -** Function OBX_GetReq -** -** Description This function sends a Get request to the connected server. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_GetReq(tOBX_HANDLE handle, BOOLEAN final, BT_HDR *p_pkt) -{ - UINT8 req_code = OBX_REQ_GET; - OBX_TRACE_API1("OBX_GetReq final: 0x%x", final ); - if (final) - req_code |= OBX_FINAL; - return obx_prepend_req_msg(handle, OBX_GET_REQ_CEVT, req_code, p_pkt); -} - - -/******************************************************************************* -** -** Function OBX_AbortReq -** -** Description This function sends an Abort request to the connected server. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_AbortReq(tOBX_HANDLE handle, BT_HDR *p_pkt) -{ - /* Disconnect request always has the final bit set */ - UINT8 req_code = (OBX_REQ_ABORT|OBX_FINAL); - return obx_prepend_req_msg(handle, OBX_ABORT_REQ_CEVT, req_code, p_pkt); -} - - -/******************************************************************************* -** -** Function OBX_DisconnectReq -** -** Description This function sends a Disconnect request to the connected server. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_DisconnectReq(tOBX_HANDLE handle, BT_HDR *p_pkt) -{ - /* Disconnect request always has the final bit set */ - UINT8 req_code = (OBX_REQ_DISCONNECT|OBX_FINAL); - return obx_prepend_req_msg(handle, OBX_DISCNT_REQ_CEVT, req_code, p_pkt); -} - -/******************************************************************************* -** -** Function OBX_ActionReq -** -** Description This function sends a Action request to the connected server. -** The Name Header and DestName Header must be in p_pkt for -** the Copy and Move Object action. -** The Name header and Permission Header must be in p_pkt for -** the Set Object Permission action. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_ActionReq(tOBX_HANDLE handle, tOBX_ACTION action_id, BT_HDR *p_pkt) -{ - /* Disconnect request always has the final bit set */ - UINT8 req_code = (OBX_REQ_ACTION|OBX_FINAL); - UINT8 *p; - - if (p_pkt == NULL) - { - OBX_TRACE_ERROR0("OBX_ActionReq must include Name & DestName Header for Copy/Move action" ); - OBX_TRACE_ERROR0("OBX_ActionReq must include Name & Permission Header for Set Object Permission action" ); - return OBX_BAD_PARAMS; - } - - /* add the Action ID header before the other headers */ - p_pkt->offset -= 2; - p_pkt->len += 2; - p = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - *p++ = OBX_HI_ACTION_ID; - *p++ = action_id; - - return obx_prepend_req_msg(handle, OBX_ACTION_REQ_CEVT, req_code, p_pkt); -} diff --git a/stack/obx/obx_csm.c b/stack/obx/obx_csm.c deleted file mode 100644 index 25447df..0000000 --- a/stack/obx/obx_csm.c +++ /dev/null @@ -1,365 +0,0 @@ -/***************************************************************************** -** -** Name: obx_csm.c -** -** File: OBEX Client State Machine and Control Block Access Functions -** -** Copyright (c) 2003-2009, Broadcom Corp., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include "bt_target.h" -#include "btu.h" /* for timer */ -#include "obx_int.h" - -/* OBEX Client Action Functions Enums (must match obx_cl_action [below] */ -enum -{ - OBX_CA_SND_REQ, - OBX_CA_NOTIFY, - OBX_CA_CONNECT_ERROR, - OBX_CA_STATE, - OBX_CA_CLOSE_PORT, - OBX_CA_CONNECT_FAIL, - OBX_CA_DISCNT_REQ, - OBX_CA_START_TIMER, - OBX_CA_FAIL_RSP, - OBX_CA_SND_PART, - OBX_CA_CONNECT_OK, - OBX_CA_SESSION_OK, - OBX_CA_SESSION_CONT, - OBX_CA_SESSION_GET, - OBX_CA_SESSION_FAIL, - OBX_CA_ABORT, - OBX_CA_SND_PUT_REQ, - OBX_CA_SND_GET_REQ, - OBX_CA_SRM_SND_REQ, - OBX_CA_SRM_PUT_REQ, - OBX_CA_SRM_GET_REQ, - OBX_CA_SRM_PUT_NOTIFY, - OBX_CA_SRM_GET_NOTIFY, - OBX_CA_SAVE_RSP, - OBX_CA_SAVE_REQ -}; - -/* OBEX Client Action Functions */ -static const tOBX_CL_ACT obx_cl_action[] = -{ - obx_ca_snd_req, - obx_ca_notify, - obx_ca_connect_error, - obx_ca_state, - obx_ca_close_port, - obx_ca_connect_fail, - obx_ca_discnt_req, - obx_ca_start_timer, - obx_ca_fail_rsp, - obx_ca_snd_part, - obx_ca_connect_ok, - obx_ca_session_ok, - obx_ca_session_cont, - obx_ca_session_get, - obx_ca_session_fail, - obx_ca_abort, - obx_ca_snd_put_req, - obx_ca_snd_get_req, - obx_ca_srm_snd_req, - obx_ca_srm_put_req, - obx_ca_srm_get_req, - obx_ca_srm_put_notify, - obx_ca_srm_get_notify, - obx_ca_save_rsp, - obx_ca_save_req -}; - -/************ OBX Client FSM State/Event Indirection Table **************/ -/* obx_csm_event() first looks at obx_csm_entry_map[][] to get an entry of the event of a particular state - * 0 means the event in the current state is ignored. - * a number with 0x80 bit set, use obx_cl_all_table[][] as the "state table". - * other numbers, look up obx_cl_main_state_table[] for the state table of current state. - * - * once the state table is determined, - * look up the "action" column to find the associated action function - * and the "next state" column to find the "next state" candidate. - * - * The actual next state could be either the state in the "next state" column - * or the state returned from the action function. - */ -static const UINT8 obx_csm_entry_map[][OBX_CS_MAX-1] = -{ -/* state name: NtCon SesRs ConRs UnAut Conn DscRs OpUna StpRs ActRs AbtRs PutRs GetRs Put Get PutS GetS Part */ -/* CONN_R */{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SESS_R */{ 2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 2, 2, 2, 2, 5, 5, 1 }, -/* DISCNT_R */{ 0, 0x87, 2, 0x87, 0x81, 0x87, 0x87, 0x81, 0x81, 0x81, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87 }, -/* PUT_R */{ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0 }, -/* GET_R */{ 0, 3, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0 }, -/* SETPATH_R*/{ 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* ACT_R */{ 0, 0, 0, 0, 6, 0, 5, 0, 0, 0, 0x82, 0x82, 0x82, 0x82, 3, 3, 1 }, -/* ABORT_R */{ 0, 0, 0, 0, 4, 0, 4, 0, 0, 0, 0x82, 0x82, 0x82, 0x82, 3, 3, 1 }, -/* OK_C */{ 0, 1, 3, 0, 0, 1, 0, 0x83, 0x83, 0x83, 0x83, 0x83, 0, 0, 0x83, 0x83, 3 }, -/* CONT_C */{ 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 1, 1, 0, 0, 4, 4, 3 }, -/* FAIL_C */{ 0, 4, 1, 0, 0, 0x87, 0, 0x86, 0x86, 2, 0x86, 0x86, 0, 0, 0x86, 0x86, 3 }, -/* PORT_CLS */{ 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84 }, -/* TX_EMPTY */{ 0x87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* FCS_SET */{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, -/* STATE */{ 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85 }, -/* TIMEOUT */{ 3, 2, 0x87, 0, 0, 0x87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } -}; - -static const UINT8 obx_cl_all_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* DISCNT_R */{OBX_CA_SND_REQ, OBX_CS_DISCNT_REQ_SENT }, -/* ABORT_R */{OBX_CA_SND_REQ, OBX_CS_ABORT_REQ_SENT }, -/* OK_C */{OBX_CA_NOTIFY, OBX_CS_NULL }, -/* PORT_CLS */{OBX_CA_CONNECT_ERROR, OBX_CS_NOT_CONNECTED }, -/* STATE */{OBX_CA_STATE, OBX_CS_NULL }, -/* FAIL_C */{OBX_CA_FAIL_RSP, OBX_CS_NULL }, -/* end */{OBX_CA_CLOSE_PORT, OBX_CS_NOT_CONNECTED } -}; - -static const UINT8 obx_cl_not_conn_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONN_R */{OBX_CA_SND_REQ, OBX_CS_CONNECT_REQ_SENT }, -/* SESS_R */{OBX_CA_SND_REQ, OBX_CS_SESSION_REQ_SENT }, -/* TIMEOUT */{OBX_CA_SESSION_FAIL, OBX_CS_NOT_CONNECTED } -}; - -static const UINT8 obx_cl_sess_rs_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* OK_C */{OBX_CA_SESSION_OK, OBX_CS_NOT_CONNECTED }, -/* CONT_C */{OBX_CA_SESSION_CONT, OBX_CS_SESSION_REQ_SENT }, -/* GET_R */{OBX_CA_SESSION_GET, OBX_CS_SESSION_REQ_SENT }, -/* FAIL_C */{OBX_CA_SESSION_FAIL, OBX_CS_NOT_CONNECTED } -}; - -static const UINT8 obx_cl_conn_rs_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* FAIL_C */{OBX_CA_CONNECT_FAIL, OBX_CS_UNAUTH }, -/* DISCNT_R */{OBX_CA_DISCNT_REQ, OBX_CS_NULL }, -/* OK_C */{OBX_CA_CONNECT_OK, OBX_CS_NULL } -}; - -static const UINT8 obx_cl_unauth_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONN_R */{OBX_CA_SND_REQ, OBX_CS_CONNECT_REQ_SENT } -}; - -static const UINT8 obx_cl_conn_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* PUT_R */{OBX_CA_SND_PUT_REQ, OBX_CS_PUT_REQ_SENT }, -/* GET_R */{OBX_CA_SND_GET_REQ, OBX_CS_GET_REQ_SENT }, -/* SETPATH_R*/{OBX_CA_SND_REQ, OBX_CS_SETPATH_REQ_SENT }, -/* ABORT_R */{OBX_CA_ABORT, OBX_CS_CONNECTED }, -/* SESS_R */{OBX_CA_SND_REQ, OBX_CS_SESSION_REQ_SENT }, -/* ACT_R */{OBX_CA_SND_REQ, OBX_CS_ACTION_REQ_SENT } -}; - -static const UINT8 obx_cl_discnt_rs_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* OK_C */{OBX_CA_NOTIFY, OBX_CS_NOT_CONNECTED }, /* and close port */ -/* CONT_C */{OBX_CA_START_TIMER, OBX_CS_DISCNT_REQ_SENT } -}; - -static const UINT8 obx_cl_op_unauth_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* PUT_R */{OBX_CA_SND_REQ, OBX_CS_PUT_REQ_SENT }, -/* GET_R */{OBX_CA_SND_REQ, OBX_CS_GET_REQ_SENT }, -/* SETPATH_R*/{OBX_CA_SND_REQ, OBX_CS_SETPATH_REQ_SENT }, -/* ABORT_R */{OBX_SM_NO_ACTION, OBX_CS_CONNECTED }, -/* ACT_R */{OBX_CA_SND_REQ, OBX_CS_ACTION_REQ_SENT } -}; - -/* static const UINT8 obx_cl_setpath_rs_table[][OBX_SM_NUM_COLS] = { */ -/* Event Action Next State */ -/* DISCNT_R {OBX_CA_SND_REQ, OBX_CS_DISCNT_REQ_SENT },*/ -/* OK_C {OBX_CA_NOTIFY, OBX_CS_NULL },*/ -/* FAIL_C {OBX_CA_FAIL_RSP, OBX_CS_NULL },*/ -/* PORT_CLS {OBX_CA_CONNECT_ERROR, OBX_CS_NOT_CONNECTED },*/ -/* STATE {OBX_CA_STATE, OBX_CS_NULL },*/ -/* }; */ - -static const UINT8 obx_cl_abort_rs_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONT_C */{OBX_CA_START_TIMER, OBX_CS_ABORT_REQ_SENT }, -/* FAIL_C */{OBX_CA_NOTIFY, OBX_CS_CONNECTED } -}; - -static const UINT8 obx_cl_put_rs_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONT_C */{OBX_CA_NOTIFY, OBX_CS_PUT_TRANSACTION }, -/* SESS_R */{OBX_CA_SND_REQ, OBX_CS_SESSION_REQ_SENT } -}; - -static const UINT8 obx_cl_get_rs_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONT_C */{OBX_CA_NOTIFY, OBX_CS_GET_TRANSACTION }, -/* SESS_R */{OBX_CA_SND_REQ, OBX_CS_SESSION_REQ_SENT } -}; - -static const UINT8 obx_cl_put_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* PUT_R */{OBX_CA_SND_REQ, OBX_CS_PUT_REQ_SENT }, -/* SESS_R */{OBX_CA_SND_REQ, OBX_CS_SESSION_REQ_SENT } -}; - -static const UINT8 obx_cl_get_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* GET_R */{OBX_CA_SND_REQ, OBX_CS_GET_REQ_SENT }, -/* SESS_R */{OBX_CA_SND_REQ, OBX_CS_SESSION_REQ_SENT } -}; - -static const UINT8 obx_cl_put_s_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* DISCNT_R */{OBX_CA_SRM_SND_REQ, OBX_CS_DISCNT_REQ_SENT }, -/* PUT_R */{OBX_CA_SRM_PUT_REQ, OBX_CS_PUT_SRM }, -/* ABORT_R */{OBX_CA_SRM_SND_REQ, OBX_CS_ABORT_REQ_SENT }, -/* CONT_C */{OBX_CA_SRM_PUT_NOTIFY, OBX_CS_PUT_SRM }, -/* SESS_R */{OBX_CA_SND_REQ, OBX_CS_SESSION_REQ_SENT } -}; - -static const UINT8 obx_cl_get_s_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* DISCNT_R */{OBX_CA_SRM_SND_REQ, OBX_CS_DISCNT_REQ_SENT }, -/* GET_R */{OBX_CA_SRM_GET_REQ, OBX_CS_GET_SRM }, -/* ABORT_R */{OBX_CA_SRM_SND_REQ, OBX_CS_ABORT_REQ_SENT }, -/* CONT_C */{OBX_CA_SRM_GET_NOTIFY, OBX_CS_GET_SRM }, -/* SESS_R */{OBX_CA_SND_REQ, OBX_CS_SESSION_REQ_SENT } -}; - -static const UINT8 obx_cl_part_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* ABORT_R */{OBX_CA_SAVE_REQ, OBX_CS_PARTIAL_SENT }, -/* FCS_SET */{OBX_CA_SND_PART, OBX_CS_NULL }, -/* FAIL_C */{OBX_CA_SAVE_RSP, OBX_CS_NULL } -}; - -static const tOBX_SM_TBL obx_cl_main_state_table[] = { - obx_cl_not_conn_table, - obx_cl_sess_rs_table, - obx_cl_conn_rs_table, - obx_cl_unauth_table, - obx_cl_conn_table, - obx_cl_discnt_rs_table, - obx_cl_op_unauth_table, - NULL, /* obx_cl_setpath_rs_table */ - NULL, /* obx_cl_action_rs_table */ - obx_cl_abort_rs_table, - obx_cl_put_rs_table, - obx_cl_get_rs_table, - obx_cl_put_table, - obx_cl_get_table, - obx_cl_put_s_table, - obx_cl_get_s_table, - obx_cl_part_table -}; - -/******************************************************************************* -** -** Function obx_csm_event -** -** Description Handle events to the client state machine. It looks up the entry -** in the obx_csm_entry_map array. If it is a valid entry, it gets -** the state table. Set the next state, if not NULL state.Execute -** the action function according to the state table. If the state -** returned by action function is not NULL state, adjust the new -** state to the returned state.If (api_evt != MAX), call callback -** function. -** -** Returns void. -** -*******************************************************************************/ -void obx_csm_event(tOBX_CL_CB *p_cb, tOBX_CL_EVENT event, BT_HDR *p_msg) -{ - UINT8 curr_state = p_cb->state; - tOBX_SM_TBL state_table = NULL; - UINT8 action, entry; - tOBX_CL_STATE act_state = OBX_CS_NULL; - UINT8 prev_state = OBX_CS_NULL; - - if( curr_state == OBX_CS_NULL || curr_state >= OBX_CS_MAX) - { - OBX_TRACE_WARNING1( "Invalid state: %d", curr_state) ; - if(p_msg) - GKI_freebuf(p_msg); - return; - } - OBX_TRACE_DEBUG4( "Client Handle 0x%x, State: %s, event: %s srm:0x%x", - p_cb->ll_cb.comm.handle, obx_cl_get_state_name( p_cb->state ), obx_cl_get_event_name(event), p_cb->srm ) ; - OBX_TRACE_DEBUG1("obx_csm_event csm offset:%d", p_cb->param.sess.obj_offset); - - /* look up the state table for the current state */ - /* lookup entry /w event & curr_state */ - /* If entry is ignore, return. - * Otherwise, get state table (according to curr_state or all_state) */ - if( (entry = obx_csm_entry_map[event][curr_state-1]) != OBX_SM_IGNORE ) - { - if(entry&OBX_SM_ALL) - { - entry &= OBX_SM_ENTRY_MASK; - state_table = obx_cl_all_table; - } - else - state_table = obx_cl_main_state_table[curr_state-1]; - } - - if( entry == OBX_SM_IGNORE || state_table == NULL) - { - OBX_TRACE_WARNING4( "Ignore event %s(%d) in state %s(%d)", - obx_cl_get_event_name(event), event, obx_cl_get_state_name(curr_state), curr_state ); - if(p_msg) - GKI_freebuf(p_msg); - return; - } - - /* Get possible next state from state table. */ - if( state_table[entry-1][OBX_SME_NEXT_STATE] != OBX_CS_NULL ) - { - prev_state = p_cb->state; - p_cb->state = state_table[entry-1][OBX_SME_NEXT_STATE]; - if (prev_state != p_cb->state) - { - p_cb->prev_state = prev_state; - OBX_TRACE_DEBUG1( "saved state1:%s", obx_cl_get_state_name(p_cb->prev_state)); - } - } - OBX_TRACE_DEBUG1( "possible new state = %s", obx_cl_get_state_name( p_cb->state ) ) ; - - /* If action is not ignore, clear param, exec action and get next state. - * The action function may set the Param for cback. - * Depending on param, call cback or free buffer. */ - /* execute action */ - action = state_table[entry-1][OBX_SME_ACTION]; - if (action != OBX_SM_NO_ACTION) - { - act_state = (*obx_cl_action[action])(p_cb, p_msg); - } - - /* adjust next state, if it needs to use the new state returned from action function */ - if( act_state != OBX_CS_NULL) - { - prev_state = p_cb->state; - p_cb->state = act_state; - OBX_TRACE_DEBUG1( "new state = %s (action)", obx_cl_get_state_name( p_cb->state )) ; - if (prev_state != p_cb->state) - { - p_cb->prev_state = prev_state; - OBX_TRACE_DEBUG1( "saved state2:%s", obx_cl_get_state_name(p_cb->prev_state)); - } - } - - if(p_cb->api_evt) - { - (p_cb->p_cback) (p_cb->ll_cb.comm.handle, p_cb->api_evt, p_cb->rsp_code, p_cb->param, p_msg); - p_cb->api_evt = OBX_NULL_EVT; - p_cb->rsp_code = 0; - memset(&p_cb->param, 0, sizeof (p_cb->param) ); - } - else if(action == OBX_SM_NO_ACTION && p_msg) - GKI_freebuf(p_msg); - OBX_TRACE_DEBUG1("after csm offset:%d", p_cb->param.sess.obj_offset); - - OBX_TRACE_DEBUG2( "result state = %s/%d", obx_cl_get_state_name( p_cb->state ), p_cb->state ) ; -} - - diff --git a/stack/obx/obx_int.h b/stack/obx/obx_int.h deleted file mode 100644 index 8d4a7f6..0000000 --- a/stack/obx/obx_int.h +++ /dev/null @@ -1,602 +0,0 @@ -/***************************************************************************** -** -** Name: obx_int.h -** -** File: OBEX Internal header file -** -** Copyright (c) 2003-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#ifndef OBX_INT_H -#define OBX_INT_H - -#include "bt_target.h" -#include "obx_api.h" -#include "gki.h" - -#define OBX_DEFAULT_TARGET_LEN 0xFF -#define OBX_INITIAL_CONN_ID 0x1 - -/* the rules for OBX handles: (some of the definitions are in obx_api.h) - * - * tOBX_HANDLE is UINT16 - * It was UINT8, the support for multiple clients on the same SCN for MAP is required - * - * LSB (0x00FF) is the same as the old definition. - * The 0x80 bit (OBX_CL_HANDLE_MASK) is set for client connections. - * The 0x40 bit (OBX_HANDLE_RX_MTU_MASK) is used internally for RFCOMM to allocate a buffer to receive data - * - * The MSB (0xFF00) is used for enhancements add for BTE release 3.15 - * This byte is the session index; used for server only. - */ - -#define OBX_CL_HANDLE_MASK 0x80 -#define OBX_CL_CB_IND_MASK 0x007F -#define OBX_HANDLE_RX_MTU_MASK 0x40 -#define OBX_LOCAL_NONCE_SIZE OBX_MIN_NONCE_SIZE /* 4 - 16 per IrOBEX spec. local nonce is always 4 */ - -#define OBX_MAX_EVT_MAP_NUM (OBX_ABORT_REQ_SEVT+1) - -#define OBX_PORT_EVENT_MASK (PORT_EV_RXCHAR | PORT_EV_TXEMPTY | \ - PORT_EV_FC | PORT_EV_FCS) - -#define OBX_BAD_SM_EVT 0xFF - -/* for wait_auth flag */ -#define OBX_WAIT_AUTH_FAIL 2 - -enum -{ - OBX_CS_NULL, /* 0 0 */ - OBX_CS_NOT_CONNECTED, /* 1 1 */ - OBX_CS_SESSION_REQ_SENT, /* 2 */ - OBX_CS_CONNECT_REQ_SENT, /* 3 2 */ - OBX_CS_UNAUTH, /* 4 3 */ - OBX_CS_CONNECTED, /* 5 4 */ - OBX_CS_DISCNT_REQ_SENT, /* 6 5 */ - OBX_CS_OP_UNAUTH, /* 7 6 */ - OBX_CS_SETPATH_REQ_SENT, /* 8 7 */ - OBX_CS_ACTION_REQ_SENT, /* 9 */ - OBX_CS_ABORT_REQ_SENT, /*10 8 */ - OBX_CS_PUT_REQ_SENT, /*11 9 */ - OBX_CS_GET_REQ_SENT, /*12 10 */ - OBX_CS_PUT_TRANSACTION, /*13 11 */ - OBX_CS_GET_TRANSACTION, /*14 12 */ - OBX_CS_PUT_SRM, /*15 */ - OBX_CS_GET_SRM, /*16 */ - OBX_CS_PARTIAL_SENT, /*17 13 */ - OBX_CS_MAX -}; - -typedef UINT8 tOBX_CL_STATE; -#define OBX_CL_STATE_DROP 0x80 /* this is used only in session_info[] to mark link drop suspend*/ - -enum -{ - OBX_CONNECT_REQ_CEVT, /* API call to send a CONNECT request. */ - OBX_SESSION_REQ_CEVT, /* API call to send a SESSION request. */ - OBX_DISCNT_REQ_CEVT, /* API call to send a DISCONNECT request. */ - OBX_PUT_REQ_CEVT, /* API call to send a PUT request. */ - OBX_GET_REQ_CEVT, /* API call to send a GET request.*/ - OBX_SETPATH_REQ_CEVT, /* API call to send a SETPATH request. */ - OBX_ACTION_REQ_CEVT, /* API call to send an ACTION request. */ - OBX_ABORT_REQ_CEVT, /* API call to send an ABORT request. */ - OBX_OK_CFM_CEVT, /* Received success response from server. */ - OBX_CONT_CFM_CEVT, /* Received continue response from server. */ - OBX_FAIL_CFM_CEVT, /* Received failure response from server. */ - OBX_PORT_CLOSE_CEVT, /* Transport is closed. */ - OBX_TX_EMPTY_CEVT, /* Transmit Queue Empty */ - OBX_FCS_SET_CEVT, /* Data flow enable */ - OBX_STATE_CEVT, /* Change state. */ - OBX_TIMEOUT_CEVT, /* Timeout occurred. */ - OBX_MAX_CEVT -}; -typedef UINT8 tOBX_CL_EVENT; - -#define OBX_MAX_API_CEVT OBX_ABORT_REQ_CEVT - -enum -{ - OBX_CONNECT_REQ_SEVT, /* 1 1 Received CONNECT request from client. */ - OBX_SESSION_REQ_SEVT, /* 2 Received SESSION request from client. */ - OBX_DISCNT_REQ_SEVT, /* 3 2 Received DISCONNECT request from client. */ - OBX_PUT_REQ_SEVT, /* 4 3 Received PUT request from client. */ - OBX_GET_REQ_SEVT, /* 5 4 Received GET request from client. */ - OBX_SETPATH_REQ_SEVT, /* 6 5 Received SETPATH request from client. */ - OBX_ACTION_REQ_SEVT, /* 7 Received ACTION request from client. */ - OBX_ABORT_REQ_SEVT, /* 8 6 Received ABORT request from client. */ - OBX_CONNECT_CFM_SEVT, /* 9 7 API call to send a CONNECT response. */ - OBX_SESSION_CFM_SEVT, /*10 API call to send a SESSION response. */ - OBX_DISCNT_CFM_SEVT, /*11 8 API call to send a DISCONNECT response or close the connection to the client. */ - OBX_PUT_CFM_SEVT, /*12 9 API call to send a PUT response. */ - OBX_GET_CFM_SEVT, /*13 10 API call to send a GET response. */ - OBX_SETPATH_CFM_SEVT, /*14 11 API call to send a SETPATH response. */ - OBX_ACTION_CFM_SEVT, /*15 API call to send an ACTION response. */ - OBX_ABORT_CFM_SEVT, /*16 12 API call to send an ABORT response. */ - OBX_PORT_CLOSE_SEVT, /*17 13 Transport is closed. */ - OBX_FCS_SET_SEVT, /*18 14 Data flow enable */ - OBX_STATE_SEVT, /*19 15 Change state. */ - OBX_TIMEOUT_SEVT, /*20 16 Timeout has occurred. */ - OBX_BAD_REQ_SEVT, /*21 17 Received a bad request from client. */ - OBX_TX_EMPTY_SEVT, /*22 18 Transmit Queue Empty */ - OBX_MAX_SEVT -}; -typedef UINT8 tOBX_SR_EVENT; - -#define OBX_SEVT_DIFF_REQ_CFM (OBX_CONNECT_CFM_SEVT - OBX_CONNECT_REQ_SEVT) /* the index difference between *REQ_SEVT and *CFM_SEVT */ -#define OBX_SEVT_MAX_REQ OBX_ACTION_REQ_SEVT /* last *REQ_SEVT */ - -enum -{ - OBX_SS_NULL, /* 0 0 */ - OBX_SS_NOT_CONNECTED, /* 1 1 */ - OBX_SS_SESS_INDICATED, /* 2 */ - OBX_SS_CONN_INDICATED, /* 3 2 */ - OBX_SS_WAIT_AUTH, /* 4 3 */ - OBX_SS_AUTH_INDICATED, /* 5 4 */ - OBX_SS_CONNECTED, /* 6 5 */ - OBX_SS_DISCNT_INDICATED, /* 7 6 */ - OBX_SS_SETPATH_INDICATED, /* 8 7 */ - OBX_SS_ACTION_INDICATED, /* 9 */ - OBX_SS_ABORT_INDICATED, /*10 8 */ - OBX_SS_PUT_INDICATED, /*11 9 */ - OBX_SS_GET_INDICATED, /*12 10 */ - OBX_SS_PUT_TRANSACTION, /*13 11 */ - OBX_SS_GET_TRANSACTION, /*14 12 */ - OBX_SS_PUT_SRM, /*15 */ - OBX_SS_GET_SRM, /*16 */ - OBX_SS_PARTIAL_SENT, /*17 13 */ - OBX_SS_WAIT_CLOSE, /*18 14 */ - OBX_SS_MAX -}; -typedef UINT8 tOBX_SR_STATE; - -typedef UINT8 tOBX_STATE; /* this must be the same type as tOBX_SR_STATE and tOBX_CL_STATE */ - -typedef struct -{ - UINT16 pkt_len;/* the packet length */ - UINT8 code; /* the response/request code with the final bit */ - UINT8 sm_evt; /* The state machine event*/ -} tOBX_RX_HDR; - -typedef void (tOBX_CLOSE_FN) (UINT16); -typedef BOOLEAN (tOBX_SEND_FN) (void *p_cb); -typedef UINT8 (*tOBX_VERIFY_OPCODE)(UINT8 opcode, tOBX_RX_HDR *p_rxh); - -#define OBX_SRM_NO 0x00 /* SRM is not enabled and not engaged */ -#define OBX_SRM_ENABLE 0x01 /* SRM is enabled. */ -#define OBX_SRM_PARAM_AL 0x02 /* SRMP is allowed only in the beginning of a transaction */ -#define OBX_SRM_REQING 0x04 /* requesting/requested to enable SRM. */ -#define OBX_SRM_ABORT 0x08 /* (server) abort/reject at SRM GET/PUT rsp API*/ -#define OBX_SRM_ENGAGE 0x10 /* SRM is engaged. */ -#define OBX_SRM_NEXT 0x20 /* peer is ready for next packet. */ -#define OBX_SRM_WAIT 0x40 /* wait for peer. */ -#define OBX_SRM_WAIT_UL 0x80 /* wait for upper layer. */ -typedef UINT8 tOBX_SRM; - -#define OBX_SRMP_WAIT 0x40 /* wait for peer */ -#define OBX_SRMP_NONF 0x80 /* handle GET non-final (used by server only) */ -#define OBX_SRMP_NONF_EVT 0x20 /* report GET non-final req event (used by server only) */ -#define OBX_SRMP_SESS_FST 0x01 /* mark the session resume. The SSN on first req might not match */ -typedef UINT8 tOBX_SRMP; - -/* continue to define tOBX_SESS_ST for internal use */ -enum -{ - OBX_SESS_TIMEOUT = OBX_SESS_EXT_MAX, /* 0x03 session is requested/set timeout. */ - OBX_SESS_CREATE, /* 0x04 session is requested/create. */ - OBX_SESS_SUSPEND, /* 0x05 session is requested/suspend. */ - OBX_SESS_RESUME, /* 0x06 session is requested/resume. */ - OBX_SESS_CLOSE, /* 0x07 session is requested/close. */ - OBX_SESS_SUSPENDING /* 0x08 session is requested/suspend: server has not reported the suspend event */ -}; -#define OBX_SESS_DROP (0x80|OBX_SESS_SUSPENDED) /* the session as suspended by link drop */ - -/* port control block */ -typedef struct -{ - tOBX_HANDLE handle; /* The handle of the client or session handle for server */ - UINT16 port_handle; /* Port handle of connection */ - UINT16 tx_mtu; /* The MTU of the connected peer */ - UINT16 rx_mtu; /* The MTU of this instance */ - TIMER_LIST_ENT tle; /* This session's Timer List Entry */ - tOBX_CLOSE_FN *p_close_fn; /* the close connection function */ - tOBX_SEND_FN *p_send_fn; /* the send message function */ - BT_HDR *p_txmsg; /* The message to send to peer */ - BUFFER_Q rx_q; /* received data buffer queue */ - BOOLEAN stopped; /* TRUE, if flow control the peer (stop peer from sending more data). */ - BT_HDR *p_rxmsg; /* The message received from peer */ -} tOBX_PORT_CB; - -typedef struct -{ - tOBX_PORT_CB *p_pcb; /* the port control block */ - UINT32 code; /* the event code from RFCOMM */ -} tOBX_PORT_EVT; - -/* l2cap control block */ -typedef struct -{ - tOBX_HANDLE handle; /* The handle of the client or session handle for server */ - UINT16 lcid; /* l2cap lcid of connection */ - UINT16 tx_mtu; /* The MTU of the connected peer */ - UINT16 rx_mtu; /* The MTU of this instance */ - TIMER_LIST_ENT tle; /* This session's Timer List Entry */ - tOBX_CLOSE_FN *p_close_fn; /* the close connection function */ - tOBX_SEND_FN *p_send_fn; /* the send message function */ - BT_HDR *p_txmsg; /* The message to send to peer */ - BUFFER_Q rx_q; /* received data buffer queue */ - BOOLEAN stopped; /* TRUE, if flow control the peer (stop peer from sending more data). */ - UINT8 ch_state; /* L2CAP channel state */ - UINT8 ch_flags; /* L2CAP configuration flags */ - BOOLEAN cong; /* TRUE, if L2CAP is congested. */ -} tOBX_L2C_CB; - -enum -{ - OBX_L2C_EVT_CONG, - OBX_L2C_EVT_CLOSE, - OBX_L2C_EVT_CONN_IND, - OBX_L2C_EVT_DATA_IND, - OBX_L2C_EVT_RESUME -}; -typedef UINT8 tOBX_L2C_EVT; - -typedef struct -{ - BD_ADDR bd_addr; - UINT16 lcid; - UINT16 psm; - UINT8 id; -} tOBX_L2C_IND; - -typedef union -{ - tOBX_L2C_IND conn_ind; - BOOLEAN is_cong; - BT_HDR *p_pkt; - UINT8 any; - BD_ADDR remote_addr; -} tOBX_L2C_EVT_PARAM; - -typedef struct -{ - tOBX_L2C_CB *p_l2cb; /* the L2CAP control block */ - tOBX_L2C_EVT_PARAM param; - tOBX_L2C_EVT l2c_evt; /* the event code from L2CAP */ -} tOBX_L2C_EVT_MSG; - -/* common of port & l2cap control block */ -typedef struct -{ - tOBX_HANDLE handle; /* The handle of the client or session handle for server */ - UINT16 id; /* l2cap lcid or port handle */ - UINT16 tx_mtu; /* The MTU of the connected peer */ - UINT16 rx_mtu; /* The MTU of this instance */ - TIMER_LIST_ENT tle; /* This session's Timer List Entry */ - tOBX_CLOSE_FN *p_close_fn; /* the close connection function */ - tOBX_SEND_FN *p_send_fn; /* the send message function */ - BT_HDR *p_txmsg; /* The message to send to peer */ - BUFFER_Q rx_q; /* received data buffer queue */ - BOOLEAN stopped; /* TRUE, if flow control the peer (stop peer from sending more data). */ -} tOBX_COMM_CB; - -/* lower layer control block */ -typedef union -{ - tOBX_PORT_CB port; - tOBX_L2C_CB l2c; - tOBX_COMM_CB comm; -} tOBX_LL_CB; - -/* client control block */ -typedef struct -{ - tOBX_CL_CBACK *p_cback; /* Application callback function to receive events */ - BT_HDR *p_next_req; /* This is used when the session is flow controlled by peer - * and a DISCONNECT or ABORT request is sent.*/ - BT_HDR *p_saved_req; /* Client saves a copy of the request sent to the server - * Just in case the operation is challenged by the server */ - BT_HDR *p_auth; /* The request-digest string, if challenging the server. - * The received OBEX packet, if waiting for password */ - tOBX_LL_CB ll_cb; /* lower layer control block for this client */ - UINT32 conn_id; /* Connection ID for this connection */ - UINT32 nonce; /* This is converted to UINT8[16] internally before adding to the OBEX header. This value is copied to the server control block and is increased after each use. 0, if only legacy OBEX (unreliable) session is desired. */ - BD_ADDR peer_addr; /* peer address */ - tOBX_EVT_PARAM param; /* The event parameter. */ - UINT8 sess_info[OBX_SESSION_INFO_SIZE]; /* session id + local nonce */ - tOBX_EVENT api_evt; /* Set the API event, if need to notify user outside of action function. */ - tOBX_CL_STATE state; /* The current state */ - tOBX_STATE next_state; /* Use by PART state to return to regular states */ - tOBX_CL_STATE prev_state; /* The previous state */ - UINT16 psm; /* L2CAP virtual psm */ - tOBX_SRM srm; /* Single Response Mode */ - tOBX_SRMP srmp; /* Single Response Mode Parameter */ - UINT8 ssn; /* Session Sequence number */ - tOBX_SESS_ST sess_st; /* Session state */ - UINT8 rsp_code; /* The response code of the response packet */ - BOOLEAN final; /* The final bit status of last request */ - BOOLEAN wait_auth; /* TRUE, if challenges the server and is waiting for the response */ -} tOBX_CL_CB; - -/* Authentication Control block */ -typedef struct -{ - UINT32 nonce; /* Timestamp used as nonce */ - tOBX_AUTH_OPT auth_option; /* Authentication option */ - UINT8 realm_len; /* The length of p_realm */ - UINT8 realm[1]; /* The realm of this server. Charset is the first byte */ -} tOBX_AUTH_PARAMS; - -/* suspend control block */ -typedef struct -{ - TIMER_LIST_ENT stle; /* The timer for suspended session timeout */ - BD_ADDR peer_addr; /* peer address */ - UINT8 sess_info[OBX_SESSION_INFO_SIZE]; /* session id + local nonce + conn id + state + srm */ - UINT32 offset; /* the file offset */ - tOBX_SR_STATE state; /* The current state */ - UINT8 ssn; /* the last ssn */ -} tOBX_SPND_CB; - -/* server control block */ -typedef struct -{ - tOBX_SR_CBACK *p_cback; /* Application callback function to receive events */ - tOBX_TARGET target; /* target header of this server */ - tOBX_AUTH_PARAMS *p_auth; /* A GKI buffer that holds the authentication related parameters */ - UINT8 sess[OBX_MAX_SR_SESSION]; /* index + 1 of sr_sess[]. 0, if not used. */ - tOBX_SPND_CB *p_suspend; /* the information for suspended sessions (GKI buffer) */ - UINT32 nonce; /* This is converted to UINT8[16] internally before adding to the OBEX header. This value is copied to the server control block and is increased after each use. 0, if only legacy OBEX (unreliable) session is desired. */ - UINT16 psm; /* PSM for this server */ - UINT8 max_suspend; /* the max number of tOBX_SPD_CB[] in p_suspend. must be less than OBX_MAX_SUSPEND_SESSIONS */ - UINT8 scn; /* SCN for this server */ - UINT8 num_sess; /* Max number of session control blocks used by this server*/ -} tOBX_SR_CB; - -/* server session control block */ -typedef struct -{ - BT_HDR *p_saved_msg; /* This is a message saved for authentication or GetReq-non-final */ - BT_HDR *p_next_req; /* This is a message saved for flow control reasons */ - tOBX_LL_CB ll_cb; /* lower layer control block for this session */ - UINT32 conn_id; /* Connection ID for this connection */ - BD_ADDR peer_addr; /* peer address */ - UINT8 sess_info[OBX_SESSION_INFO_SIZE]; /* session id + local nonce */ - tOBX_SR_STATE state; /* The current state */ - tOBX_SR_STATE prev_state; /* The previous state */ - tOBX_STATE next_state; /* Use by PART state to return to regular states */ - tOBX_HANDLE handle; /* The obx handle for server */ - tOBX_EVENT api_evt; /* The event to notify the API user. */ - tOBX_EVT_PARAM param; /* The event parameter. */ - tOBX_SRMP srmp; /* Single Response Mode Parameter */ - tOBX_SRM srm; /* Single Response Mode */ - tOBX_SESS_ST sess_st; /* Session state */ - UINT8 ssn; /* Next Session Sequence number */ - UINT8 cur_op; /* The op code for the current transaction (keep this for Abort reasons) */ - /* set to the current OP (non-abort) in rfc.c, set it to abort when a response is sent */ -} tOBX_SR_SESS_CB; - -typedef struct -{ -#if (OBX_SERVER_INCLUDED == TRUE) - tOBX_SR_CB server[OBX_NUM_SERVERS];/* The server control blocks */ - UINT32 next_cid; /* Next OBEX connection ID for server */ - tOBX_SR_SESS_CB sr_sess[OBX_NUM_SR_SESSIONS]; - tOBX_L2C_CB sr_l2cb; /* for obx_l2c_connect_ind_cback */ -#endif - -#if (OBX_CLIENT_INCLUDED == TRUE) - tOBX_CL_CB client[OBX_NUM_CLIENTS];/* The client control blocks */ - tOBX_PORT_CB *p_temp_pcb; /* Valid only during client RFCOMM_CreateConnection call */ - UINT8 next_ind; /* The index to the next client control block */ -#endif - - tOBX_HANDLE hdl_map[MAX_RFC_PORTS]; /* index of this array is the port_handle, - * the value is the OBX handle */ - UINT16 l2c_map[MAX_L2CAP_CHANNELS]; /* index of this array is (lcid - L2CAP_BASE_APPL_CID) */ - UINT32 timeout_val; /* The timeout value to wait for activity from peer */ - UINT32 sess_tout_val; /* The timeout value for reliable sessions to remain in suspend */ - UINT8 trace_level; /* The default trace level */ - UINT8 num_client; /* Number of client control blocks */ - UINT8 num_server; /* Number of server control blocks */ - UINT8 num_sr_sess; /* Number of server session control blocks */ - UINT8 max_rx_qcount; /* Max Number of rx_q count */ -} tOBX_CB; - -/***************************************************************************** -** Definition for State Machine -*****************************************************************************/ - -/* Client Action functions are of this type */ -typedef tOBX_CL_STATE (*tOBX_CL_ACT)(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); - -/* Server Action functions are of this type */ -typedef tOBX_SR_STATE (*tOBX_SR_ACT)(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); - -#define OBX_SM_IGNORE 0 -#define OBX_SM_NO_ACTION 0xFF -#define OBX_SM_ALL 0x80 /* for events like close confirm, abort request, close request where event handling is the same for most of the states */ -#define OBX_SM_ENTRY_MASK 0x7F /* state machine entry mask */ - -#define OBX_SME_ACTION 0 -#define OBX_SME_NEXT_STATE 1 -#define OBX_SM_NUM_COLS 2 - -typedef const UINT8 (*tOBX_SM_TBL)[OBX_SM_NUM_COLS]; - -/***************************************************************************** -** External global data -*****************************************************************************/ -#if OBX_DYNAMIC_MEMORY == FALSE -OBX_API extern tOBX_CB obx_cb; -#else -OBX_API extern tOBX_CB *obx_cb_ptr; -#define obx_cb (*obx_cb_ptr) -#endif -extern const tOBX_EVENT obx_sm_evt_to_api_evt[]; -extern const UINT8 obx_hdr_start_offset[]; -/***************************************************************************** -** External Function Declarations -*****************************************************************************/ -/* from obx_main.c */ - -#if (defined (BT_USE_TRACES) && BT_USE_TRACES == TRUE && OBX_CLIENT_INCLUDED == TRUE) -extern const char * obx_cl_get_state_name(tOBX_CL_STATE state); -extern const char * obx_cl_get_event_name(tOBX_CL_EVENT event); -#else -#define obx_cl_get_state_name(state_num) "" -#define obx_cl_get_event_name(event_num) "" -#endif - -#if (defined (BT_USE_TRACES) && BT_USE_TRACES == TRUE && OBX_SERVER_INCLUDED == TRUE) -extern const char * obx_sr_get_state_name(tOBX_SR_STATE state); -extern const char * obx_sr_get_event_name(tOBX_SR_EVENT event); -#else -#define obx_sr_get_state_name(state_num) "" -#define obx_sr_get_event_name(event_num) "" -#endif -/* client functions in obx_main.c */ -extern void obx_cl_timeout(TIMER_LIST_ENT *p_tle); -extern tOBX_CL_CB * obx_cl_alloc_cb(void); -extern tOBX_CL_CB * obx_cl_get_cb(tOBX_HANDLE handle); -extern tOBX_CL_CB * obx_cl_get_suspended_cb(tOBX_HANDLE *p_handle, UINT8 *p_session_info); -extern void obx_cl_free_cb(tOBX_CL_CB * p_cb); - -/* server functions in obx_main.c */ -extern tOBX_SPND_CB * obx_find_suspended_session (tOBX_SR_SESS_CB *p_scb, tOBX_TRIPLET *p_triplet, UINT8 num); -extern void obx_l2c_snd_evt (tOBX_L2C_CB *p_l2cb, tOBX_L2C_EVT_PARAM param, tOBX_L2C_EVT l2c_evt); -extern void obx_sr_timeout(TIMER_LIST_ENT *p_tle); -extern void obx_sr_sess_timeout(TIMER_LIST_ENT *p_tle); -extern tOBX_HANDLE obx_sr_alloc_cb(tOBX_StartParams *p_params); -extern tOBX_SR_CB * obx_sr_get_cb(tOBX_HANDLE handle); -extern tOBX_SR_SESS_CB * obx_sr_get_scb(tOBX_HANDLE handle); -extern void obx_sr_free_cb(tOBX_HANDLE handle); -extern void obx_sr_free_scb(tOBX_SR_SESS_CB *p_scb); -extern UINT32 obx_sr_get_next_conn_id(void); -/* common functions in obx_main.c */ -extern tOBX_PORT_CB * obx_port_handle_2cb(UINT16 port_handle); -extern void obx_start_timer(tOBX_COMM_CB *p_pcb); -extern void obx_stop_timer(TIMER_LIST_ENT *p_tle); - -/* from obx_rfc.c */ -extern void obx_cl_proc_evt(tOBX_PORT_EVT *p_evt); -extern BT_HDR * obx_build_dummy_rsp(tOBX_SR_SESS_CB *p_scb, UINT8 rsp_code); -extern void obx_sr_proc_evt(tOBX_PORT_EVT *p_evt); -extern BOOLEAN obx_rfc_snd_msg(tOBX_PORT_CB *p_pcb); -extern tOBX_STATUS obx_open_port(tOBX_PORT_CB *p_pcb, const BD_ADDR bd_addr, UINT8 scn); -extern void obx_add_port(tOBX_HANDLE obx_handle); -extern void obx_close_port(UINT16 port_handle); - -/* from obx_capi.c */ -extern tOBX_STATUS obx_prepend_req_msg(tOBX_HANDLE handle, tOBX_CL_EVENT event, UINT8 req_code, BT_HDR *p_pkt); - -/* from obx_csm.c */ -extern void obx_csm_event(tOBX_CL_CB *p_cb, tOBX_EVENT event, BT_HDR *p_msg); - -/* from obx_cact.c */ -extern void obx_ca_connect_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_snd_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_close_port(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_snd_part(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_connect_error(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_connect_fail(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_discnt_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_notify(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_fail_rsp(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_state(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_start_timer(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_connect_ok(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_session_ok(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_session_cont(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_session_get(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_session_fail(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_abort(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_snd_put_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_snd_get_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_srm_snd_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_srm_put_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_srm_get_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_srm_put_notify(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_srm_get_notify(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_save_rsp(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern tOBX_CL_STATE obx_ca_save_req(tOBX_CL_CB *p_cb, BT_HDR *p_pkt); - -/* from obx_ssm.c */ -extern void obx_ssm_event(tOBX_SR_SESS_CB *p_scb, tOBX_SR_EVENT event, BT_HDR *p_msg); - -/* from obx_sapi.c */ -extern tOBX_STATUS obx_prepend_rsp_msg(tOBX_HANDLE shandle, tOBX_SR_EVENT event, UINT8 rsp_code, BT_HDR *p_pkt); - -/* from obx_sact.c */ -extern tOBX_SR_STATE obx_sa_snd_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_snd_part(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_abort_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_op_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern BT_HDR * obx_conn_rsp(tOBX_SR_CB *p_cb, tOBX_SR_SESS_CB *p_scb, UINT8 rsp_code, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_connect_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_wc_conn_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_auth_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_connect_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_connection_error(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_close_port(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_clean_port(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_state(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_nc_to(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_save_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_rej_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_session_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_sess_conn_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_wc_sess_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_session_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_put_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_get_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_get_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_srm_put_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_srm_put_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_srm_get_fcs(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_srm_get_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern tOBX_SR_STATE obx_sa_srm_get_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); - -/* from obx_gen.c */ -extern void obx_access_rsp_code(BT_HDR *p_pkt, UINT8 *p_rsp_code); -extern void obx_adjust_packet_len(BT_HDR *p_pkt); -extern UINT16 obx_read_header_len(UINT8 *ph); -extern BT_HDR * obx_dup_pkt(BT_HDR *p_pkt); - -/* from obx_md5 */ -extern BT_HDR * obx_unauthorize_rsp(tOBX_SR_CB *p_cb, tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern void obx_session_id(UINT8 *p_sess_id, UINT8 *p_cl_addr, UINT8 * p_cl_nonce, int cl_nonce_len, - UINT8 *p_sr_addr, UINT8 * p_sr_nonce, int sr_nonce_len); - -/* from obx_l2c.c */ -extern void obx_register_l2c(tOBX_CL_CB *p_cl_cb, UINT16 psm); -extern tOBX_STATUS obx_open_l2c(tOBX_CL_CB *p_cl_cb, const BD_ADDR bd_addr); -extern tOBX_STATUS obx_l2c_sr_register (tOBX_SR_CB *p_cb); -extern void obx_close_l2c(UINT16 lcid); -extern BOOLEAN obx_l2c_snd_msg(tOBX_L2C_CB *p_l2cb); -extern void obx_sr_proc_l2c_evt (tOBX_L2C_EVT_MSG *p_msg); -extern void obx_cl_proc_l2c_evt (tOBX_L2C_EVT_MSG *p_msg); - -/* from obx_utils.c */ -extern UINT8 obx_verify_response(UINT8 opcode, tOBX_RX_HDR *p_rxh); -extern UINT8 obx_verify_request(UINT8 opcode, tOBX_RX_HDR *p_rxh); -extern BOOLEAN obx_sr_proc_pkt (tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt); -extern void obx_cl_proc_pkt (tOBX_CL_CB *p_cb, BT_HDR *p_pkt); -extern void obx_free_buf(tOBX_LL_CB *p_ll_cb); -extern UINT8 obx_add_timeout (tOBX_TRIPLET *p_trip, UINT32 timeout, tOBX_SESS_EVT *p_param); -extern void obx_read_timeout (tOBX_TRIPLET *p_trip, UINT8 num, UINT32 *p_timeout, UINT8 *p_toa); -#if (BT_USE_TRACES == TRUE) -extern void obxu_dump_hex (UINT8 *p, char *p_title, UINT16 len); -#else -#define obxu_dump_hex(p, p_title, len) -#endif -extern BT_HDR * obx_sr_prepend_msg(BT_HDR *p_pkt, UINT8 * p_data, UINT16 data_len); -extern BT_HDR * obx_cl_prepend_msg(tOBX_CL_CB *p_cb, BT_HDR *p_pkt, UINT8 * p_data, UINT16 data_len); -extern void obx_flow_control(tOBX_COMM_CB *p_comm); -extern UINT8 obx_read_triplet(tOBX_TRIPLET *p_trip, UINT8 num_trip, UINT8 tag); -extern UINT32 obx_read_obj_offset(tOBX_TRIPLET *p_trip, UINT8 num_trip); - -#endif /* OBX_INT_H */ diff --git a/stack/obx/obx_l2c.c b/stack/obx/obx_l2c.c deleted file mode 100644 index 51226d9..0000000 --- a/stack/obx/obx_l2c.c +++ /dev/null @@ -1,1031 +0,0 @@ -/***************************************************************************** -** -** Name: obx_l2c.c -** -** Description: This OBX module interfaces to L2CAP -** -** Copyright (c) 2008-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> -#include "wcassert.h" -#include "data_types.h" -#include "bt_target.h" -#include "obx_api.h" -#include "obx_int.h" -#include "l2c_api.h" -#include "l2cdefs.h" -#include "port_api.h" -#include "btu.h" -#include "btm_int.h" - -/* Configuration flags. */ -#define OBX_L2C_CFG_IND_DONE 0x01 -#define OBX_L2C_CFG_CFM_DONE 0x02 -#define OBX_L2C_SECURITY_DONE 0x04 -#define OBX_L2C_CONN_RQS_DONE 0x07 - -/* "states" used for L2CAP channel */ -#define OBX_CH_IDLE 0 /* No connection */ -#define OBX_CH_CONN 1 /* Waiting for connection confirm */ -#define OBX_CH_CFG 2 /* Waiting for configuration complete */ -#define OBX_CH_OPEN 3 /* Channel opened */ - -/* callback function declarations */ -void obx_l2c_connect_ind_cback(BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id); -void obx_l2c_connect_cfm_cback(UINT16 lcid, UINT16 result); -void obx_l2c_config_cfm_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg); -void obx_l2c_config_ind_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg); -void obx_l2c_disconnect_ind_cback(UINT16 lcid, BOOLEAN ack_needed); -void obx_l2c_disconnect_cfm_cback(UINT16 lcid, UINT16 result); -void obx_l2c_data_ind_cback(UINT16 lcid, BT_HDR *p_buf); -void obx_l2c_congestion_ind_cback(UINT16 lcid, BOOLEAN is_congested); -tOBX_SR_SESS_CB * obx_lcb_2_sr_sess_cb(tOBX_L2C_CB *p_lcb); - -#if (OBX_SERVER_INCLUDED == TRUE) -/* L2CAP callback function structure for server */ -const tL2CAP_APPL_INFO obx_l2c_sr_appl = { - obx_l2c_connect_ind_cback, /* tL2CA_CONNECT_IND_CB */ - NULL, /* tL2CA_CONNECT_CFM_CB */ - NULL, /* tL2CA_CONNECT_PND_CB */ - obx_l2c_config_ind_cback, /* tL2CA_CONFIG_IND_CB */ - obx_l2c_config_cfm_cback, /* tL2CA_CONFIG_CFM_CB */ - obx_l2c_disconnect_ind_cback, /* tL2CA_DISCONNECT_IND_CB */ - obx_l2c_disconnect_cfm_cback, /* tL2CA_DISCONNECT_CFM_CB */ - NULL, /* tL2CA_QOS_VIOLATION_IND_CB */ - obx_l2c_data_ind_cback, /* tL2CA_DATA_IND_CB */ - obx_l2c_congestion_ind_cback, /* tL2CA_CONGESTION_STATUS_CB */ - NULL /* tL2CA_TX_COMPLETE_CB */ -}; -#endif - -#if (OBX_CLIENT_INCLUDED == TRUE) -/* L2CAP callback function structure for client */ -const tL2CAP_APPL_INFO obx_l2c_cl_appl = { - NULL, /* tL2CA_CONNECT_IND_CB */ - obx_l2c_connect_cfm_cback, /* tL2CA_CONNECT_CFM_CB */ - NULL, /* tL2CA_CONNECT_PND_CB */ - obx_l2c_config_ind_cback, /* tL2CA_CONFIG_IND_CB */ - obx_l2c_config_cfm_cback, /* tL2CA_CONFIG_CFM_CB */ - obx_l2c_disconnect_ind_cback, /* tL2CA_DISCONNECT_IND_CB */ - obx_l2c_disconnect_cfm_cback, /* tL2CA_DISCONNECT_CFM_CB */ - NULL, /* tL2CA_QOS_VIOLATION_IND_CB */ - obx_l2c_data_ind_cback, /* tL2CA_DATA_IND_CB */ - obx_l2c_congestion_ind_cback, /* tL2CA_CONGESTION_STATUS_CB */ - NULL /* tL2CA_TX_COMPLETE_CB */ -}; -#endif - -/* OBX eL2CAP default options */ -const tL2CAP_FCR_OPTS obx_l2c_fcr_opts_def = { - L2CAP_FCR_ERTM_MODE, /* Mandatory for Obex over L2CAP */ - OBX_FCR_OPT_TX_WINDOW_SIZE_BR_EDR, /* Tx window size over Bluetooth */ - OBX_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */ - OBX_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */ - OBX_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ - L2CAP_DEFAULT_ERM_MPS /* MPS segment size */ -}; - -/******************************************************************************* -** Function obx_l2c_snd_evt -** Description Sends an L2CAP event to OBX through the BTU task. -*******************************************************************************/ -void obx_l2c_snd_evt (tOBX_L2C_CB *p_l2cb, tOBX_L2C_EVT_PARAM param, tOBX_L2C_EVT l2c_evt) -{ - BT_HDR *p_msg; - tOBX_L2C_EVT_MSG *p_evt; - UINT16 event; - - if (!p_l2cb) - return; - - p_msg = (BT_HDR*)GKI_getbuf(BT_HDR_SIZE + sizeof(tOBX_PORT_EVT)); - WC_ASSERT(p_msg); - - if (p_l2cb->handle & OBX_CL_HANDLE_MASK) - event = BT_EVT_TO_OBX_CL_L2C_MSG; - else - event = BT_EVT_TO_OBX_SR_L2C_MSG; - - p_msg->event = event; - p_msg->len = sizeof(tOBX_L2C_EVT_MSG); - p_msg->offset = 0; - p_evt = (tOBX_L2C_EVT_MSG *)(p_msg + 1); - p_evt->l2c_evt = l2c_evt; - p_evt->p_l2cb = p_l2cb; - p_evt->param = param; - - GKI_send_msg(BTU_TASK, BTU_HCI_RCV_MBOX, p_msg); -} - -#if (OBX_SERVER_INCLUDED == TRUE) -/******************************************************************************* -** -** Function obx_sr_scb_by_psm -** -** Description Find the server session control block for L2CAP. -** -** -** Returns void -** -*******************************************************************************/ -tOBX_SR_SESS_CB * obx_sr_scb_by_psm (UINT16 psm) -{ - UINT32 xx, yy; - tOBX_SR_CB *p_cb; - tOBX_SR_SESS_CB *p_scb = NULL, *p_scbt; - UINT16 port_handle; - - for (xx=0; xx<obx_cb.num_server; xx++) - { - if (obx_cb.server[xx].psm == psm) - { - p_cb = &obx_cb.server[xx]; - /* find one that has not allocated a RFCOMM port */ - for (yy=0; yy<p_cb->num_sess; yy++) - { - p_scbt = &obx_cb.sr_sess[p_cb->sess[yy]-1]; - if (p_scbt->ll_cb.comm.id == 0) - { - p_scb = p_scbt; - p_scb->ll_cb.l2c.p_close_fn = obx_close_l2c; - p_scb->ll_cb.l2c.p_send_fn = (tOBX_SEND_FN *)obx_l2c_snd_msg; - break; - } - } - - if (p_scb == NULL) - { - /* check if an RFCOMM port can be freed */ - for (yy=0; yy<p_cb->num_sess; yy++) - { - p_scbt = &obx_cb.sr_sess[p_cb->sess[yy]-1]; - if (p_scbt->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg && p_scbt->state == OBX_SS_NOT_CONNECTED) - { - port_handle = p_scbt->ll_cb.port.port_handle; - p_scbt->ll_cb.port.port_handle = 0; - p_scb = p_scbt; - p_scb->ll_cb.l2c.p_close_fn = obx_close_l2c; - p_scb->ll_cb.l2c.p_send_fn = (tOBX_SEND_FN *)obx_l2c_snd_msg; - obx_close_port(port_handle); - RFCOMM_RemoveServer(port_handle); - obx_sr_free_scb(p_scbt); - break; - } - } - } - break; - } - } - - return p_scb; -} - -/******************************************************************************* -** -** Function obx_sr_proc_l2c_evt -** -** Description This is called to process BT_EVT_TO_OBX_SR_L2C_MSG -** Process server events from L2CAP. Get the associated server control -** block. If this is a request packet, stop timer. Find the -** associated API event and save it in server control block -** (api_evt). Fill the event parameter (param). -** Call obx_ssm_event() with the associated events.If the associated -** control block is not found (maybe the target header does not -** match) or busy, compose a service unavailable response and call -** obx_l2c_snd_msg(). -** Returns void -** -*******************************************************************************/ -void obx_sr_proc_l2c_evt (tOBX_L2C_EVT_MSG *p_msg) -{ - tOBX_SR_SESS_CB *p_scb = NULL; - tOBX_L2C_CB *p_lcb; - BT_HDR *p_pkt=NULL; - tOBX_RX_HDR *p_rxh; - UINT8 opcode; - tOBX_L2C_IND *p_ind; - tL2CAP_CFG_INFO cfg; - UINT16 result = L2CAP_CONN_NO_RESOURCES; -#if (BT_USE_TRACES == TRUE) - UINT16 len; -#endif - tL2CAP_ERTM_INFO ertm_info; - tBT_UUID bt_uuid = {2, {UUID_PROTOCOL_OBEX}}; - tOBX_EVT_PARAM param; - tOBX_SR_CB *p_cb; - - if (p_msg == NULL || p_msg->p_l2cb == NULL) - return; - - if (p_msg->l2c_evt == OBX_L2C_EVT_CONN_IND) - { - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = TRUE; - - p_ind = &p_msg->param.conn_ind; - if ((p_scb = obx_sr_scb_by_psm(p_ind->psm)) != NULL) - { - memcpy(p_scb->param.conn.peer_addr, p_ind->bd_addr, BD_ADDR_LEN); - memcpy(p_scb->peer_addr, p_ind->bd_addr, BD_ADDR_LEN); - result = L2CAP_CONN_OK; - p_lcb = &p_scb->ll_cb.l2c; - cfg.mtu = p_lcb->rx_mtu; - - cfg.fcr_present = TRUE; - cfg.fcr = obx_l2c_fcr_opts_def; - } - /* else no control channel yet, reject */ - - /* Set the FCR options: */ - ertm_info.preferred_mode = obx_l2c_fcr_opts_def.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_pool_id = OBX_USER_RX_POOL_ID; - ertm_info.user_tx_pool_id = OBX_USER_TX_POOL_ID; - ertm_info.fcr_rx_pool_id = OBX_FCR_RX_POOL_ID; - ertm_info.fcr_tx_pool_id = OBX_FCR_TX_POOL_ID; - - /* Send L2CAP connect rsp */ - L2CA_CONNECT_RSP(p_ind->bd_addr, p_ind->id, p_ind->lcid, result, 0, &ertm_info, &bt_uuid); - - /* if result ok, proceed with connection */ - if (result == L2CAP_CONN_OK) - { - /* store LCID */ - p_lcb->lcid = p_ind->lcid; - obx_cb.l2c_map[p_ind->lcid - L2CAP_BASE_APPL_CID] = p_lcb->handle; - OBX_TRACE_DEBUG2("l2c_map[%d]=0x%x",p_ind->lcid - L2CAP_BASE_APPL_CID, p_lcb->handle ); - - /* transition to configuration state */ - p_lcb->ch_state = OBX_CH_CFG; - p_lcb->ch_flags = OBX_L2C_SECURITY_DONE; - - /* Send L2CAP config req */ - L2CA_CONFIG_REQ(p_ind->lcid, &cfg); - } - return; - } - - p_lcb = p_msg->p_l2cb; - p_scb = obx_lcb_2_sr_sess_cb(p_lcb); - if (p_scb == NULL) - return; - - switch (p_msg->l2c_evt) - { - case OBX_L2C_EVT_RESUME: - p_cb = &obx_cb.server[p_scb->handle - 1]; - param.ssn = p_scb->ssn; - (p_cb->p_cback) (p_scb->ll_cb.comm.handle, OBX_GET_REQ_EVT, param, p_pkt); - break; - - case OBX_L2C_EVT_CONG: - p_lcb->cong = p_msg->param.is_cong; - obx_ssm_event (p_scb, OBX_FCS_SET_SEVT, NULL); - break; - - case OBX_L2C_EVT_CLOSE: - obx_ssm_event (p_scb, OBX_PORT_CLOSE_SEVT, NULL); - break; - - case OBX_L2C_EVT_DATA_IND: - p_pkt = p_msg->param.p_pkt; - OBX_TRACE_DEBUG2("obx_sr_proc_l2c_evt len:%d, offset:%d", p_pkt->len, p_pkt->offset ); -#if (BT_USE_TRACES == TRUE) - len = p_pkt->len; - if (len > 0x20) - len = 0x20; - obxu_dump_hex ((UINT8 *)(p_pkt + 1) + p_pkt->offset, "rsp evt", len); -#endif - p_rxh = (tOBX_RX_HDR *)(p_pkt + 1); - opcode = *((UINT8 *)(p_pkt + 1) + p_pkt->offset); - memset(p_rxh, 0, sizeof(tOBX_RX_HDR)); - if (obx_verify_request (opcode, p_rxh) == OBX_BAD_SM_EVT) - { - OBX_TRACE_ERROR1("bad opcode:0x%x disconnect now", opcode ); - GKI_freebuf(p_pkt); - /* coverity [overrun-call] */ - obx_ssm_event(p_scb, OBX_TX_EMPTY_SEVT, NULL); - return; - } - p_pkt->event = obx_sm_evt_to_api_evt[p_rxh->sm_evt]; - p_pkt->layer_specific = GKI_get_buf_size(p_pkt) - BT_HDR_SIZE - p_pkt->offset - p_pkt->len; - OBX_TRACE_DEBUG3("opcode:0x%x event:%d sm_evt:%d", opcode, p_pkt->event, p_rxh->sm_evt ); - if (p_pkt->event != OBX_BAD_SM_EVT) - { - if (GKI_queue_is_empty(&p_lcb->rx_q) && (p_scb->srm & OBX_SRM_WAIT_UL) == 0) - { - obx_sr_proc_pkt (p_scb, p_pkt); - } - else - { - GKI_enqueue (&p_lcb->rx_q, p_pkt); - if (p_lcb->rx_q.count > obx_cb.max_rx_qcount) - { - p_lcb->stopped = TRUE; - L2CA_FlowControl(p_lcb->lcid, FALSE); - } - OBX_TRACE_DEBUG4 ("obx_sr_proc_l2c_evt stopped:%d state:%d rx_q.count:%d, srm:0x%x", - p_lcb->stopped, p_scb->state, p_lcb->rx_q.count, p_scb->srm ); - } - } - else - { - OBX_TRACE_ERROR0("bad SM event" ); - } - break; - } -} - -/******************************************************************************* -** -** Function obx_l2c_sr_register -** -** Description register the PSM to L2CAP. -** -** -** Returns void -** -*******************************************************************************/ -tOBX_STATUS obx_l2c_sr_register (tOBX_SR_CB *p_cb) -{ - tOBX_STATUS status = OBX_NO_RESOURCES; - - if (L2CA_REGISTER (p_cb->psm, &obx_l2c_sr_appl, AMP_AUTOSWITCH_ALLOWED|AMP_USE_AMP_IF_POSSIBLE)) - { - status = OBX_SUCCESS; - } - return status; -} -#endif - -#if (OBX_SERVER_INCLUDED == TRUE) - -/******************************************************************************* -** -** Function obx_lcb_2_sr_sess_cb -** -** Description Find the client control block for the given l2cap session. -** -** -** Returns void -** -*******************************************************************************/ -tOBX_SR_SESS_CB * obx_lcb_2_sr_sess_cb(tOBX_L2C_CB *p_lcb) -{ - UINT32 xx, yy; - tOBX_SR_CB *p_cb; - tOBX_SR_SESS_CB *p_scb = NULL; - - for (xx=0; xx<obx_cb.num_server; xx++) - { - if (obx_cb.server[xx].num_sess) - { - p_cb = &obx_cb.server[xx]; - for (yy=0; yy<p_cb->num_sess; yy++) - { - if (&(obx_cb.sr_sess[p_cb->sess[yy]-1].ll_cb.l2c) == p_lcb) - { - p_scb = &(obx_cb.sr_sess[p_cb->sess[yy]-1]); - break; - } - } - - if (p_scb) - break; - } - } - return p_scb; -} -#endif - -#if (OBX_CLIENT_INCLUDED == TRUE) -/******************************************************************************* -** -** Function obx_lcb_2_clcb -** -** Description Find the client control block for the given l2cap session. -** -** -** Returns void -** -*******************************************************************************/ -tOBX_CL_CB * obx_lcb_2_clcb(tOBX_L2C_CB *p_lcb) -{ - UINT32 xx; - tOBX_CL_CB *p_cl_cb = NULL; - - for (xx=0; xx<obx_cb.num_client; xx++) - { - if (&obx_cb.client[xx].ll_cb.l2c == p_lcb) - { - p_cl_cb = &obx_cb.client[xx]; - break; - } - } - return p_cl_cb; -} -#endif - -/******************************************************************************* -** -** Function obx_lcid_2lcb -** -** Description Given a lcid, return the associated client or server -** control block. -** -** Returns -** -*******************************************************************************/ -tOBX_L2C_CB * obx_lcid_2lcb(UINT16 lcid) -{ - tOBX_L2C_CB *p_lcb = NULL; - tOBX_HANDLE obx_handle = 0; -#if (OBX_SERVER_INCLUDED == TRUE) - tOBX_SR_CB *p_cb; -#endif - tOBX_HANDLE obx_mskd_handle; - - /* this function is called by obx_rfc_cback() only. - * assume that port_handle is within range */ - obx_handle = obx_cb.l2c_map[lcid-L2CAP_BASE_APPL_CID]; - obx_mskd_handle = obx_handle&OBX_HANDLE_MASK; - OBX_TRACE_DEBUG3("obx_lcid_2lcb lcid:0x%x obx_handle:0x%x obx_mskd_handle:0x%x", - lcid, obx_handle, obx_mskd_handle); - - if (obx_handle > 0) - { - if (obx_mskd_handle & OBX_CL_HANDLE_MASK) - { -#if (OBX_CLIENT_INCLUDED == TRUE) - obx_mskd_handle &= ~OBX_CL_HANDLE_MASK; - p_lcb = &obx_cb.client[obx_mskd_handle - 1].ll_cb.l2c; -#endif /* OBX_CLIENT_INCLUDED */ - } - else if (obx_mskd_handle < OBX_NUM_SERVERS) - { -#if (OBX_SERVER_INCLUDED == TRUE) - p_cb = &obx_cb.server[obx_mskd_handle - 1]; - p_lcb = &obx_cb.sr_sess[p_cb->sess[OBX_DEC_SESS_IND(obx_handle)]-1].ll_cb.l2c; - OBX_TRACE_DEBUG3("p_lcb lcid:0x%x sess_ind:%d, sr_sess[%d]", - p_lcb->lcid, OBX_DEC_SESS_IND(obx_handle), p_cb->sess[OBX_DEC_SESS_IND(obx_handle)]-1); -#endif /* OBX_SERVER_INCLUDED */ - } - } - - return p_lcb; -} - -/******************************************************************************* -** -** Function obx_l2c_checks_ch_flags -** -** Description This function processes the L2CAP configuration indication -** event. -** -** Returns void -** -*******************************************************************************/ -static void obx_l2c_checks_ch_flags (tOBX_L2C_CB *p_lcb) -{ - tOBX_L2C_EVT_PARAM evt_param; - - OBX_TRACE_DEBUG1 ("obx_l2c_checks_ch_flags ch_flags:0x%x ", p_lcb->ch_flags); - /* if all the required ch_flags are set, report the OPEN event now */ - if ((p_lcb->ch_flags & OBX_L2C_CONN_RQS_DONE) == OBX_L2C_CONN_RQS_DONE) - { - p_lcb->ch_state = OBX_CH_OPEN; - obx_start_timer((tOBX_COMM_CB *)p_lcb); - evt_param.is_cong = FALSE; - obx_l2c_snd_evt (p_lcb, evt_param, OBX_L2C_EVT_CONG); - } -} - -/******************************************************************************* -** -** Function obx_l2c_connect_ind_cback -** -** Description This is the L2CAP connect indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -#if (OBX_SERVER_INCLUDED == TRUE) -void obx_l2c_connect_ind_cback(BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id) -{ - tOBX_L2C_EVT_PARAM evt_param; - - obx_cb.sr_l2cb.handle = 0; /* to mark as server event */ - memcpy( evt_param.conn_ind.bd_addr, bd_addr, BD_ADDR_LEN); - evt_param.conn_ind.lcid = lcid; - evt_param.conn_ind.psm = psm; - evt_param.conn_ind.id = id; - obx_l2c_snd_evt (&obx_cb.sr_l2cb, evt_param, OBX_L2C_EVT_CONN_IND); -} -#endif /* OBX_SERVER_INCLUDED */ - -#if (OBX_CLIENT_INCLUDED == TRUE) -/******************************************************************************* -** -** Function obx_cl_proc_l2c_evt -** -** Description This is called to process BT_EVT_TO_OBX_CL_L2C_MSG -** Process client events from L2CAP. Get the associated client control -** block. If this is a response packet, stop timer. Call -** obx_csm_event() with event OK_CFM, FAIL_CFM or CONT_CFM. -** Returns void -** -*******************************************************************************/ -void obx_cl_proc_l2c_evt (tOBX_L2C_EVT_MSG *p_msg) -{ - tOBX_CL_CB *p_cl_cb = NULL; - tOBX_L2C_CB *p_l2cb; - BT_HDR *p_pkt; - tOBX_RX_HDR *p_rxh; - UINT8 opcode; - - if (p_msg == NULL || p_msg->p_l2cb == NULL) - return; - - p_l2cb = p_msg->p_l2cb; - p_cl_cb = obx_lcb_2_clcb(p_l2cb); - if (p_cl_cb == NULL) - return; - - switch (p_msg->l2c_evt) - { - case OBX_L2C_EVT_CONG: - p_msg->p_l2cb->cong = p_msg->param.is_cong; - obx_csm_event (p_cl_cb, OBX_FCS_SET_CEVT, NULL); - break; - - case OBX_L2C_EVT_CLOSE: - obx_csm_event (p_cl_cb, OBX_PORT_CLOSE_CEVT, NULL); - break; - - case OBX_L2C_EVT_DATA_IND: - p_pkt = p_msg->param.p_pkt; - p_rxh = (tOBX_RX_HDR *)(p_pkt + 1); - opcode = *((UINT8 *)(p_pkt + 1) + p_pkt->offset); - memset(p_rxh, 0, sizeof(tOBX_RX_HDR)); - obx_verify_response (opcode, p_rxh); - - OBX_TRACE_DEBUG4 ("obx_cl_proc_l2c_evt event:0x%x/0x%x state:%d srm:0x%x", p_pkt->event, p_rxh->sm_evt, p_cl_cb->state, p_cl_cb->srm ); - if (p_rxh->sm_evt != OBX_BAD_SM_EVT) - { - if (GKI_queue_is_empty(&p_l2cb->rx_q) && (p_cl_cb->srm & OBX_SRM_WAIT_UL) == 0) - { - obx_cl_proc_pkt (p_cl_cb, p_pkt); - } - else - { - GKI_enqueue (&p_l2cb->rx_q, p_pkt); - if (p_l2cb->rx_q.count > obx_cb.max_rx_qcount) - { - p_l2cb->stopped = TRUE; - L2CA_FlowControl(p_l2cb->lcid, FALSE); - } - OBX_TRACE_DEBUG3 ("obx_cl_proc_l2c_evt rx_q.count:%d, stopped:%d state:%d", p_l2cb->rx_q.count, p_l2cb->stopped, p_cl_cb->state ); - } - } - else - { - OBX_TRACE_ERROR0("bad SM event" ); - } - break; - - } -} - -/******************************************************************************* -** -** Function obx_l2c_sec_check_complete -** -** Description The function called when Security Manager finishes -** verification of the service side connection -** -** Returns void -** -*******************************************************************************/ -static void obx_l2c_sec_check_complete (BD_ADDR bd_addr, void *p_ref_data, UINT8 res) -{ - tOBX_L2C_CB *p_lcb = (tOBX_L2C_CB *)p_ref_data; - - OBX_TRACE_DEBUG3 ("obx_l2c_sec_check_complete ch_state:%d, ch_flags:0x%x, status:%d", - p_lcb->ch_state, p_lcb->ch_flags, res); - if (p_lcb->ch_state == OBX_CH_IDLE) - return; - - if (res == BTM_SUCCESS) - { - p_lcb->ch_flags |= OBX_L2C_SECURITY_DONE; - obx_l2c_checks_ch_flags (p_lcb); - } - else - { - /* security failed - disconnect the channel */ - L2CA_DISCONNECT_REQ (p_lcb->lcid); - } -} - -/******************************************************************************* -** -** Function obx_l2c_connect_cfm_cback -** -** Description This is the L2CAP connect confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void obx_l2c_connect_cfm_cback(UINT16 lcid, UINT16 result) -{ - tOBX_L2C_CB *p_lcb; - tL2CAP_CFG_INFO cfg; - tOBX_L2C_EVT_PARAM evt_param; - tOBX_CL_CB *p_cl_cb = NULL; - - /* look up lcb for this channel */ - if ((p_lcb = obx_lcid_2lcb(lcid)) != NULL) - { - OBX_TRACE_DEBUG1("obx_l2c_connect_cfm_cback ch_state:%d", p_lcb->ch_state); - /* if in correct state */ - if (p_lcb->ch_state == OBX_CH_CONN) - { - /* if result successful */ - if (result == L2CAP_CONN_OK) - { - /* set channel state */ - p_lcb->ch_state = OBX_CH_CFG; - - p_cl_cb = obx_lcb_2_clcb(p_lcb); - btm_sec_mx_access_request (p_cl_cb->peer_addr, p_cl_cb->psm, TRUE, - 0, 0, &obx_l2c_sec_check_complete, p_lcb); - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - - cfg.mtu_present = TRUE; - cfg.mtu = p_lcb->rx_mtu; - - cfg.fcr_present = TRUE; - cfg.fcr = obx_l2c_fcr_opts_def; - - L2CA_CONFIG_REQ(lcid, &cfg); - } - /* else failure */ - else - { - evt_param.any = 0; - obx_l2c_snd_evt (p_lcb, evt_param, OBX_L2C_EVT_CLOSE); - } - } - } -} -#endif /* OBX_CLIENT_INCLUDED */ - - -/******************************************************************************* -** -** Function obx_l2c_config_cfm_cback -** -** Description This is the L2CAP config confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void obx_l2c_config_cfm_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tOBX_L2C_CB *p_lcb; - - /* look up lcb for this channel */ - if ((p_lcb = obx_lcid_2lcb(lcid)) != NULL) - { - /* if in correct state */ - if (p_lcb->ch_state == OBX_CH_CFG) - { - /* if result successful */ - if (p_cfg->result == L2CAP_CFG_OK) - { - /* update flags */ - p_lcb->ch_flags |= OBX_L2C_CFG_CFM_DONE; - - /* if configuration complete */ - obx_l2c_checks_ch_flags(p_lcb); - } - /* else failure */ - else - { - /* store result value - p_lcb->ch_result = p_cfg->result; */ - - /* Send L2CAP disconnect req */ - L2CA_DISCONNECT_REQ(lcid); - } - } - } -} - -/******************************************************************************* -** -** Function obx_l2c_config_ind_cback -** -** Description This is the L2CAP config indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void obx_l2c_config_ind_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tOBX_L2C_CB *p_lcb; - UINT16 max_mtu = OBX_MAX_MTU; - - /* Don't include QoS nor flush timeout in the response since we - currently always accept these values. Note: fcr_present is left - untouched since l2cap negotiates this internally - */ - p_cfg->flush_to_present = FALSE; - p_cfg->qos_present = FALSE; - - /* look up lcb for this channel */ - if ((p_lcb = obx_lcid_2lcb(lcid)) != NULL) - { - /* store the mtu in tbl */ - if (p_cfg->mtu_present) - { - p_lcb->tx_mtu = p_cfg->mtu; - } - else - { - p_lcb->tx_mtu = L2CAP_DEFAULT_MTU; - } - - if (p_lcb->tx_mtu > max_mtu) - { - p_lcb->tx_mtu = p_cfg->mtu = max_mtu; - - /* Must tell the peer what the adjusted value is */ - p_cfg->mtu_present = TRUE; - } - else /* Don't include in the response */ - p_cfg->mtu_present = FALSE; - OBX_TRACE_DEBUG2 ("obx_l2c_config_ind_cback tx_mtu:%d use:%d", p_lcb->tx_mtu, max_mtu); - - p_cfg->result = L2CAP_CFG_OK; - - /* send L2CAP configure response */ - L2CA_CONFIG_RSP(lcid, p_cfg); - - if (p_cfg->result != L2CAP_CFG_OK) - { - return; - } - - /* if first config ind */ - if ((p_lcb->ch_flags & OBX_L2C_CFG_IND_DONE) == 0) - { - /* update flags */ - p_lcb->ch_flags |= OBX_L2C_CFG_IND_DONE; - - /* if configuration complete */ - obx_l2c_checks_ch_flags(p_lcb); - } - } -} - -/******************************************************************************* -** -** Function obx_l2c_disconnect_ind_cback -** -** Description This is the L2CAP disconnect indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void obx_l2c_disconnect_ind_cback(UINT16 lcid, BOOLEAN ack_needed) -{ - tOBX_L2C_CB *p_lcb; - tOBX_L2C_EVT_PARAM evt_param; - - /* look up lcb for this channel */ - if ((p_lcb = obx_lcid_2lcb(lcid)) != NULL) - { - if (ack_needed) - { - /* send L2CAP disconnect response */ - L2CA_DISCONNECT_RSP(lcid); - } - - evt_param.any = 0; - obx_l2c_snd_evt (p_lcb, evt_param, OBX_L2C_EVT_CLOSE); - } -} - -/******************************************************************************* -** -** Function obx_l2c_disconnect_cfm_cback -** -** Description This is the L2CAP disconnect confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void obx_l2c_disconnect_cfm_cback(UINT16 lcid, UINT16 result) -{ - tOBX_L2C_CB *p_lcb; - tOBX_L2C_EVT_PARAM evt_param; - - /* look up lcb for this channel */ - if ((p_lcb = obx_lcid_2lcb(lcid)) != NULL) - { - evt_param.any = 0; - obx_l2c_snd_evt (p_lcb, evt_param, OBX_L2C_EVT_CLOSE); - } -} - -/******************************************************************************* -** -** Function obx_l2c_data_ind_cback -** -** Description This is the L2CAP data indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void obx_l2c_data_ind_cback(UINT16 lcid, BT_HDR *p_buf) -{ - tOBX_L2C_CB *p_lcb; - tOBX_L2C_EVT_PARAM evt_param; -#if (BT_USE_TRACES == TRUE) - UINT16 len; -#endif - - /* look up lcb for this channel */ - if ((p_lcb = obx_lcid_2lcb(lcid)) != NULL) - { - evt_param.p_pkt = p_buf; - OBX_TRACE_DEBUG3("obx_l2c_data_ind_cback 0x%x, len:%d, offset:%d", p_buf, p_buf->len, p_buf->offset ); -#if (BT_USE_TRACES == TRUE) - len = p_buf->len; - if (len > 0x20) - len = 0x20; - obxu_dump_hex ((UINT8 *)(p_buf + 1) + p_buf->offset, "rsp cback", len); -#endif - obx_l2c_snd_evt (p_lcb, evt_param, OBX_L2C_EVT_DATA_IND); - } - else /* prevent buffer leak */ - GKI_freebuf(p_buf); -} - - -/******************************************************************************* -** -** Function obx_l2c_congestion_ind_cback -** -** Description This is the L2CAP congestion indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void obx_l2c_congestion_ind_cback(UINT16 lcid, BOOLEAN is_congested) -{ - tOBX_L2C_CB *p_lcb; - tOBX_L2C_EVT_PARAM evt_param; - - OBX_TRACE_DEBUG2("obx_l2c_congestion_ind_cback lcid:%d, is_congested:%d",lcid, is_congested ); - /* look up lcb for this channel */ - if ((p_lcb = obx_lcid_2lcb(lcid)) != NULL) - { - evt_param.is_cong = is_congested; - obx_l2c_snd_evt (p_lcb, evt_param, OBX_L2C_EVT_CONG); - } -} - -#if (OBX_CLIENT_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_register_l2c -** Description Call L2CA_Register() to get virtual psm. -** Returns -*******************************************************************************/ -void obx_register_l2c(tOBX_CL_CB *p_cl_cb, UINT16 psm) -{ - p_cl_cb->psm = L2CA_REGISTER (psm, &obx_l2c_cl_appl, AMP_AUTOSWITCH_ALLOWED|AMP_USE_AMP_IF_POSSIBLE); -} - -/******************************************************************************* -** Function obx_open_l2c -** Description Call L2CA_Register() & L2CA_ConnectReq() to get lcid. -** Returns port handle -*******************************************************************************/ -tOBX_STATUS obx_open_l2c(tOBX_CL_CB *p_cl_cb, const BD_ADDR bd_addr) -{ - tOBX_L2C_CB *p_l2cb = &p_cl_cb->ll_cb.l2c; - tOBX_STATUS status = OBX_NO_RESOURCES; /* successful */ - UINT16 max_mtu = OBX_MAX_MTU; - tL2CAP_CFG_INFO cfg; - tL2CAP_ERTM_INFO ertm_info; - tBT_UUID bt_uuid = {2, {UUID_PROTOCOL_OBEX}}; - - OBX_TRACE_DEBUG2("obx_open_l2c rxmtu:%d, cbmtu:%d", p_l2cb->rx_mtu, max_mtu ); - - /* clear buffers from previous connection */ - obx_free_buf(&p_cl_cb->ll_cb); - - /* make sure the MTU is in registered range */ - if (p_l2cb->rx_mtu > max_mtu) - p_l2cb->rx_mtu = max_mtu; - if (p_l2cb->rx_mtu < OBX_MIN_MTU) - p_l2cb->rx_mtu = OBX_MIN_MTU; - - if (p_cl_cb->psm) - { - memcpy (p_cl_cb->peer_addr, bd_addr, BD_ADDR_LEN); - - /* Set the FCR options: */ - ertm_info.preferred_mode = obx_l2c_fcr_opts_def.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_pool_id = OBX_USER_RX_POOL_ID; - ertm_info.user_tx_pool_id = OBX_USER_TX_POOL_ID; - ertm_info.fcr_rx_pool_id = OBX_FCR_RX_POOL_ID; - ertm_info.fcr_tx_pool_id = OBX_FCR_TX_POOL_ID; - - p_l2cb->lcid = L2CA_CONNECT_REQ (p_cl_cb->psm, (BD_ADDR_PTR)bd_addr, &ertm_info, &bt_uuid); - if (p_l2cb->lcid) - { - p_l2cb->ch_state = OBX_CH_CONN; - p_l2cb->ch_flags = 0; - p_l2cb->cong = TRUE; - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.fcr_present = TRUE; - cfg.fcr = obx_l2c_fcr_opts_def; - status = OBX_SUCCESS; - } - } - - OBX_TRACE_DEBUG3("obx_open_l2c rxmtu:%d, lcid:%d, l2c.handle:0x%x", - p_l2cb->rx_mtu, p_l2cb->lcid, p_l2cb->handle ); - - if (status == OBX_SUCCESS) - { - obx_cb.l2c_map[p_l2cb->lcid - L2CAP_BASE_APPL_CID] = p_l2cb->handle; - p_l2cb->p_send_fn = (tOBX_SEND_FN *)obx_l2c_snd_msg; - p_l2cb->p_close_fn = obx_close_l2c; - } - else - { - status = OBX_NO_RESOURCES; - } - - return status; -} -#endif - -/******************************************************************************* -** -** Function obx_close_l2c -** Description Clear the port event mask and callback. Close the port. -** Returns void -*******************************************************************************/ -void obx_close_l2c(UINT16 lcid) -{ - L2CA_DISCONNECT_REQ (lcid); -} - -/******************************************************************************* -** Function obx_l2c_snd_msg -** Description Call PORT_WriteData() to send an OBEX message to peer. If -** all data is sent, free the GKI buffer that holds -** the OBEX message. If only portion of data is -** sent, adjust the BT_HDR for PART state. -** Returns TRUE if all data is sent -*******************************************************************************/ -BOOLEAN obx_l2c_snd_msg(tOBX_L2C_CB *p_l2cb) -{ - BOOLEAN sent = FALSE; - - if (!p_l2cb->cong) - { - OBX_TRACE_DEBUG2("obx_l2c_snd_msg len:%d, offset:0x%x", p_l2cb->p_txmsg->len, p_l2cb->p_txmsg->offset); - - obx_stop_timer(&p_l2cb->tle); - if (L2CA_DATA_WRITE (p_l2cb->lcid, p_l2cb->p_txmsg) == L2CAP_DW_CONGESTED) - { - OBX_TRACE_DEBUG0("obx_l2c_snd_msg congested"); - p_l2cb->cong = TRUE; - } - obx_start_timer ((tOBX_COMM_CB *)p_l2cb); - p_l2cb->p_txmsg = NULL; - sent = TRUE; - } - - return sent; -} diff --git a/stack/obx/obx_main.c b/stack/obx/obx_main.c deleted file mode 100644 index 7dc7c97..0000000 --- a/stack/obx/obx_main.c +++ /dev/null @@ -1,946 +0,0 @@ -/***************************************************************************** -** -** Name: obx_main.c -** -** File: OBEX common API and interface to other Bluetooth modules -** -** Copyright (c) 2003-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "bt_target.h" -#include "obx_int.h" -#include "btu.h" /* for timer */ -#include "l2c_api.h" -#include "l2cdefs.h" - -#if (defined (BT_USE_TRACES) && BT_USE_TRACES == TRUE) -const char * const obx_cl_state_name [] = -{ - "NULL", - "NOT_CONN", - "SESS_RS", - "CONN_RS", - "UNAUTH", - "CONN", - "DISCNT_RS", - "OP_UNAUTH", - "SETPATH_RS", - "ACT_RS", - "ABORT_RS", - "PUT_RS", - "GET_RS", - "PUT", - "GET", - "PUT_S", - "GET_S", - "PART", - "Unknown" -}; - -const char * const obx_cl_event_name [] = -{ - "CONN_R", - "SESS_R", - "DISCNT_R", - "PUT_R", - "GET_R", - "SETPATH_R", - "ACT_R", - "ABORT_R", - "OK_C", - "CONT_C", - "FAIL_C", - "PORT_CLS", - "TX_EMPTY", - "FCS_SET", - "STATE", - "TIMEOUT", - "Unknown" -}; - -const char * const obx_sr_state_name [] = -{ - "NULL", - "NOT_CONN", - "SESS_I", - "CONN_I", - "WAIT_AUTH", - "AUTH_I", - "CONN", - "DISCNT_I", - "SETPATH_I", - "ACT_I", - "ABORT_I", - "PUT_I", - "GET_I", - "PUT", - "GET", - "PUT_S", - "GET_S", - "PART", - "WAIT_CLS", - "Unknown" -}; - -const char * const obx_sr_event_name [] = -{ - "CONN_R", - "SESS_R", - "DISCNT_R", - "PUT_R", - "GET_R", - "SETPATH_R", - "ACT_R", - "ABORT_R", - "CONN_C", - "SESS_C", - "DISCNT_C", - "PUT_C", - "GET_C", - "SETPATH_C", - "ACT_C", - "ABORT_C", - "PORT_CLS", - "FCS_SET", - "STATE", - "TIMEOUT", - "BAD_REQ", - "TX_EMPTY", - "Unknown" -}; -#endif - -#if OBX_DYNAMIC_MEMORY == FALSE -OBX_API tOBX_CB obx_cb; -#endif - - -#if (defined (BT_USE_TRACES) && BT_USE_TRACES == TRUE) -#if (OBX_CLIENT_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_cl_get_state_name -** Returns The client state name. -*******************************************************************************/ -const char *obx_cl_get_state_name(tOBX_CL_STATE state) -{ - const char * p_str = obx_cl_state_name[OBX_CS_MAX]; - if (state < OBX_CS_MAX) - { - p_str = obx_cl_state_name[state]; - } - return p_str; -} - -/******************************************************************************* -** Function obx_cl_get_event_name -** Returns The client event name. -*******************************************************************************/ -const char *obx_cl_get_event_name(tOBX_CL_EVENT event) -{ - const char * p_str = obx_cl_event_name[OBX_MAX_CEVT]; - if (event < OBX_MAX_CEVT) - { - p_str = obx_cl_event_name[event]; - } - return p_str; -} -#endif - -#if (OBX_SERVER_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_sr_get_state_name -** Returns The server state name. -*******************************************************************************/ -const char *obx_sr_get_state_name(tOBX_SR_STATE state) -{ - const char * p_str = obx_sr_state_name[OBX_SS_MAX]; - if (state < OBX_SS_MAX) - { - p_str = obx_sr_state_name[state]; - } - return p_str; -} - -/******************************************************************************* -** Function obx_sr_get_event_name -** Returns The server event name. -*******************************************************************************/ -const char *obx_sr_get_event_name(tOBX_SR_EVENT event) -{ - const char * p_str = obx_sr_event_name[OBX_MAX_SEVT]; - if (event < OBX_MAX_SEVT) - { - p_str = obx_sr_event_name[event]; - } - return p_str; -} -#endif -#endif - -/******************************************************************************* -** Function obx_start_timer -** Description start BTU timer. -*******************************************************************************/ -void obx_start_timer(tOBX_COMM_CB *p_pcb) -{ - UINT16 type = 0; - UINT32 timeout = obx_cb.timeout_val; - - if (timeout) - { - if (p_pcb->handle & OBX_CL_HANDLE_MASK) - { - if (p_pcb->p_txmsg && p_pcb->p_txmsg->event == OBX_DISCONNECT_REQ_EVT) - { - timeout = OBX_DISC_TOUT_VALUE; - } - type = BTU_TTYPE_OBX_CLIENT_TO; - } - else - { - if (p_pcb->p_txmsg && p_pcb->p_txmsg->event == (OBX_DISCNT_CFM_SEVT + 1)) - { - timeout = OBX_DISC_TOUT_VALUE; - } - type = BTU_TTYPE_OBX_SERVER_TO; - } - btu_start_timer(&p_pcb->tle, type, timeout); - } - OBX_TRACE_DEBUG3("obx_start_timer type: %d, val:%d, p_tle:0x%x", type, timeout, &p_pcb->tle); -} - -/******************************************************************************* -** Function obx_stop_timer -** Description Stop BTU timer -*******************************************************************************/ -void obx_stop_timer(TIMER_LIST_ENT *p_tle) -{ - btu_stop_timer(p_tle); - OBX_TRACE_DEBUG1("obx_stop_timer p_tle:0x%x", p_tle); -} - -#if (OBX_CLIENT_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_cl_timeout -** Description Get client control block from timer param. Start BTU timer again. -** Call application callback routine with OBX_TIMEOUT_EVT event. -*******************************************************************************/ -void obx_cl_timeout(TIMER_LIST_ENT *p_tle) -{ - tOBX_CL_CB *p_cb = (tOBX_CL_CB *) p_tle->param; - tOBX_EVT_PARAM evtp; - tOBX_HANDLE handle = p_cb->ll_cb.comm.handle; - tOBX_CL_CBACK *p_cback = p_cb->p_cback; - - memset(&evtp, 0, sizeof(tOBX_EVT_PARAM)); - if (obx_cb.timeout_val) - btu_start_timer(p_tle, BTU_TTYPE_OBX_CLIENT_TO, obx_cb.timeout_val); - obx_csm_event(p_cb, OBX_TIMEOUT_CEVT, NULL); - (*p_cback) (handle, OBX_TIMEOUT_EVT, OBX_RSP_DEFAULT, evtp, NULL); -} - -/******************************************************************************* -** -** Function obx_cl_alloc_cb -** -** Description allocate a client control block. -** -*******************************************************************************/ -tOBX_CL_CB *obx_cl_alloc_cb(void) -{ - int xx, yy; - tOBX_CL_CB *p_cb = NULL; - - /* allocate a client control block */ - for (xx=0, yy=obx_cb.next_ind; xx<obx_cb.num_client; xx++, yy++) - { - if (yy >= obx_cb.num_client) - yy = 0; - p_cb = &obx_cb.client[yy]; - - if (p_cb->ll_cb.comm.handle == OBX_HANDLE_NULL) - { - p_cb->ll_cb.comm.handle = OBX_CL_HANDLE_MASK | (yy + 1); - obx_cb.next_ind = yy+1; /* it will be adjusted, so we do not need to check the range now */ - OBX_TRACE_DEBUG3("obx_cl_alloc_cb obx handle:0x%x, yy:%d, next: %d", - p_cb->ll_cb.comm.handle, yy, obx_cb.next_ind); - p_cb->ll_cb.comm.tx_mtu = 0; - p_cb->conn_id = OBX_INVALID_CONN_ID; - - p_cb->ll_cb.comm.tle.param = (UINT32)p_cb; - p_cb->psm = 0; - p_cb->srm = 0; - break; - } - } - - if (xx == obx_cb.num_client) - p_cb = NULL; - return p_cb; -} - -/******************************************************************************* -** -** Function obx_cl_get_cb -** -** Description Returns the pointer to the client control block with given handle. -** -*******************************************************************************/ -tOBX_CL_CB *obx_cl_get_cb(tOBX_HANDLE handle) -{ - tOBX_CL_CB *p_cb = NULL; - UINT8 ind = (handle & OBX_CL_CB_IND_MASK); - - if (handle & OBX_CL_HANDLE_MASK) - { - if (ind <= obx_cb.num_client && ind > 0) - { - if (obx_cb.client[--ind].ll_cb.comm.handle == handle) - p_cb = &obx_cb.client[ind]; - } - } - - return p_cb; -} - -/******************************************************************************* -** -** Function obx_cl_get_suspended_cb -** -** Description Returns the pointer to the client control block with given handle. -** -*******************************************************************************/ -tOBX_CL_CB *obx_cl_get_suspended_cb(tOBX_HANDLE *p_handle, UINT8 *p_session_info) -{ - tOBX_HANDLE handle = *p_handle; - tOBX_CL_CB *p_cb = NULL; - tOBX_CL_CB *p_ccb = NULL; - UINT8 ind = (handle & OBX_CL_CB_IND_MASK); - - OBX_TRACE_DEBUG1("obx_cl_get_suspended_cb handle: 0x%x", handle); - if (handle & OBX_CL_HANDLE_MASK) - { - if (ind <= obx_cb.num_client && ind > 0) - { - if (obx_cb.client[--ind].ll_cb.comm.handle == handle) - { - p_ccb = &obx_cb.client[ind]; - if (p_ccb->sess_st == OBX_SESS_SUSPENDED && - ((p_session_info == p_ccb->sess_info) || (memcmp(p_session_info, p_ccb->sess_info, OBX_SESSION_INFO_SIZE) == 0))) - { - OBX_TRACE_DEBUG0("found a suspended session"); - p_cb = p_ccb; - } - } - } - } - if (p_cb == NULL) /* if the handle is NULL, assume the system was power cycled. attempt to allocate a control block */ - { - p_cb = obx_cl_alloc_cb(); - if (p_cb) - { - *p_handle = p_cb->ll_cb.comm.handle; - p_cb->sess_st = OBX_SESS_SUSPENDED; - memcpy(p_cb->sess_info, p_session_info, OBX_SESSION_INFO_SIZE); - OBX_TRACE_DEBUG1("allocated a suspended session handle: 0x%x", *p_handle); - } - } - - return p_cb; -} - -/******************************************************************************* -** -** Function obx_cl_free_cb -** -** Description Free the given client control block. -** -** Returns void -** -*******************************************************************************/ -void obx_cl_free_cb(tOBX_CL_CB * p_cb) -{ - if (p_cb) - { - OBX_TRACE_DEBUG2("obx_cl_free_cb id: %d, sess_st:%d", p_cb->ll_cb.comm.id, p_cb->sess_st); - - if (p_cb->ll_cb.comm.id>0) - { - if (p_cb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg) - obx_cb.hdl_map[p_cb->ll_cb.port.port_handle - 1] = 0; - else - obx_cb.l2c_map[p_cb->ll_cb.l2c.lcid - L2CAP_BASE_APPL_CID] = 0; - } - - /* make sure the GKI buffers are freed */ - if (p_cb->p_next_req) - GKI_freebuf(p_cb->p_next_req); - - if (p_cb->p_saved_req) - GKI_freebuf(p_cb->p_saved_req); - - if (p_cb->p_auth) - GKI_freebuf(p_cb->p_auth); - - obx_free_buf (&p_cb->ll_cb); - - if (p_cb->psm) - L2CA_DEREGISTER (p_cb->psm); - - /* make sure the timer is stopped */ - btu_stop_timer(&p_cb->ll_cb.comm.tle); - - memset(p_cb, 0, sizeof(tOBX_CL_CB) ); - } -} -#endif /* OBX_CLIENT_INCLUDED */ - -#if (OBX_SERVER_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_find_suspended_session -** Description if p_triplet is NULL, -** check if there's still room for a reliable session -** else check if the given session is still in the suspended list -*******************************************************************************/ -tOBX_SPND_CB *obx_find_suspended_session (tOBX_SR_SESS_CB *p_scb, tOBX_TRIPLET *p_triplet, UINT8 num) -{ - UINT8 ind; - BOOLEAN found = FALSE; - BOOLEAN infinite = FALSE; - UINT8 *p, xx; - tOBX_SR_CB *p_cb = obx_sr_get_cb(p_scb->handle); - tOBX_SPND_CB *p_spndcb, *p_ret = NULL; - - OBX_TRACE_DEBUG0("obx_find_suspended_session "); - if (p_triplet == NULL) - { - if (p_cb->p_suspend) - { - for (xx=0, p_spndcb=p_cb->p_suspend; xx<p_cb->max_suspend; xx++, p_spndcb++) - { - if ((p_spndcb->state == OBX_SS_NULL) || (memcmp(p_spndcb->peer_addr, p_scb->peer_addr, BD_ADDR_LEN)==0)) - { - OBX_TRACE_DEBUG3("[%d] state: %d, BDA: %08x", xx, p_spndcb->state, - (p_spndcb->peer_addr[2]<<24)+(p_spndcb->peer_addr[3]<<16)+(p_spndcb->peer_addr[4]<<8)+p_spndcb->peer_addr[5]); - /* this entry is not used yet or overwriting the entry with the same address */ - found = TRUE; - break; - } - else if (p_spndcb->stle.param == 0) - { - infinite = TRUE; - } - } - OBX_TRACE_DEBUG2("found: %d infinite:%d", found, infinite); - if (found == FALSE) - found = infinite; - } - else if (p_cb->max_suspend > 0) - { - found = TRUE; - } - p_ret = (tOBX_SPND_CB *)p_scb; - } - else if (p_cb->p_suspend) - { - ind = obx_read_triplet(p_triplet, num, OBX_TAG_SESS_PARAM_SESS_ID); - if (ind < num && p_triplet[ind].len == OBX_SESSION_ID_SIZE) - { - p = p_triplet[ind].p_array; - for (xx=0, p_spndcb=p_cb->p_suspend; xx<p_cb->max_suspend; xx++, p_spndcb++) - { - OBX_TRACE_DEBUG5("[%d] state: %d/%d, ssn:%d offset:x%x", xx, p_spndcb->state, - p_spndcb->sess_info[OBX_SESSION_INFO_ST_IDX], p_spndcb->ssn, p_spndcb->offset); - if ((p_spndcb->state != OBX_SS_NULL) && - (memcmp (p, p_spndcb->sess_info, OBX_SESSION_ID_SIZE) == 0)) - { - obxu_dump_hex (p_spndcb->sess_info, "sess info", OBX_SESSION_INFO_SIZE); - /* prepare p_scb to the proper state for resume */ - p_ret = p_spndcb; - break; - } - } - } - } - return p_ret; -} - -/******************************************************************************* -** Function obx_sr_sess_timeout -** Description Get suspended session control block from timer param. -** mark the suspended session as NULL -*******************************************************************************/ -void obx_sr_sess_timeout(TIMER_LIST_ENT *p_tle) -{ - tOBX_SPND_CB *p_spndcb = (tOBX_SPND_CB *) p_tle->param; - - OBX_TRACE_DEBUG0("obx_sr_sess_timeout"); - p_spndcb->state = OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sr_timeout -** Description Get server control block from timer param. Start BTU timer again. -** Call application callback routine with OBX_TIMEOUT_EVT event. -*******************************************************************************/ -void obx_sr_timeout(TIMER_LIST_ENT *p_tle) -{ - tOBX_SR_SESS_CB *p_scb = (tOBX_SR_SESS_CB *) p_tle->param; - tOBX_EVT_PARAM evtp; - tOBX_HANDLE handle = p_scb->ll_cb.comm.handle; - tOBX_SR_CBACK *p_cback; - tOBX_SR_CB *p_cb; - - memset(&evtp, 0, sizeof(tOBX_EVT_PARAM)); - if (obx_cb.timeout_val) - btu_start_timer(p_tle, BTU_TTYPE_OBX_SERVER_TO, obx_cb.timeout_val); - p_cb = &obx_cb.server[p_scb->handle - 1]; - p_cback = p_cb->p_cback; - obx_ssm_event(p_scb, OBX_TIMEOUT_SEVT, NULL); - (*p_cback) (handle, OBX_TIMEOUT_EVT, evtp, NULL); -} - -/******************************************************************************* -** -** Function obx_sr_alloc_cb -** -** Description allocate a server control block. -** -*******************************************************************************/ -tOBX_HANDLE obx_sr_alloc_cb(tOBX_StartParams *p_params) -{ - int xx, yy, zz; - tOBX_SR_CB *p_cb = &obx_cb.server[0]; - tOBX_SR_SESS_CB *p_scb = &obx_cb.sr_sess[0]; - tOBX_HANDLE obx_handle = OBX_HANDLE_NULL; - - OBX_TRACE_DEBUG1("obx_sr_alloc_cb num sess: %d", p_params->max_sessions); - /* allocate a server control block */ - for (xx=0; xx<obx_cb.num_server; xx++, p_cb++) - { - if (p_cb->scn == 0 && p_cb->psm == 0) - { - obx_handle = xx + 1; - p_cb->scn = p_params->scn; - p_cb->psm = p_params->psm; - break; - } - } - - if (xx != obx_cb.num_server) - { - /* allocate session control blocks */ - zz = 0; - for (yy=0; yy<obx_cb.num_sr_sess && zz < p_params->max_sessions; yy++, p_scb++) - { - if (p_scb->ll_cb.comm.handle == OBX_HANDLE_NULL) - { - p_scb->handle = obx_handle; - if (p_params->get_nonf) - p_scb->srmp = OBX_SRMP_NONF_EVT; - p_cb->sess[zz] = yy + 1; - p_scb->srm = p_params->srm; - p_scb->ll_cb.comm.handle = OBX_ENC_SESS_HANDLE((obx_handle), zz); - p_scb->ll_cb.comm.tx_mtu = 0; - p_scb->ll_cb.comm.tle.param = (UINT32)p_scb; - OBX_TRACE_DEBUG2("[%d]: 0x%x", zz, p_scb->ll_cb.comm.handle); - zz++; - } - } - - if (zz == p_params->max_sessions && L2C_IS_VALID_PSM(p_params->psm)) - { - if (obx_l2c_sr_register(p_cb) != OBX_SUCCESS) - { - OBX_TRACE_ERROR0("Cannot register to L2CAP"); - zz = 0; /* let it fail */ - } - } - - if (zz != p_params->max_sessions) - { - OBX_TRACE_ERROR0("not enough resources: release the allocated ones"); - p_cb->scn = 0; - p_cb->psm = 0; - obx_handle = OBX_HANDLE_NULL; - p_scb = &obx_cb.sr_sess[0]; - for (yy=0; yy<obx_cb.num_sr_sess; yy++, p_scb++) - { - if (p_scb->handle == obx_handle) - { - p_scb->ll_cb.comm.handle = OBX_HANDLE_NULL; - } - } - } - else - { - p_cb->num_sess = p_params->max_sessions; - p_cb->nonce = p_params->nonce; - p_cb->max_suspend = p_params->max_suspend; - if (p_cb->nonce && (p_cb->max_suspend == 0)) - p_cb->max_suspend = 1; - if (p_cb->max_suspend > OBX_MAX_SUSPEND_SESSIONS) - p_cb->max_suspend = OBX_MAX_SUSPEND_SESSIONS; - if ((p_cb->max_suspend * sizeof (tOBX_SPND_CB)) > GKI_MAX_BUF_SIZE) - { - OBX_TRACE_ERROR1("OBX_MAX_SUSPEND_SESSIONS:%d is too big", OBX_MAX_SUSPEND_SESSIONS); - } - } - } - return obx_handle; -} - -/******************************************************************************* -** -** Function obx_sr_get_cb -** -** Description Returns the pointer to the server control block with given handle. -** -*******************************************************************************/ -tOBX_SR_CB * obx_sr_get_cb(tOBX_HANDLE handle) -{ - tOBX_SR_CB *p_cb = NULL; - tOBX_HANDLE obx_handle = OBX_DEC_HANDLE(handle); - - /* check range */ - if (obx_handle <= obx_cb.num_server && obx_handle > 0 && obx_cb.server[obx_handle-1].p_cback) - { - p_cb = &obx_cb.server[obx_handle-1]; - } - - return p_cb; -} - -/******************************************************************************* -** -** Function obx_sr_get_scb -** -** Description Returns the pointer to the server control block with given handle. -** -*******************************************************************************/ -tOBX_SR_SESS_CB * obx_sr_get_scb(tOBX_HANDLE handle) -{ - tOBX_SR_CB *p_cb; - tOBX_SR_SESS_CB *p_scb = NULL; - tOBX_HANDLE obx_handle; - UINT16 sess_ind; - - /* check range */ - obx_handle = OBX_DEC_HANDLE(handle) - 1; - if (obx_handle < obx_cb.num_server) - { - /* make sure the handle is a valid one */ - p_cb = &obx_cb.server[obx_handle]; - sess_ind = OBX_DEC_SESS_IND(handle); - if ((sess_ind < p_cb->num_sess)) - { - if ((obx_cb.sr_sess[p_cb->sess[sess_ind]-1].ll_cb.comm.handle) == handle) - p_scb = &obx_cb.sr_sess[p_cb->sess[sess_ind]-1]; - } - } - - return p_scb; -} - -/******************************************************************************* -** -** Function obx_sr_free_cb -** -** Description Free the given server control block. -** -** Returns void -** -*******************************************************************************/ -void obx_sr_free_cb(tOBX_HANDLE handle) -{ - tOBX_SR_CB * p_cb = obx_sr_get_cb(handle); - tOBX_SR_SESS_CB *p_scb; - int yy; - - OBX_TRACE_DEBUG1("obx_sr_free_cb handle:0x%x", handle); - /* check range */ - if (p_cb) - { - p_scb = &obx_cb.sr_sess[0]; - for (yy=0; yy<obx_cb.num_sr_sess; yy++, p_scb++) - { - if (OBX_DEC_HANDLE(p_scb->handle) == OBX_DEC_HANDLE(handle)) - { - obx_sr_free_scb(p_scb); - if (p_scb->ll_cb.comm.id>0) - { - if (p_scb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg) - obx_cb.hdl_map[p_scb->ll_cb.port.port_handle - 1] = 0; - else - obx_cb.l2c_map[p_scb->ll_cb.l2c.lcid - L2CAP_BASE_APPL_CID] = 0; - } - memset(p_scb, 0, sizeof(tOBX_SR_SESS_CB) ); - } - } - - if (p_cb->p_auth) - { - GKI_freebuf(p_cb->p_auth); - p_cb->p_auth = 0; - } - - memset(p_cb, 0, sizeof(tOBX_SR_CB) ); - } -} - -/******************************************************************************* -** -** Function obx_sr_free_scb -** -** Description Free the given server session control block. -** -** Returns void -** -*******************************************************************************/ -void obx_sr_free_scb(tOBX_SR_SESS_CB *p_scb) -{ - OBX_TRACE_DEBUG2("obx_sr_free_scb shandle:0x%x, sess_st:%d", p_scb->ll_cb.comm.handle, p_scb->sess_st); - - /* make sure the GKI buffers are freed */ - if (p_scb->p_saved_msg) - { - GKI_freebuf(p_scb->p_saved_msg); - p_scb->p_saved_msg = 0; - } - - if (p_scb->p_next_req) - { - GKI_freebuf(p_scb->p_next_req); - p_scb->p_next_req = 0; - } - obx_free_buf (&p_scb->ll_cb); - - /* make sure the timer is stopped */ - btu_stop_timer(&p_scb->ll_cb.comm.tle); -} - -/******************************************************************************* -** -** Function obx_sr_get_next_conn_id -** -** Description assigns the next available connection id. It will avoid using -** active conn id instances as well so that we can work with the -** IVT stack bugs. -** -*******************************************************************************/ -UINT32 obx_sr_get_next_conn_id(void) -{ -#if (OBX_CLIENT_INCLUDED == TRUE) - tOBX_CL_CB *p_ccb; - int xx; - BOOLEAN done; - - /* Make sure no client instances are using the value */ - do - { - obx_cb.next_cid++; - - /* Increment the value and make sure it is legal */ - if (obx_cb.next_cid == OBX_INVALID_CONN_ID) - obx_cb.next_cid = OBX_INITIAL_CONN_ID; - - done = TRUE; - for (xx=0, p_ccb = &obx_cb.client[0]; xx < obx_cb.num_client; xx++, p_ccb++) - { - /* If the handle is in use and same as proposed conn_id, increment and restart */ - if (p_ccb->ll_cb.comm.handle != OBX_HANDLE_NULL && p_ccb->conn_id == obx_cb.next_cid) - { - OBX_TRACE_WARNING1(" **** OBX CONN_ID Collision (0x%08x) trying another...", obx_cb.next_cid); - done = FALSE; - break; - } - } - } while (!done); - -#else /* Client code is not compiled in */ - - obx_cb.next_cid++; - - /* Increment the value and make sure it is legal */ - if (obx_cb.next_cid == OBX_INVALID_CONN_ID) - obx_cb.next_cid = OBX_INITIAL_CONN_ID; -#endif - - return obx_cb.next_cid; -} - -#endif /* OBX_SERVER_INCLUDED */ - -/******************************************************************************* -** -** Function obx_port_handle_2cb -** -** Description Given a port handle, return the associated client or server -** control block. -** -** Returns -** -*******************************************************************************/ -tOBX_PORT_CB * obx_port_handle_2cb(UINT16 port_handle) -{ - tOBX_PORT_CB *p_pcb = NULL; - tOBX_HANDLE obx_handle = 0; -#if (OBX_SERVER_INCLUDED == TRUE) - tOBX_SR_CB *p_cb; -#endif - - /* this function is called by obx_rfc_cback() only. - * assume that port_handle is within range */ - obx_handle = obx_cb.hdl_map[port_handle-1]; - OBX_TRACE_DEBUG2("obx_port_handle_2cb port_handle:%d obx_handle:0x%x", port_handle, obx_handle); - - if (obx_handle > 0) - { - if (obx_handle & OBX_CL_HANDLE_MASK) - { -#if (OBX_CLIENT_INCLUDED == TRUE) - obx_handle &= OBX_CL_CB_IND_MASK; - p_pcb = &obx_cb.client[obx_handle - 1].ll_cb.port; -#endif /* OBX_CLIENT_INCLUDED */ - } - else - { -#if (OBX_SERVER_INCLUDED == TRUE) - p_cb = &obx_cb.server[OBX_DEC_HANDLE(obx_handle) - 1]; - p_pcb = &obx_cb.sr_sess[p_cb->sess[OBX_DEC_SESS_IND(obx_handle)]-1].ll_cb.port; - OBX_TRACE_DEBUG1("p_pcb port_handle:%d", p_pcb->port_handle); -#endif /* OBX_SERVER_INCLUDED */ - } - } - - return p_pcb; -} - - - -/******************************************************************************* -** -** Function OBX_Init -** -** Description This function is called to initialize the control block for this -** layer. It must be called before accessing any other of its API -** functions. It is typically called once during the start up of -** the stack. -** -** Returns void. -** -*******************************************************************************/ -void OBX_Init(void) -{ - memset(&obx_cb, 0, sizeof(tOBX_CB)); - -#if defined(OBX_INITIAL_TRACE_LEVEL) - obx_cb.trace_level = OBX_INITIAL_TRACE_LEVEL; -#else - obx_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ -#endif - -#if (OBX_CLIENT_INCLUDED == TRUE) - obx_cb.next_ind = 0; - obx_cb.num_client = OBX_NUM_CLIENTS; -#endif - -#if (OBX_SERVER_INCLUDED == TRUE) - obx_cb.num_server = OBX_NUM_SERVERS; - obx_cb.num_sr_sess = OBX_NUM_SR_SESSIONS; - obx_cb.next_cid = OBX_INITIAL_CONN_ID; -#endif - obx_cb.timeout_val = OBX_TIMEOUT_VALUE; - obx_cb.sess_tout_val= OBX_SESS_TIMEOUT_VALUE; - obx_cb.max_rx_qcount= OBX_MAX_RX_QUEUE_COUNT; -} - -/******************************************************************************* -** -** Function OBX_SetTraceLevel -** -** Description This function sets the debug trace level for OBX. -** If 0xff is passed, the current trace level is returned. -** -** Input Parameters: -** level: The level to set the OBX tracing to: -** 0xff-returns the current setting. -** 0-turns off tracing. -** >= 1-Errors. -** >= 2-Warnings. -** >= 3-APIs. -** >= 4-Events. -** >= 5-Debug. -** -** Returns The new trace level or current trace level if -** the input parameter is 0xff. -** -*******************************************************************************/ -UINT8 OBX_SetTraceLevel (UINT8 level) -{ - if (level != 0xFF) - obx_cb.trace_level = level; - - return (obx_cb.trace_level); -} - -/******************************************************************************* -** Function OBX_HandleToMtu -** -** Description Given an OBEX handle, return the associated peer MTU. -** -** Returns MTU. -** -*******************************************************************************/ -UINT16 OBX_HandleToMtu(tOBX_HANDLE handle) -{ - UINT16 mtu = OBX_MIN_MTU; - BOOLEAN rx = (handle & OBX_HANDLE_RX_MTU_MASK); -#if (OBX_CLIENT_INCLUDED == TRUE) - int xx; -#endif -#if (OBX_SERVER_INCLUDED == TRUE) - tOBX_SR_SESS_CB *p_scb; -#endif - - handle &= ~OBX_HANDLE_RX_MTU_MASK; - - if (handle != OBX_HANDLE_NULL) - { - if (handle & OBX_CL_HANDLE_MASK) - { -#if (OBX_CLIENT_INCLUDED == TRUE) - /* a client handle */ - for (xx=0; xx<obx_cb.num_client; xx++) - { - if (handle == obx_cb.client[xx].ll_cb.comm.handle) - { - mtu = (rx) ? obx_cb.client[xx].ll_cb.comm.rx_mtu : obx_cb.client[xx].ll_cb.comm.tx_mtu; - break; - } - } -#endif - } - else - { -#if (OBX_SERVER_INCLUDED == TRUE) - /* a server handle */ - p_scb = obx_sr_get_scb(handle); - /* make sure the handle is a valid one */ - if (p_scb && p_scb->ll_cb.comm.handle != OBX_HANDLE_NULL) - { - mtu = (rx) ? p_scb->ll_cb.comm.rx_mtu : p_scb->ll_cb.comm.tx_mtu; - } -#endif - } - } - - if (mtu < OBX_MIN_MTU) - mtu = OBX_MIN_MTU; - OBX_TRACE_DEBUG3("OBX_HandleToMtu handle: 0x%x, rx:%x, mtu:%d", handle, rx, mtu); - return mtu; -} - diff --git a/stack/obx/obx_md5.c b/stack/obx/obx_md5.c deleted file mode 100644 index 6e0d6ea..0000000 --- a/stack/obx/obx_md5.c +++ /dev/null @@ -1,1050 +0,0 @@ -/***************************************************************************** -** -** Name: obx_md5.c -** -** File: OBEX Authentication related functions -** -** Copyright (c) 2003-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <stdio.h> -#include <string.h> - -#include "bt_target.h" -#include "btu.h" -#include "obx_int.h" -#include "wcassert.h" - - - -/* -* This code implements the MD5 message-digest algorithm. -* The algorithm is due to Ron Rivest. This code was -* written by Colin Plumb in 1993, no copyright is claimed. -* This code is in the public domain; do with it what you wish. -* -* Equivalent code is available from RSA Data Security, Inc. -* This code has been tested against that, and is equivalent, -* except that you don't need to include two pages of legalese -* with every copy. -* -* To compute the message digest of a chunk of bytes, declare an -* MD5Context structure, pass it to MD5Init, call MD5Update as -* needed on buffers full of bytes, and then call MD5Final, which -* will fill a supplied 16-byte array with the digest. -*/ -typedef UINT32 word32; -typedef UINT8 byte; -struct xMD5Context { - word32 buf[4]; - word32 bytes[2]; - word32 in[16]; -}; - -static void obx_md5_transform(word32 buf[4], word32 const in[16]); - -/* -* Shuffle the bytes into little-endian order within words, as per the -* MD5 spec. Note: this code works regardless of the byte order. -*/ -static void obx_byte_swap(word32 *buf, unsigned words) -{ - byte *p = (byte *)buf; - do { - *buf++ = (word32)((unsigned)p[3] << 8 | p[2]) << 16 - | (word32)((unsigned)p[1] << 8 | p[0]); - p += 4; - } while (--words); -} - -/* -* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious -* initialization constants. -*/ -static void obx_md5_init(struct xMD5Context *ctx) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - ctx->bytes[0] = 0; - ctx->bytes[1] = 0; -} - -/* -* Update context to reflect the concatenation of another buffer full -* of bytes. -*/ -static void obx_md5_update(struct xMD5Context *ctx, byte const *buf, int len) -{ - word32 t; - /* Update byte count */ - t = ctx->bytes[0]; - if ((ctx->bytes[0] = t + len) < t) - ctx->bytes[1]++; /* Carry from low to high */ - t = 64 - (t & 0x3f); /* Space avail in ctx->in (at least 1) */ - if ((unsigned)t > (unsigned)len) - { - memcpy ((byte *)ctx->in + 64 - (unsigned)t, buf, len); - return; - } - /* First chunk is an odd size */ - memcpy (ctx->in + (64 - (unsigned)t), buf, (unsigned)t); - obx_byte_swap(ctx->in, 16); - obx_md5_transform(ctx->buf, ctx->in); - buf += (unsigned)t; - len -= (unsigned)t; - /* Process data in 64-byte chunks */ - while (len >= 64) - { - /* coverity[access_dbuff_const] */ - memcpy (ctx->in, buf, 64); - obx_byte_swap(ctx->in, 16); - obx_md5_transform(ctx->buf, ctx->in); - buf += 64; - len -= 64; - } - /* Handle any remaining bytes of data. */ - memcpy (ctx->in, buf, len); -} - -/* -* Final wrapup - pad to 64-byte boundary with the bit pattern -* 1 0* (64-bit count of bits processed, MSB-first) -*/ -static void obx_md5_final(byte digest[16], struct xMD5Context *ctx) -{ - int count = (int)(ctx->bytes[0] & 0x3f); /* Bytes in ctx->in */ - byte *p = (byte *)ctx->in + count; /* First unused byte */ - /* Set the first char of padding to 0x80. There is always room.*/ - *p++ = 0x80; - /* Bytes of padding needed to make 56 bytes (-8..55) */ - count = 56 - 1 - count; - if (count < 0) /* Padding forces an extra block */ - { - memset (p, 0, count+8); - obx_byte_swap(ctx->in, 16); - obx_md5_transform(ctx->buf, ctx->in); - p = (byte *)ctx->in; - count = 56; - } - memset (p, 0, count+8); - obx_byte_swap(ctx->in, 14); - /* Append length in bits and transform */ - ctx->in[14] = ctx->bytes[0] << 3; - ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; - obx_md5_transform(ctx->buf, ctx->in); - obx_byte_swap(ctx->buf, 4); - memcpy (digest, ctx->buf, 16); - memset (ctx, 0, sizeof(ctx)); -} - -/* The four core functions - F1 is optimized somewhat */ -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f,w,x,y,z,in,s) \ -(w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x) - -/* -* The core of the MD5 algorithm, this alters an existing MD5 hash to -* reflect the addition of 16 longwords of new data. MD5Update blocks -* the data and converts bytes into longwords for this routine. -*/ -static const word32 obx_md5_f1 [] = -{ - 0xd76aa478, - 0xe8c7b756, - 0x242070db, - 0xc1bdceee, - - 0xf57c0faf, - 0x4787c62a, - 0xa8304613, - 0xfd469501, - - 0x698098d8, - 0x8b44f7af, - 0xffff5bb1, - 0x895cd7be, - - 0x6b901122, - 0xfd987193, - 0xa679438e, - 0x49b40821 -}; - -static const word32 obx_md5_f2 [] = -{ - 0xf61e2562, - 0xc040b340, - 0x265e5a51, - 0xe9b6c7aa, - - 0xd62f105d, - 0x02441453, - 0xd8a1e681, - 0xe7d3fbc8, - - 0x21e1cde6, - 0xc33707d6, - 0xf4d50d87, - 0x455a14ed, - - 0xa9e3e905, - 0xfcefa3f8, - 0x676f02d9, - 0x8d2a4c8a -}; - -static const word32 obx_md5_f3 [] = -{ - 0xfffa3942, - 0x8771f681, - 0x6d9d6122, - 0xfde5380c, - - 0xa4beea44, - 0x4bdecfa9, - 0xf6bb4b60, - 0xbebfbc70, - - 0x289b7ec6, - 0xeaa127fa, - 0xd4ef3085, - 0x04881d05, - - 0xd9d4d039, - 0xe6db99e5, - 0x1fa27cf8, - 0xc4ac5665 -}; - -static const word32 obx_md5_f4 [] = -{ - 0xf4292244, - 0x432aff97, - 0xab9423a7, - 0xfc93a039, - - 0x655b59c3, - 0x8f0ccc92, - 0xffeff47d, - 0x85845dd1, - - 0x6fa87e4f, - 0xfe2ce6e0, - 0xa3014314, - 0x4e0811a1, - - 0xf7537e82, - 0xbd3af235, - 0x2ad7d2bb, - 0xeb86d391 -}; - -static const UINT8 obx_md5_a [] = -{ - 1, - 2, - 3, - 0, - 1, - 2, - 3 -}; - -static const word32 obx_md5_var1 [] = -{ - 7, - 12, - 17, - 22 -}; - -static const word32 obx_md5_var2 [] = -{ - 5, - 9, - 14, - 20 -}; - -static const word32 obx_md5_var3 [] = -{ - 4, - 11, - 16, - 23 -}; - -static const word32 obx_md5_var4 [] = -{ - 6, - 10, - 15, - 21 -}; - -static void obx_md5_transform(word32 buf[4], word32 const in[16]) -{ - int xx, yy, zz, i, j, k; - word32 a[4]; - - a[0] = buf[0]; - a[1] = buf[1]; - a[2] = buf[2]; - a[3] = buf[3]; - - yy = 0; - for(xx=0; xx<4; xx++) - { - j = 3; - for(i=0; i < 4; i++) - { - k = j--; - /* - OBX_TRACE_DEBUG4( "f1 a: %d, yy: %d, inc: 0x%x, var: %d", - obx_md5_a[k], yy, obx_md5_f1[yy], obx_md5_var1[i]); - */ - MD5STEP(F1, a[obx_md5_a[k]], a[obx_md5_a[k+1]], a[obx_md5_a[k+2]], a[obx_md5_a[k+3]], - in[yy] + obx_md5_f1[yy], obx_md5_var1[i]); - yy++; - } - } - - yy = 1; - zz = 0; - for(xx=0; xx<4; xx++) - { - j = 3; - for(i=0; i < 4; i++) - { - k = j--; - /* - OBX_TRACE_DEBUG4( "f2 a: %d, yy: %d, inc: 0x%x, var: %d", - obx_md5_a[k], yy, obx_md5_f2[zz], obx_md5_var2[i]); - */ - MD5STEP(F2, a[obx_md5_a[k]], a[obx_md5_a[k+1]], a[obx_md5_a[k+2]], a[obx_md5_a[k+3]], - in[yy] + obx_md5_f2[zz++], obx_md5_var2[i]); - yy += 5; - yy %= 16; - } - } - - yy = 5; - zz = 0; - for(xx=0; xx<4; xx++) - { - j = 3; - for(i=0; i < 4; i++) - { - k = j--; - /* - OBX_TRACE_DEBUG4( "f3 a: %d, yy: %d, inc: 0x%x, var: %d", - obx_md5_a[k], yy, obx_md5_f3[zz], obx_md5_var3[i]); - */ - MD5STEP(F3, a[obx_md5_a[k]], a[obx_md5_a[k+1]], a[obx_md5_a[k+2]], a[obx_md5_a[k+3]], - in[yy] + obx_md5_f3[zz++], obx_md5_var3[i]); - yy += 3; - yy %= 16; - } - } - - - yy = 0; - zz = 0; - for(xx=0; xx<4; xx++) - { - j = 3; - for(i=0; i < 4; i++) - { - k = j--; - /* - OBX_TRACE_DEBUG4( "f4 a: %d, yy: %d, inc: 0x%x, var: %d", - obx_md5_a[k], yy, obx_md5_f4[zz], obx_md5_var4[i]); - */ - MD5STEP(F4, a[obx_md5_a[k]], a[obx_md5_a[k+1]], a[obx_md5_a[k+2]], a[obx_md5_a[k+3]], - in[yy] + obx_md5_f4[zz++], obx_md5_var4[i]); - yy += 7; - yy %= 16; - } - } - - buf[0] += a[0]; - buf[1] += a[1]; - buf[2] += a[2]; - buf[3] += a[3]; -} - -/******************************************************************************* -** -** Function OBX_MD5 -** -** Description This function is called to run the MD5 algorithm. -** -** Returns void -** -*******************************************************************************/ -static void OBX_MD5(void *digest, UINT8 *nonce, UINT8 * password, int password_len) -{ - struct xMD5Context context; - UINT8 before[OBX_NONCE_SIZE + OBX_MAX_AUTH_KEY_SIZE + 4]; - - memcpy(before, nonce, OBX_NONCE_SIZE); - before[OBX_NONCE_SIZE] = ':'; - memcpy(before + OBX_NONCE_SIZE + 1, password, password_len); - /* - scru_dump_hex (before, "before", OBX_NONCE_SIZE + 1 + password_len, TRACE_LAYER_OBEX, TRACE_TYPE_GENERIC); - */ - - obx_md5_init(&context); -/* coverity[overrun-buffer-val] */ -/* -FALSE-POSITIVE: coverity says "Overrun of static array "before" of size 36 bytes by passing it as an argument to a function which indexes it at byte position 63" -obx_md5_update() only goes into that condition when (len >= 64). In this case, len is (OBX_NONCE_SIZE + 1 + password_len) which is less than or equal to 33. -password_len is less than or equal to OBX_MAX_AUTH_KEY_SIZE. The size of before[] is more than enough */ - obx_md5_update(&context, (byte const *)before, OBX_NONCE_SIZE + 1 + password_len); - obx_md5_final((byte *)digest, &context); - /* - scru_dump_hex (digest, "after", 16, TRACE_LAYER_OBEX, TRACE_TYPE_GENERIC); - */ -} - -/******************************************************************************* -** -** Function obx_session_id -** -** Description This function is called to run the MD5 algorithm to create a -** session id. -** -** Returns void -** -*******************************************************************************/ -void obx_session_id(UINT8 *p_sess_id, UINT8 *p_cl_addr, UINT8 * p_cl_nonce, int cl_nonce_len, - UINT8 *p_sr_addr, UINT8 * p_sr_nonce, int sr_nonce_len) -{ - struct xMD5Context context; - UINT8 before[(OBX_NONCE_SIZE + BD_ADDR_LEN) * 2 + 4]; - UINT8 *p = before; - UINT8 len; - - memcpy(p, p_cl_addr, BD_ADDR_LEN); - p += BD_ADDR_LEN; - memcpy(p, p_cl_nonce, cl_nonce_len); - p += cl_nonce_len; - memcpy(p, p_sr_addr, BD_ADDR_LEN); - p += BD_ADDR_LEN; - memcpy(p, p_sr_nonce, sr_nonce_len); - p += sr_nonce_len; - /* - scru_dump_hex (before, "before", OBX_NONCE_SIZE + 1 + password_len, TRACE_LAYER_OBEX, TRACE_TYPE_GENERIC); - */ - - len = BD_ADDR_LEN + cl_nonce_len + BD_ADDR_LEN + sr_nonce_len; - obx_md5_init(&context); -/* coverity [overrun-buffer-val] */ -/* Overrun of static array "before" of size 48 bytes by passing it as an argument to a function which indexes it at byte position 63*/ -/* FALSE-POSITIVE: obx_md5_update() only goes into that condition when (len >= 64). In this case, len is (OBX_NONCE_SIZE + 1 + password_len) which is less than or equal to 33. -password_len is less than or equal to OBX_MAX_AUTH_KEY_SIZE. The size of before[] is more than enough */ - obx_md5_update(&context, (byte const *)before, len); - obx_md5_final((byte *)p_sess_id, &context); - /* - scru_dump_hex (p_sess_id, "after", 16, TRACE_LAYER_OBEX, TRACE_TYPE_GENERIC); - */ -} - -#if (OBX_SERVER_INCLUDED == TRUE) -/******************************************************************************* -** -** Function obx_copy_and_rm_auth_hdrs -** -** Description This function is used to copy the given OBEX packet to a new packet -** with the authentication headers removed. -** -** Returns tOBX_STATUS -** -*******************************************************************************/ -tOBX_STATUS obx_copy_and_rm_auth_hdrs(BT_HDR *p_pkt, BT_HDR *p_new, UINT8 * p_hi) -{ - tOBX_STATUS status = OBX_SUCCESS; - UINT8 *pn, *po, *p_nlen = NULL; - int hsize, nsize; - UINT16 nlen, olen; - UINT8 size; - int xx; - - WC_ASSERT(p_new); - - - po = (UINT8 *)(p_pkt + 1) + p_pkt->offset + 1; - BE_STREAM_TO_UINT16(olen, po); - OBX_TRACE_DEBUG3( "obx_copy_and_rm_auth_hdrs event: %d, new len:%d, olen:%d", - p_pkt->event, p_new->len, olen); - - po = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - if(p_new->len == 0) - { - p_new->offset = p_pkt->offset; - p_nlen = (UINT8 *)(p_new + 1) + p_new->offset + 1; - } - pn = (UINT8 *)(p_new + 1) + p_new->offset; - - /* Get the number of bytes before headers start */ - size = obx_hdr_start_offset[p_pkt->event - 1]; - if(p_new->len) - { - /* for OBX_AuthResponse - * - do not need to copy the stuff before headers - * there's already some header, skip them */ - pn += p_new->len; - nlen = p_new->len; - } - else - { - /* for obx_unauthorize_rsp - * - needs to copy the stuff before headers */ - memcpy(pn, po, size); - pn += size; - nlen = size; - } - po += size; - - olen -= size; - while(olen) - { - OBX_TRACE_DEBUG1( "olen:%d", olen); - hsize = (int)obx_read_header_len(po); - if(olen > hsize) - olen -= hsize; - else - olen = 0; - - xx = 0; - nsize = hsize; - while(p_hi[xx] != OBX_HI_NULL) - { - /* - OBX_TRACE_DEBUG2( "po:0x%x, hix:0x%x", *po, p_hi[xx]); - */ - if(*po == p_hi[xx++]) - { - nsize = 0; - break; - } - } - OBX_TRACE_DEBUG2( "hsize:%d, nsize:%d", hsize, nsize); - if(nsize) - { - /* skip auth challenge and auth response */ - if((nlen+hsize) < p_pkt->layer_specific) - { - /* copy other headers */ - memcpy(pn, po, hsize); - pn += hsize; - nlen += hsize; - } - else - { - OBX_TRACE_WARNING1( "obx_copy_and_rm_auth_hdrs Not enough room: %d", olen); - /* no more room in the new packet */ - status = OBX_NO_RESOURCES; - break; - } - } - po += hsize; - } - - if(status == OBX_SUCCESS) - { - if(p_nlen) - { - UINT16_TO_BE_STREAM(p_nlen, nlen); - } - p_new->len = nlen; - p_new->layer_specific = GKI_get_buf_size(p_new) - BT_HDR_SIZE - p_new->offset; - p_new->event = p_pkt->event; - } - - return status; -} - -/******************************************************************************* -** -** Function obx_unauthorize_rsp -** -** Description This function is used to add authentication challenge triplet -** -** Returns void. -** Note: this function assumes that all data can fit in the MTU -*******************************************************************************/ -BT_HDR * obx_unauthorize_rsp(tOBX_SR_CB *p_cb, tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - UINT8 *p; - UINT8 nonce[OBX_NONCE_SIZE+2]; - UINT8 option[2]; - UINT8 *p_target = NULL; - tOBX_TRIPLET triplet[OBX_MAX_NUM_AUTH_TRIPLET]; - UINT8 num_trip = 0; - BT_HDR *p_old; - UINT8 hi[] = {OBX_HI_CHALLENGE, OBX_HI_AUTH_RSP, OBX_HI_NULL}; - - OBX_TRACE_DEBUG1( "obx_unauthorize_rsp: %d", p_cb->target.len); - if(OBX_CheckHdr(p_pkt, OBX_HI_CHALLENGE) || OBX_CheckHdr(p_pkt, OBX_HI_AUTH_RSP)) - { - p_old = p_pkt; - p_pkt = OBX_HdrInit(p_scb->ll_cb.comm.handle, (UINT16)(p_old->len + BT_HDR_SIZE + p_old->offset)); - obx_copy_and_rm_auth_hdrs(p_old, p_pkt, hi); - GKI_freebuf(p_old); - } - - if(p_cb->target.len) - { - /* There must be the target header, change it to be WHO header */ - if( (p_target = OBX_CheckHdr(p_pkt, OBX_HI_TARGET)) != NULL) - { - *p_target = OBX_HI_WHO; - } - } - OBX_TRACE_DEBUG1( "p_target: %x", p_target); - - if(p_cb->p_auth) - { - /* server registers for authentication */ - /* prepare the triplet byte sequence */ - /* add nonce: tag, length, value */ - p_cb->p_auth->nonce = GKI_get_tick_count(); - sprintf ((char *)nonce, "%016lu", p_cb->p_auth->nonce); - - num_trip = 0; - triplet[num_trip].tag = OBX_NONCE_CHLNG_TAG; - triplet[num_trip].len = OBX_NONCE_SIZE; - triplet[num_trip].p_array = nonce; - num_trip++; - - if(p_cb->p_auth->auth_option) - { - /* add option */ - triplet[num_trip].tag = OBX_OPTIONS_CHLNG_TAG; - triplet[num_trip].len = 1; - option[0] = p_cb->p_auth->auth_option; - triplet[num_trip].p_array = option; - num_trip++; - } - if(p_cb->p_auth->realm_len) - { - /* add realm */ - triplet[num_trip].tag = OBX_REALM_CHLNG_TAG; - triplet[num_trip].len = p_cb->p_auth->realm_len+1; - triplet[num_trip].p_array = p_cb->p_auth->realm; - num_trip++; - } - - /* add the sequence to header */ - OBX_AddTriplet(p_pkt, OBX_HI_CHALLENGE, triplet, num_trip); - } - - p = (UINT8 *)(p_pkt + 1) + p_pkt->offset; - /* change the opcode to unauthorized response */ - *p++ = OBX_RSP_UNAUTHORIZED | OBX_FINAL; - /* adjust the packet len */ - UINT16_TO_BE_STREAM(p, p_pkt->len); - - /* add session sequence number, if session is active */ - if ((p_scb->sess_st == OBX_SESS_ACTIVE) && ((p_target = OBX_CheckHdr(p_pkt, OBX_HI_SESSION_SN)) != NULL)) - { - p_target++; - (*p_target)++; - } - - p_pkt->event = OBX_CONNECT_RSP_EVT; - - return p_pkt; -} - -/******************************************************************************* -** -** Function OBX_Password -** -** Description This function is called by the server to respond to an -** OBX_PASSWORD_EVT event. -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if OBX does not resources -** -*******************************************************************************/ -tOBX_STATUS OBX_Password(tOBX_HANDLE shandle, UINT8 *p_password, UINT8 password_len, - UINT8 *p_userid, UINT8 userid_len) -{ - tOBX_STATUS status = OBX_SUCCESS; - BT_HDR *p_pkt; - BT_HDR *p_rsp; - UINT8 temp_digest[OBX_DIGEST_SIZE]; - UINT8 nonce[OBX_NONCE_SIZE + 1]; - BOOLEAN pass = FALSE; - BOOLEAN digest_done = FALSE; - BOOLEAN option_userid = FALSE; - tOBX_TRIPLET triplet[OBX_MAX_NUM_AUTH_TRIPLET]; - UINT8 num_trip = OBX_MAX_NUM_AUTH_TRIPLET; - UINT8 xx; - UINT8 *p_target; - UINT16 tlen; - tOBX_SR_SESS_CB *p_scb = obx_sr_get_scb(shandle); - tOBX_SR_CB *p_cb = obx_sr_get_cb(shandle); - UINT8 *p; - tOBX_EVT_PARAM param; /* The event parameter. */ - - WC_ASSERT(password_len < OBX_MAX_AUTH_KEY_SIZE); - - if(p_scb == NULL || p_scb->p_saved_msg == NULL) - return OBX_NO_RESOURCES; - - /* The coverity complaints on this function is not correct. - * The value in triplet[] is set/initialized by OBX_ReadTriplet if num_trip returns TRUE. - * leave this unnecessary memset here */ - memset(triplet,0,sizeof(triplet)); - - p_pkt = p_scb->p_saved_msg; - - if(p_cb->p_auth == NULL) - { - pass = TRUE; - } - else if(OBX_ReadTriplet(p_pkt, OBX_HI_AUTH_RSP, triplet, &num_trip) == TRUE) - { - if(p_password && password_len ) - { - /* if given password, verify it */ - for(xx=0; xx<num_trip; xx++) - { - if(triplet[xx].tag == OBX_DIGEST_RSP_TAG) - { - sprintf((char *)nonce, "%016lu", p_cb->p_auth->nonce); - OBX_MD5 (temp_digest, nonce, p_password, password_len); - if (memcmp (temp_digest, triplet[xx].p_array, OBX_DIGEST_SIZE) == 0) - pass = TRUE; - break; - } - } - } - } - - /* check if challenged by client */ - num_trip = OBX_MAX_NUM_AUTH_TRIPLET; - if(pass == TRUE && OBX_ReadTriplet(p_pkt, OBX_HI_CHALLENGE, triplet, &num_trip) == TRUE) - { - /* Make sure password was passed in and not empty */ - if (p_password && password_len ) - { - for(xx=0; xx<num_trip; xx++) - { - if(triplet[xx].tag == OBX_NONCE_CHLNG_TAG) - { - /* nonce tag is mandatory */ - OBX_MD5 (temp_digest, triplet[xx].p_array, p_password, password_len); - digest_done = TRUE; - } - else if(triplet[xx].tag == OBX_OPTIONS_CHLNG_TAG) - { - /* user ID bit is set */ - if(OBX_AO_USR_ID & triplet[xx].p_array[0]) - option_userid = TRUE; - } - } - - if (option_userid && (userid_len == 0 || p_userid == NULL) ) - { - status = OBX_BAD_PARAMS; - } - } - } - - if(status == OBX_SUCCESS) - { - p_scb->p_saved_msg = NULL; - if(pass == TRUE) - { - p_rsp = OBX_HdrInit(shandle, OBX_MIN_MTU); - - /* add the authentication response if been challenged */ - if(digest_done) - { - num_trip = 1; - triplet[0].tag = OBX_DIGEST_RSP_TAG; - triplet[0].len = OBX_DIGEST_SIZE; - triplet[0].p_array = temp_digest; - if(option_userid) - { - num_trip++; - triplet[1].tag = OBX_USERID_RSP_TAG; - triplet[1].len = userid_len; - triplet[1].p_array = p_userid; - } - OBX_AddTriplet(p_rsp, OBX_HI_AUTH_RSP, triplet, num_trip); - } - - if( p_cb->target.len == OBX_DEFAULT_TARGET_LEN && - OBX_ReadTargetHdr(p_pkt, &p_target, &tlen, 0) == TRUE) - { - /* API user is supposed to handle WHO header - * for this special case, we add it for the API user */ - OBX_AddWhoHdr(p_rsp, p_target, tlen); - } - - /* use OBX_ConnectRsp to fill the common data */ - status = OBX_ConnectRsp(shandle, OBX_RSP_OK, p_rsp); - if(status == OBX_SUCCESS) - { - /* If authentication is successful, need to update session info */ - p = &p_scb->sess_info[OBX_SESSION_INFO_ID_IDX]; - UINT32_TO_BE_STREAM(p, p_scb->conn_id); - param.sess.p_sess_info = p_scb->sess_info; - param.sess.sess_op = OBX_SESS_OP_CREATE; - param.sess.sess_st = p_scb->sess_st; - param.sess.nssn = p_scb->param.ssn; - param.sess.ssn = p_scb->param.ssn; - param.sess.obj_offset = 0; - p = &p_scb->sess_info[OBX_SESSION_INFO_MTU_IDX]; - UINT16_TO_BE_STREAM(p, p_scb->param.conn.mtu); - memcpy(param.sess.peer_addr, p_scb->peer_addr, BD_ADDR_LEN); - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_SESSION_REQ_EVT, param, p_pkt); - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_CONNECT_REQ_EVT, p_scb->param, p_pkt); - } - else - GKI_freebuf(p_pkt); - } - else - { - /* server can not find the password, send unauthorized response */ - p_pkt = obx_unauthorize_rsp(p_cb, p_scb, p_pkt); - obx_ssm_event(p_scb, OBX_CONNECT_CFM_SEVT, p_pkt); - } - } - /* - else p_scb->p_saved_msg is still valid. - */ - - return status; -} -#endif - - -#if (OBX_CLIENT_INCLUDED == TRUE) -/******************************************************************************* -** -** Function OBX_AuthResponse -** -** Description This function is called by the client to respond to an -** OBX_PASSWORD_EVT event. -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if OBX does not resources -** -*******************************************************************************/ -tOBX_STATUS OBX_AuthResponse(tOBX_HANDLE handle, - UINT8 *p_password, UINT8 password_len, - UINT8 *p_userid, UINT8 userid_len, - BOOLEAN authenticate) -{ - tOBX_CL_CB *p_cb = obx_cl_get_cb(handle); - tOBX_STATUS status = OBX_NO_RESOURCES; - BT_HDR *p_pkt; - BT_HDR *p_saved_req; - UINT8 num_trip, flags = 0; - UINT16 nlen, xx; - UINT8 temp_digest[OBX_DIGEST_SIZE]; - UINT8 nonce[OBX_NONCE_SIZE + 1]; - BOOLEAN digest_done = FALSE; - BOOLEAN option_userid = FALSE; - UINT8 rsp_code; - BOOLEAN final; - UINT8 *p_target; - tOBX_TRIPLET triplet[OBX_MAX_NUM_AUTH_TRIPLET]; - UINT8 hi[] = {OBX_HI_CONN_ID, OBX_HI_TARGET, OBX_HI_CHALLENGE, OBX_HI_AUTH_RSP, - OBX_HI_SESSION_SN, /* prevent SSN from being copied */ - OBX_HI_NULL}; - WC_ASSERT(password_len < OBX_MAX_AUTH_KEY_SIZE); - WC_ASSERT(p_password); - - if(p_cb == NULL || p_cb->p_auth == NULL || p_cb->p_saved_req == NULL) - return OBX_NO_RESOURCES; - - p_saved_req = p_cb->p_saved_req; - p_pkt = OBX_HdrInit(handle, GKI_MAX_BUF_SIZE); /* make sure added length will fit */ - WC_ASSERT(p_pkt); - OBX_TRACE_DEBUG2("OBX_AuthResponse p_saved_req:%d, p_saved_req->len %d ", - p_saved_req->event, p_saved_req->len); - - /* if the save_req contains SSN, add it now */ - if ((p_target = OBX_CheckHdr(p_saved_req, OBX_HI_SESSION_SN)) != NULL) - { - p_target++; - OBX_Add1ByteHdr(p_pkt, OBX_HI_SESSION_SN, (UINT8)((*p_target) + 1)); - } - - /* The coverity complaints on this function is not correct. - * The value in triplet[] is set/initialized by OBX_ReadTriplet if num_trip returns TRUE. - * leave this unnecessary memset here */ - memset(triplet,0,sizeof(triplet)); - - /* if target header exists in the original request - * and the Connection ID has not been assigned yet, - * copy the target header over */ - if(OBX_ReadTargetHdr(p_saved_req, &p_target, &nlen, 0) == TRUE) - { - OBX_AddTargetHdr(p_pkt, p_target, nlen); - } - - /* read the challenge from received packet */ - num_trip = OBX_MAX_NUM_AUTH_TRIPLET; - if(OBX_ReadTriplet(p_cb->p_auth, OBX_HI_CHALLENGE, triplet, &num_trip) == TRUE) - { - status = OBX_SUCCESS; - for(xx=0; xx<num_trip; xx++) - { - if(triplet[xx].tag == OBX_NONCE_CHLNG_TAG) - { - /* nonce tag is mandatory */ - OBX_MD5 (temp_digest, triplet[xx].p_array, p_password, password_len); - digest_done = TRUE; - } - else if(triplet[xx].tag == OBX_OPTIONS_CHLNG_TAG) - { - /* user ID bit is set */ - if(OBX_AO_USR_ID & triplet[xx].p_array[0]) - option_userid = TRUE; - } - } - - if(option_userid && (userid_len == 0 || p_userid == NULL) ) - { - status = OBX_BAD_PARAMS; - } - OBX_TRACE_DEBUG2( "num_trip:%d, option_userid:%d", num_trip, option_userid); - - if(digest_done && status == OBX_SUCCESS) - { - /* Compose and add the authentication Response header */ - num_trip = 1; - triplet[0].tag = OBX_DIGEST_RSP_TAG; - triplet[0].len = OBX_DIGEST_SIZE; - triplet[0].p_array = temp_digest; - if(option_userid) - { - /* add user id */ - num_trip++; - triplet[1].tag = OBX_USERID_RSP_TAG; - triplet[1].len = userid_len; - triplet[1].p_array = p_userid; - } - OBX_AddTriplet(p_pkt, OBX_HI_AUTH_RSP, triplet, num_trip); - - /* if we want to authenticate the server, add the challenge header here */ - /* Note: we only do it for the CONNECT request */ - if(authenticate && p_saved_req->event == OBX_CONNECT_REQ_EVT) - { - /* Indicate in the control block to verify the response */ - p_cb->wait_auth = TRUE; - - /* add the challenge nonce */ - num_trip = 1; - triplet[0].tag = OBX_NONCE_CHLNG_TAG; - triplet[0].len = OBX_NONCE_SIZE; - triplet[0].p_array = nonce; - sprintf ((char *)nonce, "%016lu", GKI_get_tick_count()); - OBX_AddTriplet(p_pkt, OBX_HI_CHALLENGE, triplet, num_trip); - OBX_MD5 ((UINT8 *)(p_cb->p_auth), nonce, p_password, password_len); - } - - /* copy non-(target, conn_id, authentication) headers from p_saved_req. */ - status = obx_copy_and_rm_auth_hdrs(p_saved_req, p_pkt, hi); - OBX_TRACE_DEBUG4( "status:%d, save:%d, pkt:%d, off:%d", - status, p_saved_req->event, p_pkt->event, p_pkt->offset); - - if(status == OBX_SUCCESS) - { - /* get the final from the saved request */ - rsp_code = OBX_RSP_DEFAULT; - obx_access_rsp_code(p_saved_req, &rsp_code); - final = (rsp_code & OBX_FINAL) ? TRUE : FALSE; - OBX_TRACE_DEBUG1( "saved final:%d", final); - - /* call the associated API function to send the request again */ - switch(p_pkt->event) - { - case OBX_CONNECT_REQ_EVT: - status = OBX_ConnectReq((BD_ADDR_PTR)BT_BD_ANY, 0, 0, NULL, &p_cb->ll_cb.comm.handle, p_pkt); - break; - case OBX_PUT_REQ_EVT: - status = OBX_PutReq(handle, final, p_pkt); - break; - case OBX_GET_REQ_EVT: - status = OBX_GetReq(handle, final, p_pkt); - break; - case OBX_SETPATH_REQ_EVT: - /* get the flags from old request - if SetPath */ - flags = *((UINT8 *)(p_saved_req + 1) + p_saved_req->offset + 3); - status = OBX_SetPathReq(handle, flags, p_pkt); - break; - default: - /* it does not make sense to authenticate on Abort and Disconnect */ - OBX_TRACE_WARNING1( "Authenticate on bad request: %d", p_pkt->event); - status = OBX_NO_RESOURCES; - } /* switch (event) */ - } - } /* digest done */ - } /* challenge heaer exists */ - - if(status != OBX_SUCCESS) - { - GKI_freebuf(p_pkt); - } - - if(p_cb->wait_auth == FALSE) - { - GKI_freebuf(p_cb->p_auth); - p_cb->p_auth = NULL; - } - return status; -} - -#if (OBX_MD5_TEST_INCLUDED == TRUE) -/******************************************************************************* -** -** Function OBX_VerifyResponse -** -** Description This function is called by the client to verify the challenge -** response. -** -** Returns TRUE, if successful. -** FALSE, if authentication failed -** -*******************************************************************************/ -BOOLEAN OBX_VerifyResponse(UINT32 nonce_u32, UINT8 *p_password, UINT8 password_len, UINT8 *p_response) -{ - BOOLEAN status = FALSE; - UINT8 nonce[OBX_NONCE_SIZE + 1]; - UINT8 temp_digest[OBX_DIGEST_SIZE]; - - OBX_TRACE_API0( "OBX_VerifyResponse"); - if (p_password && password_len) - { - sprintf((char *)nonce, "%016lu", nonce_u32); - OBX_MD5 (temp_digest, nonce, p_password, password_len); - if (memcmp (temp_digest, p_response, OBX_DIGEST_SIZE) == 0) - status = TRUE; - } - return status; -} -#endif /* OBX_MD5_TEST_INCLUDED */ - - -#endif - - - diff --git a/stack/obx/obx_rfc.c b/stack/obx/obx_rfc.c deleted file mode 100644 index b02fbef..0000000 --- a/stack/obx/obx_rfc.c +++ /dev/null @@ -1,613 +0,0 @@ -/***************************************************************************** -** -** Name: obx_rfc.c -** -** File: OBEX interface to the RFCOMM module -** -** Copyright (c) 2003-2008, Broadcom Corp., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include "wcassert.h" - -#include "bt_target.h" -#include "obx_int.h" - -#include "port_api.h" -#include "sdpdefs.h" -#include "btu.h" - -/******************************************************************************* -** Function obx_rfc_snd_evt -** Description Sends an rfcomm event to OBX through the BTU task. -*******************************************************************************/ -static void obx_rfc_snd_evt (tOBX_PORT_CB *p_pcb, UINT32 code) -{ - BT_HDR *p_msg; - tOBX_PORT_EVT *p_evt; - UINT16 event; - - if (!p_pcb) - return; - - p_msg = (BT_HDR*)GKI_getbuf(BT_HDR_SIZE + sizeof(tOBX_PORT_EVT)); - WC_ASSERT(p_msg); - - if (p_pcb->handle & OBX_CL_HANDLE_MASK) - event = BT_EVT_TO_OBX_CL_MSG; - else - event = BT_EVT_TO_OBX_SR_MSG; - - p_msg->event = event; - p_msg->len = sizeof(tOBX_PORT_EVT); - p_msg->offset = 0; - p_evt = (tOBX_PORT_EVT *)(p_msg + 1); - p_evt->code = code; - p_evt->p_pcb = p_pcb; - - GKI_send_msg(BTU_TASK, BTU_HCI_RCV_MBOX, p_msg); -} - -/******************************************************************************* -** Function obx_rfc_cback -** Description find the port control block and post an event to BTU task. -** NOTE: This callback does not handle connect up/down events. -** obx_rfc_mgmt_cback is used for these events. -*******************************************************************************/ -static void obx_rfc_cback (UINT32 code, UINT16 port_handle) -{ - tOBX_PORT_CB *p_pcb = obx_port_handle_2cb(port_handle); - - if (p_pcb) - { - obx_rfc_snd_evt (p_pcb, code); - } - else - { - OBX_TRACE_WARNING0("Can not find control block"); - } -} - -/******************************************************************************* -** Function obx_rfc_mgmt_cback -** Callback registered with the PORT entity's Management Callback so that OBX -** can be notified when the connection has come up or gone down. -********************************************************************************/ -void obx_rfc_mgmt_cback(UINT32 port_status, UINT16 port_handle) -{ - tOBX_PORT_CB *p_pcb = obx_port_handle_2cb(port_handle); - UINT32 code; - -#if (OBX_CLIENT_INCLUDED == TRUE) - if (!p_pcb && port_status != PORT_SUCCESS) - { - /* See if error called within RFCOMM_CreateConnection */ - if (obx_cb.p_temp_pcb) - { - p_pcb = obx_cb.p_temp_pcb; - obx_cb.p_temp_pcb = NULL; - } - } -#endif - - if (p_pcb) - { - code = (port_status == PORT_SUCCESS) ? PORT_EV_CONNECTED : PORT_EV_CONNECT_ERR; - obx_rfc_snd_evt (p_pcb, code); - } - else - { - OBX_TRACE_WARNING0("mgmt cback: Can not find control block"); - } -} - - -/******************************************************************************* -** Function obx_read_data -** Description This functions reads data from FRCOMM. Return a message if the -** whole packet is read. -** The following defines how BT_HDR is used in this function -** event: response or request event code -** len: the length read so far. -** offset: offset to the beginning of the actual data. -** layer_specific: left -*******************************************************************************/ -static BT_HDR * obx_read_data (tOBX_PORT_CB *p_pcb, tOBX_VERIFY_OPCODE p_verify_opcode) -{ - BT_HDR *p_ret = NULL; - UINT8 *p; - UINT16 ask_len; - UINT16 got_len; - int rc; - tOBX_RX_HDR *p_rxh; - tOBX_SR_SESS_CB *p_scb; - UINT8 opcode; - UINT16 pkt_len; - BOOLEAN failed = FALSE; - - OBX_TRACE_DEBUG1("obx_read_data port_handle:%d", p_pcb->port_handle ); - for (;;) - { - if (p_pcb->p_rxmsg == NULL) - { - p_pcb->p_rxmsg = OBX_HdrInit((tOBX_HANDLE)(p_pcb->handle|OBX_HANDLE_RX_MTU_MASK), - OBX_LRG_DATA_POOL_SIZE); - memset((p_pcb->p_rxmsg + 1), 0, sizeof(tOBX_RX_HDR)); - } - /* we use this header to keep the status of this packet (instead of in control block) */ - p_rxh = (tOBX_RX_HDR *)(p_pcb->p_rxmsg + 1); - - ask_len = 0; - if (p_rxh->code == 0) - { - if (p_pcb->p_rxmsg->len == 0) /* we need this if statement in case of "throw away" */ - ask_len = 1; - } - else if (p_pcb->p_rxmsg->len < (OBX_PKT_LEN_SIZE + 1) ) - { - /* if we do not know the packet len yet, read from port */ - ask_len = OBX_PKT_LEN_SIZE + 1 - p_pcb->p_rxmsg->len; - } - else - { - /* we already know the packet len. - * determine how many more bytes we need for this packet */ - ask_len = p_rxh->pkt_len - p_pcb->p_rxmsg->len; - } - - /* the position of next byte to read */ - p = (UINT8 *)(p_pcb->p_rxmsg + 1) + p_pcb->p_rxmsg->offset + p_pcb->p_rxmsg->len; - - if (ask_len) - { - rc = PORT_ReadData( p_pcb->port_handle, (char*)p, ask_len, &got_len); - if (rc != PORT_SUCCESS) - { - OBX_TRACE_WARNING2("Error %d returned from PORT_Read_Data, len:%d", rc, got_len); - } - - OBX_TRACE_DEBUG2("ask_len: %d, got_len:%d", ask_len, got_len ); - if (got_len == 0) - { - /* If we tried to read but did not get anything, */ - /* there is nothing more to read at this time */ - break; - } - p_pcb->p_rxmsg->len += got_len; - p_pcb->p_rxmsg->layer_specific -= got_len; - } - - /* process the response/opcode, if not yet */ - if (p_rxh->code == 0 && p_pcb->p_rxmsg->len) - { - opcode = *((UINT8 *)(p_pcb->p_rxmsg + 1) + p_pcb->p_rxmsg->offset); - if ( (p_verify_opcode)(opcode, p_rxh) == OBX_BAD_SM_EVT) - { - OBX_TRACE_WARNING1("bad opcode:0x%x - Disconnecting", opcode ); - /* received data with bad length. */ - - /*bad length disconnect */ - failed = TRUE; - break; - } - continue; - } - - /* process the packet len */ - if (p_rxh->pkt_len == 0 && p_pcb->p_rxmsg->len >= (OBX_PKT_LEN_SIZE + 1) ) - { - p = (UINT8 *)(p_pcb->p_rxmsg + 1) + p_pcb->p_rxmsg->offset + 1; - BE_STREAM_TO_UINT16(pkt_len, p); - - if ( (pkt_len > p_pcb->rx_mtu) || - (pkt_len < 3) || - (pkt_len == 4) ) - { - /* received data with bad length. */ - OBX_TRACE_WARNING2("Received bad packet len -Disconnecting: %d RX MTU: %x", - pkt_len, p_pcb->rx_mtu); - /*bad length disconnect */ - failed = TRUE; - break; - } - else - { - /* keep the packet len in the header */ - p_rxh->pkt_len = pkt_len; - } - continue; - } - - if (p_pcb->p_rxmsg->len == p_rxh->pkt_len) - { - /* received a whole packet */ - OBX_TRACE_DEBUG1("got a packet. opcode:0x%x", p_rxh->code ); - p_ret = p_pcb->p_rxmsg; - p_pcb->p_rxmsg = NULL; - break; - } - - } - - if (failed) - { - if (p_pcb->handle & OBX_CL_HANDLE_MASK) - { - obx_close_port(p_pcb->port_handle); - } - else - { - if ((p_scb = obx_sr_get_scb(p_pcb->handle)) != NULL) - obx_ssm_event(p_scb, OBX_PORT_CLOSE_SEVT, NULL); - - } - p_ret = NULL; - } - - return p_ret; -} - - -#if (OBX_CLIENT_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_cl_proc_evt -** Description This is called to process BT_EVT_TO_OBX_CL_MSG -** Process events from RFCOMM. Get the associated client control -** block. If this is a response packet, stop timer. Call -** obx_csm_event() with event OK_CFM, FAIL_CFM or CONT_CFM. -*******************************************************************************/ -void obx_cl_proc_evt(tOBX_PORT_EVT *p_evt) -{ - tOBX_PORT_CB *p_pcb = p_evt->p_pcb; - tOBX_CL_CB *p_cb = obx_cl_get_cb(p_pcb->handle); - BT_HDR *p_pkt; - - if (p_cb == NULL) - { - /* probably already close the port and deregistered from OBX */ - OBX_TRACE_ERROR1("Could not find control block for handle: 0x%x", p_pcb->handle); - return; - } - - if (p_evt->code & PORT_EV_CONNECT_ERR) - { - obx_csm_event(p_cb, OBX_PORT_CLOSE_CEVT, NULL); - return; - } /* PORT_EV_CONNECT_ERR */ - - if (p_evt->code & PORT_EV_TXEMPTY) - { - obx_csm_event(p_cb, OBX_TX_EMPTY_CEVT, NULL); - } /* PORT_EV_TXEMPTY */ - - if (p_evt->code & PORT_EV_RXCHAR) - { - while( (p_pkt = obx_read_data(p_pcb, obx_verify_response)) != NULL ) - { - if (GKI_queue_is_empty(&p_pcb->rx_q)) - { - if (p_pkt->event != OBX_BAD_SM_EVT) - { - obx_cl_proc_pkt (p_cb, p_pkt); - } - else - { - OBX_TRACE_ERROR0("bad SM event" ); - } - } - else if (p_pkt->event != OBX_BAD_SM_EVT) - { - GKI_enqueue (&p_pcb->rx_q, p_pkt); - if (p_pcb->rx_q.count > obx_cb.max_rx_qcount) - { - p_pcb->stopped = TRUE; - PORT_FlowControl(p_pcb->port_handle, FALSE); - } - } - } /* while received a packet */ - } /* PORT_EV_RXCHAR */ - - if (p_evt->code & PORT_EV_FC) - { - if (p_evt->code & PORT_EV_FCS) - { - OBX_TRACE_EVENT0("cl flow control event - FCS SET ----" ); - obx_csm_event(p_cb, OBX_FCS_SET_CEVT, NULL); - } - } /* PORT_EV_FC */ -} -#endif - -#if (OBX_SERVER_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_build_dummy_rsp -** Description make up a dummy response if the app does not call response API -** yet and AbortRsp is called -*******************************************************************************/ -BT_HDR * obx_build_dummy_rsp(tOBX_SR_SESS_CB *p_scb, UINT8 rsp_code) -{ - BT_HDR *p_pkt; - UINT8 *p; - UINT16 size = 3; - - p_pkt = OBX_HdrInit(p_scb->ll_cb.comm.handle, OBX_CMD_POOL_SIZE); - p = (UINT8 *)(p_pkt+1)+p_pkt->offset+p_pkt->len; - *p++ = (rsp_code|OBX_FINAL); - if (p_scb->conn_id) - { - size += 5; - UINT16_TO_BE_STREAM(p, size); - *p++ = OBX_HI_CONN_ID; - UINT32_TO_BE_STREAM(p, p_scb->conn_id); - } - else - { - UINT16_TO_BE_STREAM(p, size); - } - p_pkt->len = size; - p_pkt->event = OBX_PUT_RSP_EVT; /* or OBX_GET_RSP_EVT: for tracing purposes */ - return p_pkt; -} - -/******************************************************************************* -** Function obx_add_port -** Description check if this server has aother un-used port to open -** -** -** Returns void -*******************************************************************************/ -void obx_add_port(tOBX_HANDLE obx_handle) -{ - tOBX_SR_CB * p_cb = obx_sr_get_cb(obx_handle); - tOBX_SR_SESS_CB *p_scb, *p_scb0; - int xx; - tOBX_STATUS status = OBX_NO_RESOURCES; - BOOLEAN found; - - OBX_TRACE_DEBUG1("obx_add_port handle:0x%x", obx_handle ); - if (p_cb && p_cb->scn) - { - OBX_TRACE_DEBUG2("num_sess:%d scn:%d", p_cb->num_sess, p_cb->scn ); - p_scb0 = &obx_cb.sr_sess[p_cb->sess[0]-1]; - found = FALSE; - /* find an RFCOMM port that is not connected yet */ - for (xx=0; xx < p_cb->num_sess && p_cb->sess[xx]; xx++) - { - p_scb = &obx_cb.sr_sess[p_cb->sess[xx]-1]; - OBX_TRACE_DEBUG3("[%d] id:0x%x, state:%d", xx, p_scb->ll_cb.comm.id, p_scb->state ); - - if (p_scb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg - && p_scb->state == OBX_SS_NOT_CONNECTED) - { - found = TRUE; - break; - } - } - - if (!found) - { - for (xx=0; xx < p_cb->num_sess && p_cb->sess[xx]; xx++) - { - p_scb = &obx_cb.sr_sess[p_cb->sess[xx]-1]; - OBX_TRACE_DEBUG2("[%d] port_handle:%d", xx, p_scb->ll_cb.port.port_handle ); - if (!p_scb->ll_cb.comm.id) - { - status = obx_open_port(&p_scb->ll_cb.port, BT_BD_ANY, p_cb->scn); - if (status == OBX_SUCCESS) - { - p_scb->ll_cb.port.rx_mtu= p_scb0->ll_cb.port.rx_mtu; - p_scb->state = OBX_SS_NOT_CONNECTED; - } - break; - } - } - } - } -} - -/******************************************************************************* -** Function obx_sr_proc_evt -** Description This is called to process BT_EVT_TO_OBX_SR_MSG -** Process events from RFCOMM. Get the associated server control -** block. If this is a request packet, stop timer. Find the -** associated API event and save it in server control block -** (api_evt). Fill the event parameter (param). -** Call obx_ssm_event() with the associated events.If the associated -** control block is not found (maybe the target header does not -** match) or busy, compose a service unavailable response and call -** obx_rfc_snd_msg(). -*******************************************************************************/ -void obx_sr_proc_evt(tOBX_PORT_EVT *p_evt) -{ - tOBX_SR_SESS_CB *p_scb; - BT_HDR *p_pkt; - tOBX_RX_HDR *p_rxh; - tOBX_PORT_CB *p_pcb = p_evt->p_pcb; - - - OBX_TRACE_DEBUG2("obx_sr_proc_evt handle: 0x%x, port_handle:%d", p_evt->p_pcb->handle, p_evt->p_pcb->port_handle); - if (p_pcb->handle == 0 || p_pcb->p_send_fn != (tOBX_SEND_FN*)obx_rfc_snd_msg) - return; - - if ((p_scb = obx_sr_get_scb(p_pcb->handle)) == NULL) - { - /* probably already close the port and deregistered from OBX */ - OBX_TRACE_ERROR1("Could not find control block for handle: 0x%x", p_pcb->handle); - return; - } - - if (p_evt->code & PORT_EV_CONNECTED) - { - p_scb->ll_cb.port.tx_mtu = OBX_MIN_MTU; - obx_start_timer(&p_scb->ll_cb.comm); - /* Get the Bd_Addr */ - PORT_CheckConnection (p_scb->ll_cb.port.port_handle, - p_scb->param.conn.peer_addr, - NULL); - memcpy(p_scb->peer_addr, p_scb->param.conn.peer_addr, BD_ADDR_LEN); - } - - if (p_evt->code & PORT_EV_CONNECT_ERR) - { - obx_ssm_event(p_scb, OBX_PORT_CLOSE_SEVT, NULL); - return; - } /* PORT_EV_CONNECT_ERR */ - - if (p_evt->code & PORT_EV_RXCHAR) - { - while( (p_pkt = obx_read_data(p_pcb, obx_verify_request)) != NULL) - { - p_rxh = (tOBX_RX_HDR *)(p_pkt + 1); - p_pkt->event = obx_sm_evt_to_api_evt[p_rxh->sm_evt]; - if (GKI_queue_is_empty(&p_pcb->rx_q)) - { - if (p_pkt->event != OBX_BAD_SM_EVT) - { - obx_sr_proc_pkt (p_scb, p_pkt); - } - else - { - OBX_TRACE_ERROR0("bad SM event" ); - } - } - else - { - GKI_enqueue (&p_pcb->rx_q, p_pkt); - if (p_pcb->rx_q.count > obx_cb.max_rx_qcount) - { - p_pcb->stopped = TRUE; - PORT_FlowControl(p_pcb->port_handle, FALSE); - } - } - } /* while a packet */ - } /* PORT_EV_RXCHAR */ - - /* The server does not need to handle this event - */ - if (p_evt->code & PORT_EV_TXEMPTY) - { - obx_ssm_event(p_scb, OBX_TX_EMPTY_SEVT, NULL); - } - - if (p_evt->code & PORT_EV_FC) - { - if (p_evt->code & PORT_EV_FCS) - { - OBX_TRACE_EVENT0("sr flow control event - FCS SET ----" ); - obx_ssm_event(p_scb, OBX_FCS_SET_SEVT, NULL); - } - } /* PORT_EV_FC */ -} -#endif /* OBX_SERVER_INCLUDED */ - -/******************************************************************************* -** Function obx_open_port -** Description Call RFCOMM_CreateConnection() to get port_handle. -** Call PORT_SetEventCallback() with given callback. -** Call PORT_SetEventMask() with given event mask. Return port handle. -** Returns port handle -*******************************************************************************/ -tOBX_STATUS obx_open_port(tOBX_PORT_CB *p_pcb, const BD_ADDR bd_addr, UINT8 scn) -{ - tOBX_STATUS status = OBX_SUCCESS; /* successful */ - UINT16 port_rc; - BOOLEAN is_server = (p_pcb->handle & OBX_CL_HANDLE_MASK)?FALSE:TRUE; - UINT16 max_mtu = OBX_MAX_MTU; - - OBX_TRACE_DEBUG2("obx_open_port rxmtu:%d, cbmtu:%d", p_pcb->rx_mtu, max_mtu ); - - /* clear buffers from previous connection */ - obx_free_buf ((tOBX_LL_CB*)p_pcb); - - /* make sure the MTU is in registered range */ - if (p_pcb->rx_mtu > max_mtu) - p_pcb->rx_mtu = max_mtu; - if (p_pcb->rx_mtu < OBX_MIN_MTU) - p_pcb->rx_mtu = OBX_MIN_MTU; - -#if (OBX_CLIENT_INCLUDED == TRUE) - /* There's a remote chance that an error can occur in L2CAP before the handle - * before the handle can be assigned (server side only). We will save the - * client control block while the handle is not known */ - if (!is_server) - { - obx_cb.p_temp_pcb = p_pcb; - } -#endif - - port_rc = RFCOMM_CreateConnection ( UUID_PROTOCOL_OBEX, scn, - is_server, (UINT16)(p_pcb->rx_mtu+1), (BD_ADDR_PTR)bd_addr, - &p_pcb->port_handle, obx_rfc_mgmt_cback); - - OBX_TRACE_DEBUG3("obx_open_port rxmtu:%d, port_handle:%d, port.handle:0x%x", - p_pcb->rx_mtu, p_pcb->port_handle, p_pcb->handle ); - -#if (OBX_CLIENT_INCLUDED == TRUE) - if (!is_server) - { - obx_cb.p_temp_pcb = NULL; - } -#endif - - if (port_rc == PORT_SUCCESS) - { - obx_cb.hdl_map[p_pcb->port_handle - 1] = p_pcb->handle; - PORT_SetEventCallback (p_pcb->port_handle, obx_rfc_cback); - PORT_SetEventMask (p_pcb->port_handle, OBX_PORT_EVENT_MASK); - p_pcb->p_send_fn = (tOBX_SEND_FN *)obx_rfc_snd_msg; - p_pcb->p_close_fn = obx_close_port; - } - else - { - status = OBX_NO_RESOURCES; - } - - return status; -} - - -/******************************************************************************* -** Function obx_close_port -** Description Clear the port event mask and callback. Close the port. -** Returns void -*******************************************************************************/ -void obx_close_port(UINT16 port_handle) -{ - RFCOMM_RemoveConnection(port_handle); -} - -/******************************************************************************* -** Function obx_rfc_snd_msg -** Description Call PORT_WriteData() to send an OBEX message to peer. If -** all data is sent, free the GKI buffer that holds -** the OBEX message. If only portion of data is -** sent, adjust the BT_HDR for PART state. -** Returns TRUE if all data is sent -*******************************************************************************/ -BOOLEAN obx_rfc_snd_msg(tOBX_PORT_CB *p_pcb) -{ - BOOLEAN status = FALSE; - UINT16 bytes_written = 0; - - obx_stop_timer(&p_pcb->tle); - PORT_WriteData(p_pcb->port_handle, ((char*)(p_pcb->p_txmsg + 1)) + p_pcb->p_txmsg->offset, - p_pcb->p_txmsg->len, &bytes_written); - - obx_start_timer ((tOBX_COMM_CB *)p_pcb); - - if (bytes_written == p_pcb->p_txmsg->len) - { - GKI_freebuf(p_pcb->p_txmsg); - p_pcb->p_txmsg = NULL; - status = TRUE; - } - else - { - /* packet not completely written to RFCOMM */ - p_pcb->p_txmsg->offset += bytes_written; - p_pcb->p_txmsg->len -= bytes_written; - } - - return status; -} diff --git a/stack/obx/obx_sact.c b/stack/obx/obx_sact.c deleted file mode 100644 index 1602752..0000000 --- a/stack/obx/obx_sact.c +++ /dev/null @@ -1,1519 +0,0 @@ -/***************************************************************************** -** -** Name: obx_sact.c -** -** File: OBEX Server State Machine Action Functions -** -** Copyright (c) 2003-2012, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include <bt_target.h> - -#include "btu.h" -#include "obx_int.h" -#include "btm_api.h" - -/******************************************************************************* -** Function obx_sa_snd_rsp -** Description Call p_send_fn() to send the OBEX message to the peer. -** Start timer. Return NULL state.If data is partially sent, set -** next_state in port control block. Return PART state. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_snd_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = p_scb->state; - UINT8 rsp_code = OBX_RSP_DEFAULT; - tOBX_SR_CB *p_cb; - BOOLEAN not_cong = TRUE; - - obx_access_rsp_code(p_pkt, &rsp_code); - p_scb->cur_op = OBX_REQ_ABORT; - - - p_scb->ll_cb.comm.p_txmsg = p_pkt; - rsp_code &= ~OBX_FINAL; - /* Get and Put operation may need to adjust the state*/ - if (rsp_code != OBX_RSP_CONTINUE ) - { - if (p_scb->state == OBX_SS_GET_TRANSACTION || - p_scb->state == OBX_SS_PUT_SRM || - p_scb->state == OBX_SS_GET_SRM || - p_scb->state == OBX_SS_PUT_TRANSACTION) - { - state = OBX_SS_CONNECTED; - /* the SRM bits can not be cleared here, if aborting */ - if ((p_scb->srm &OBX_SRM_ABORT) == 0) - p_scb->srm &= OBX_SRM_ENABLE; - } - } - - OBX_TRACE_DEBUG2("obx_sa_snd_rsp sess_st:%d, event:%d", p_scb->sess_st, p_pkt->event); - if ((p_scb->sess_st == OBX_SESS_ACTIVE) && (p_pkt->event != (OBX_SESSION_CFM_SEVT + 1))) - { - p_scb->ssn++; - } - - if (p_scb->ll_cb.comm.p_send_fn(&p_scb->ll_cb) == FALSE) - { - p_scb->next_state = state; - state = OBX_SS_PARTIAL_SENT; - } - else if (p_scb->state == OBX_SS_GET_SRM) - { - if (((p_scb->srmp & OBX_SRMP_WAIT) == 0) && (rsp_code == OBX_RSP_CONTINUE)) - { - if (p_scb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_l2c_snd_msg) - { - OBX_TRACE_DEBUG1("obx_sa_snd_rsp cong:%d", p_scb->ll_cb.l2c.cong); - if (p_scb->ll_cb.l2c.cong) - { - not_cong = FALSE; - } - } - - /* do not need to wait - - fake a get request event, so the profile would issue another GET response */ - if (not_cong) - { - p_cb = obx_sr_get_cb(p_scb->handle); - (p_cb->p_cback) (p_scb->ll_cb.comm.handle, OBX_GET_REQ_EVT, p_scb->param, NULL); - } - } - p_scb->srmp &= ~OBX_SRMP_WAIT; - } - else if (p_scb->sess_st == OBX_SESS_SUSPENDING) - { - p_scb->ssn++; - p_scb->param.sess.ssn = p_scb->ssn; - p_scb->param.sess.nssn = p_scb->ssn; - p_scb->sess_st = OBX_SESS_SUSPEND; - p_scb->sess_info[OBX_SESSION_INFO_ST_IDX] = p_scb->state; - state = OBX_SS_SESS_INDICATED; - p_scb->api_evt = OBX_SESSION_REQ_EVT; - } - - return state; -} - -/******************************************************************************* -** Function obx_sa_snd_part -** Description Call p_send_fn() to send the left-over OBEX message to the -** peer. Start timer. If all the data is sent, call obx_ssm_event() -** with STATE event to next_state in the port control block. -** If (p_saved), call obx_ssm_event() to process the saved request. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_snd_part(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - UINT8 rsp_code = OBX_RSP_DEFAULT; - tOBX_SR_CB *p_cb; - - obx_access_rsp_code(p_scb->ll_cb.comm.p_txmsg , &rsp_code); - if (p_scb->ll_cb.comm.p_send_fn(&p_scb->ll_cb) == TRUE) - { - obx_ssm_event(p_scb, OBX_STATE_SEVT, NULL); - if (p_scb->p_next_req) - { - p_pkt = p_scb->p_next_req; - obx_access_rsp_code(p_pkt , &rsp_code); - p_scb->p_next_req = NULL; - p_scb->api_evt = (tOBX_EVENT)p_pkt->event; - obx_ssm_event(p_scb, (tOBX_SR_EVENT)(p_pkt->event-1), p_pkt); - } - - OBX_TRACE_DEBUG3("obx_sa_snd_part state:%d, srm:0x%x, rsp_code:0x%x", p_scb->state, p_scb->srm, rsp_code); - if (p_scb->state == OBX_SS_GET_SRM) - { - rsp_code &= ~OBX_FINAL; - if (((p_scb->srm & OBX_SRM_WAIT) == 0) && (rsp_code == OBX_RSP_CONTINUE)) - { - /* do not need to wait - - fake a get request event, so the profile would issue another GET response */ - p_cb = obx_sr_get_cb(p_scb->handle); - (p_cb->p_cback) (p_scb->ll_cb.comm.handle, OBX_GET_REQ_EVT, p_scb->param, NULL); - } - } - } - return state; -} - -/******************************************************************************* -** Function obx_sa_abort_rsp -** Description Send an abort response. -** If Put/Get response has not been sent yet, -** send it before the abort response. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_abort_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - BT_HDR *p_dummy; - UINT8 rsp_code = OBX_RSP_CONTINUE; - - if (p_scb->cur_op != OBX_REQ_ABORT && ((p_scb->srm & OBX_SRM_ENGAGE) == 0)) - { - /* if we have not respond to an op yet, send a dummy response */ - if (p_scb->cur_op == (rsp_code|OBX_REQ_PUT) ) - rsp_code = OBX_RSP_INTRNL_SRVR_ERR; - p_dummy = obx_build_dummy_rsp(p_scb, rsp_code); - obx_sa_snd_rsp(p_scb, p_dummy); - } - - /* clear the SRM bits; leave only the enabled bit */ - p_scb->srm &= OBX_SRM_ENABLE; - state = obx_sa_snd_rsp(p_scb, p_pkt); - return state; -} - -/******************************************************************************* -** Function obx_sa_op_rsp -** Description Send response for Put/Get when Abort request is already received -*******************************************************************************/ -tOBX_SR_STATE obx_sa_op_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - if (p_scb->cur_op != OBX_REQ_ABORT) - state = obx_sa_snd_rsp(p_scb, p_pkt); -#if (BT_USE_TRACES == TRUE) - else - OBX_TRACE_WARNING0("OBX is not waiting for a rsp API!!"); -#endif - return state; -} - -/******************************************************************************* -** Function obx_verify_target -** Description Verify that target header or connection ID is correct. -** Make sure that they do not both exist -*******************************************************************************/ -static UINT8 obx_verify_target(tOBX_SR_CB *p_cb, tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - UINT16 len = 0; - UINT8 rsp_code = OBX_RSP_SERVICE_UNAVL; - UINT32 conn_id = 0; - UINT8 *p_target = NULL; - - OBX_Read4ByteHdr(p_pkt, OBX_HI_CONN_ID, &conn_id); -/* Coverity: -Event unchecked_value: Return value of "OBX_ReadTargetHdr" is not checked -Coverity: FALSE-POSITIVE error from Coverity tool. Please do NOT remove following comment. */ -/* coverity[unchecked_value] False-positive: If target headser does not exist, - p_target would remain the default value/NULL and len would be set to 0. - There's no need to check the return value of OBX_ReadTargetHdr -*/ - OBX_ReadTargetHdr(p_pkt, &p_target, &len, 0); - - if (p_cb->target.len) - { - /* directed connection: make sure the connection ID matches */ - if ( conn_id && conn_id == p_scb->conn_id ) - rsp_code = OBX_RSP_OK; - - if (p_cb->target.len == OBX_DEFAULT_TARGET_LEN) - { - /* the user verify target (cases like BIP that has multiple targets) */ - rsp_code = OBX_RSP_OK; - } - else if ( len == p_cb->target.len && p_target && - memcmp(p_cb->target.target, p_target, p_cb->target.len) == 0) - { - rsp_code = OBX_RSP_OK; - } - } - else - { - /* no target - request to inbox, like OPP */ - if (conn_id == 0 && len == 0) - { - if (p_scb->ll_cb.comm.tx_mtu < OBX_MIN_MTU) - rsp_code = OBX_RSP_FORBIDDEN; - else - rsp_code = OBX_RSP_OK; - } - } - - /* target header and connection ID are not supposed to exist in the same packet*/ - if (conn_id != 0 && p_target != NULL) - rsp_code = OBX_RSP_BAD_REQUEST; - - OBX_TRACE_DEBUG3("obx_verify_target rsp: %x, id:%x, code:%x", - rsp_code, conn_id, ((tOBX_RX_HDR *)(p_pkt + 1))->code); - if (rsp_code != OBX_RSP_OK) - p_pkt->event = OBX_CONNECT_RSP_EVT; - return rsp_code; -} - -/******************************************************************************* -** Function obx_conn_rsp -** Description Called by OBX_ConnectRsp() and obx_sa_connect_ind() to compose -** a connect response packet. -*******************************************************************************/ -BT_HDR * obx_conn_rsp(tOBX_SR_CB *p_cb, tOBX_SR_SESS_CB *p_scb, UINT8 rsp_code, BT_HDR *p_pkt) -{ - UINT8 msg[OBX_HDR_OFFSET + OBX_MAX_CONN_HDR_EXTRA]; - UINT8 *p = msg; - - /* response packets always have the final bit set */ - *p++ = (rsp_code | OBX_FINAL); - p += OBX_PKT_LEN_SIZE; - - *p++ = OBX_VERSION; - *p++ = OBX_CONN_FLAGS; - UINT16_TO_BE_STREAM(p, p_scb->ll_cb.comm.rx_mtu); - - /* add session sequence number, if session is active */ - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - *p++ = OBX_HI_SESSION_SN; - *p++ = (p_scb->ssn+1); - } - - if (p_scb->conn_id && rsp_code == OBX_RSP_OK) - { - *p++ = OBX_HI_CONN_ID; - UINT32_TO_BE_STREAM(p, p_scb->conn_id); - } - - p_pkt = obx_sr_prepend_msg(p_pkt, msg, (UINT16)(p - msg) ); - - /* If the target is registered to server and the WHO headers not in the packet - * add WHO header here */ - p_pkt->event = OBX_CONNECT_RSP_EVT; - if (p_cb->target.len && p_cb->target.len != OBX_DEFAULT_TARGET_LEN && - OBX_CheckHdr(p_pkt, OBX_HI_WHO) == NULL) - { - OBX_AddByteStrHdr(p_pkt, OBX_HI_WHO, p_cb->target.target, p_cb->target.len); - /* adjust the packet len */ - obx_adjust_packet_len(p_pkt); - } - return p_pkt; -} - -/******************************************************************************* -** Function obx_sa_wc_conn_ind -** Description Connect Req is received when waiting for the port to close -** Call callback with OBX_CLOSE_IND_EVT to clean up the profiles -** then call obx_sa_connect_ind to process the connect req. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_wc_conn_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_EVT_PARAM param; - tOBX_SR_CB *p_cb = obx_sr_get_cb(p_scb->handle); - - obx_stop_timer(&p_scb->ll_cb.comm.tle); - memset(¶m, 0, sizeof(tOBX_EVT_PARAM)); - if (p_cb && p_cb->p_cback) - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_CLOSE_IND_EVT, param, NULL); - obx_sa_connect_ind(p_scb, p_pkt); - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_connect_ind -** Description Save peer MTU in the server control block.If the server does not -** register authentication, call callback with OBX_CONNECT_REQ_EVT -** and the MTU from the request message. Return NULL state. -** If authenticate, compose an unauthorized response, and call -** obx_sa_snd_rsp() to send it to the client. Return WAIT_AUTH state. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_connect_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - UINT8 rsp_code = OBX_RSP_SERVICE_UNAVL; - tOBX_SR_CB *p_cb = obx_sr_get_cb(p_scb->handle); - UINT8 *p; - tOBX_EVT_PARAM param; /* The event parameter. */ - - /* clear the SRM bits; leave only the enabled bit */ - p_scb->srm &= OBX_SRM_ENABLE; - - OBX_TRACE_DEBUG0("obx_sa_connect_ind"); - p_scb->api_evt = OBX_NULL_EVT; - - /* verify that the connect request is OK */ - rsp_code = obx_verify_target(p_cb, p_scb, p_pkt); - if (rsp_code == OBX_RSP_OK) - { - if (p_cb->target.len && p_scb->conn_id == 0) - { - /* if Connection ID is used for this connection and none assigned yet, - * - assign one */ - p_scb->conn_id = obx_sr_get_next_conn_id(); - OBX_TRACE_DEBUG1(" **** obx_sr_get_next_conn_id (0x%08x)", p_scb->conn_id); - } - - /* tx_mtu is processed in obx_sr_proc_evt() */ - if (p_cb->p_auth) - { - /* If client challenge us first, and the server registers for authentication: - * remove the authentication headers and challenge it back */ - /* send unauthorize response */ - p_pkt = obx_unauthorize_rsp(p_cb, p_scb, p_pkt); - state = OBX_SS_WAIT_AUTH; - } - else - { - if (OBX_CheckHdr(p_pkt, OBX_HI_CHALLENGE) != NULL) - { - /* If client challenge us first, and the server does not register for authentication: - * report the challenge */ - p_scb->p_saved_msg = obx_dup_pkt(p_pkt); - state = OBX_SS_AUTH_INDICATED; - p_scb->api_evt = OBX_PASSWORD_EVT; - } - else - { - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - p = &p_scb->sess_info[OBX_SESSION_INFO_ID_IDX]; - UINT32_TO_BE_STREAM(p, p_scb->conn_id); - param.sess.p_sess_info = p_scb->sess_info; - param.sess.sess_op = OBX_SESS_OP_CREATE; - param.sess.sess_st = p_scb->sess_st; - param.sess.nssn = p_scb->param.ssn; - param.sess.ssn = p_scb->param.ssn; - param.sess.obj_offset = 0; - p = &p_scb->sess_info[OBX_SESSION_INFO_MTU_IDX]; - UINT16_TO_BE_STREAM(p, p_scb->param.conn.mtu); - memcpy(param.sess.peer_addr, p_scb->peer_addr, BD_ADDR_LEN); - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_SESSION_REQ_EVT, param, NULL); - } - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_CONNECT_REQ_EVT, p_scb->param, p_pkt); - } - } - } - else - { - /* bad target or connection ID - reject the request */ - rsp_code |= OBX_FINAL; - obx_access_rsp_code(p_pkt, &rsp_code); - state = OBX_SS_NOT_CONNECTED; - } - - if (state != OBX_SS_NULL && state != OBX_SS_AUTH_INDICATED) - { - /* each port has its own credit. - * It's very unlikely that we can be flow controlled here */ - obx_sa_snd_rsp(p_scb, p_pkt); - } - - return state; -} - -/******************************************************************************* -** Function obx_sa_auth_ind -** Description Save peer MTU and the OBEX message in the server control block. -** Call callback function with OBX_PASSWORD_EVT. -** Note: This action function is only valid when MD5 is included -** Leave this as a stub function to avoid altering the state machine -*******************************************************************************/ -tOBX_SR_STATE obx_sa_auth_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - UINT8 rsp_code; - tOBX_SR_CB *p_cb = obx_sr_get_cb(p_scb->handle); - - p_scb->api_evt = OBX_NULL_EVT; - rsp_code = obx_verify_target(p_cb, p_scb, p_pkt); - - if (rsp_code == OBX_RSP_OK) - { - /* tx_mtu is processed in obx_sr_proc_evt() */ - if (OBX_CheckHdr(p_pkt, OBX_HI_AUTH_RSP) == NULL) - { - /* we are expecting authentication response in this state. - * if none is received, reject the request */ - p_pkt = obx_unauthorize_rsp(p_cb, p_scb, p_pkt); - state = OBX_SS_NOT_CONNECTED; - } - else - { - /* the client sends authentication response. - * save a copy in the control block. Verify it when OBX_Password() is issued */ - p_scb->p_saved_msg = obx_dup_pkt(p_pkt); - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_PASSWORD_EVT, p_scb->param, p_pkt); - } - } - else - { - /* bad target or connection ID - reject the request */ - rsp_code |= OBX_FINAL; - obx_access_rsp_code(p_pkt, &rsp_code); - state = OBX_SS_NOT_CONNECTED; - } - - if (state != OBX_SS_NULL) - { - /* each port has its own credit. - * It's very unlikely that we can be flow controlled here */ - obx_sa_snd_rsp(p_scb, p_pkt); - } - - return state; -} - -/******************************************************************************* -** Function obx_sa_connect_rsp -** Description obx_sa_snd_rsp().If(p_saved), free the OBEX message.If OK -** response, return NULL state.If unauthorized response, return -** WAIT_AUTH state.If other fail response, return NOT_CONN state. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_connect_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - UINT8 rsp_code = OBX_RSP_DEFAULT; - tOBX_SR_STATE state = p_scb->state; - - obx_access_rsp_code(p_pkt, &rsp_code); - - if (p_scb->p_saved_msg) - { - GKI_freebuf(p_scb->p_saved_msg); - p_scb->p_saved_msg = NULL; - } - - if ( rsp_code == (OBX_RSP_UNAUTHORIZED | OBX_FINAL) && - OBX_CheckHdr(p_pkt, OBX_HI_CHALLENGE) != NULL) - { - state = OBX_SS_WAIT_AUTH; - } - else if (rsp_code != (OBX_RSP_OK | OBX_FINAL) ) - state = OBX_SS_NOT_CONNECTED; - - /* each port has its own credit. - * It's very unlikely that we can be flow controlled here */ - obx_sa_snd_rsp(p_scb, p_pkt); - - return state; -} - -/******************************************************************************* -** Function obx_sa_connection_error -** Description Stop timer. Reopen transport. Call callback function with -** OBX_CLOSE_IND_EVT. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_connection_error(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_EVT_PARAM param; - tOBX_SR_CB *p_cb = obx_sr_get_cb(p_scb->handle); - tOBX_SR_CBACK *p_cback = NULL; - tOBX_SR_STATE save_state; - - OBX_TRACE_DEBUG4("obx_sa_connection_error tx_mtu: %d, sess_st:%d state:%d, prev_state:%d", - p_scb->ll_cb.comm.tx_mtu, p_scb->sess_st, p_scb->state, p_scb->prev_state); - - if (p_cb) - { - p_cback = p_cb->p_cback; - memset(¶m, 0, sizeof(tOBX_EVT_PARAM)); - } - - /* clear buffers from previous connection */ - obx_free_buf (&p_scb->ll_cb); - - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - /* The transport is interrupted while a reliable session is active: - * report a suspend event fot application to save the information in NV */ - save_state = p_scb->prev_state; - p_scb->sess_info[OBX_SESSION_INFO_SRM_IDX] = p_scb->srm; - param.sess.p_sess_info = p_scb->sess_info; - param.sess.sess_op = OBX_SESS_OP_TRANSPORT; - param.sess.sess_st = p_scb->sess_st; - param.sess.nssn = p_scb->ssn; - param.sess.ssn = p_scb->ssn; - param.sess.obj_offset = 0; - param.sess.timeout = OBX_SESS_TIMEOUT_VALUE; - if (save_state == OBX_SS_PARTIAL_SENT) - save_state = p_scb->next_state; - - if ((p_scb->srm & OBX_SRM_ENGAGE) == 0) - { - /* SRM is not engaged. - * When the session is resume, client needs to send the request first, - * the save ssm state may need to be adjusted */ - if (save_state == OBX_SS_PUT_INDICATED) - { - save_state = OBX_SS_PUT_TRANSACTION; - } - else if (save_state == OBX_SS_GET_INDICATED) - { - save_state = OBX_SS_GET_TRANSACTION; - } - } - p_scb->sess_info[OBX_SESSION_INFO_ST_IDX] = save_state; - OBX_TRACE_DEBUG2("saved state:0x%x, srm:0x%x", save_state, p_scb->sess_info[OBX_SESSION_INFO_SRM_IDX]); - memcpy(param.sess.peer_addr, p_scb->peer_addr, BD_ADDR_LEN); - p_scb->sess_st = OBX_SESS_NONE; - if (p_cback) - (*p_cback)(p_scb->ll_cb.comm.handle, OBX_SESSION_INFO_EVT, param, NULL); - } - else if (p_scb->sess_st == OBX_SESS_CLOSE || p_scb->state == OBX_SS_NOT_CONNECTED) - p_scb->sess_st = OBX_SESS_NONE; - - if (p_scb->ll_cb.comm.tx_mtu != 0) - { - p_scb->ll_cb.comm.tx_mtu = 0; - obx_stop_timer(&p_scb->ll_cb.comm.tle); - p_scb->conn_id = 0; - if (p_cback) - (*p_cback)(p_scb->ll_cb.comm.handle, OBX_CLOSE_IND_EVT, param, p_pkt); - } - - if (p_scb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_l2c_snd_msg) - { - p_scb->ll_cb.comm.id = 0; /* mark this port unused. */ - p_scb->srm &= OBX_SRM_ENABLE; - obx_add_port (p_scb->handle); - } - - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_close_port -** Description Close transport. Start timer. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_close_port(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - if (p_pkt) - GKI_freebuf(p_pkt); - p_scb->ll_cb.comm.p_close_fn(p_scb->ll_cb.comm.id); - obx_sr_free_scb(p_scb); - obx_start_timer(&p_scb->ll_cb.comm); - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_clean_port -** Description Close transport and clean up api_evt if illegal obex message is -** received. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_clean_port(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - p_scb->api_evt = OBX_NULL_EVT; - return obx_sa_close_port(p_scb, p_pkt); -} -/******************************************************************************* -** Function obx_sa_state -** Description change state -*******************************************************************************/ -tOBX_SR_STATE obx_sa_state(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - return p_scb->next_state; -} - -/******************************************************************************* -** Function obx_sa_nc_to -** Description Timer expires in not_conn state -** if there is existing connections -> disconnect -*******************************************************************************/ -tOBX_SR_STATE obx_sa_nc_to(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - BD_ADDR bd_addr; - - obx_stop_timer(&p_scb->ll_cb.comm.tle); - /* if there is existing connections -> disconnect */ - if (OBX_GetPeerAddr(p_scb->ll_cb.comm.handle, bd_addr) != 0) - { - p_scb->ll_cb.comm.p_close_fn(p_scb->ll_cb.comm.id); - p_scb->conn_id = 0; - /* wait for the conn err event to re-open the port */ - } - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_save_req -** Description When a request received from peer in PART state, -** save the request for later processing -*******************************************************************************/ -tOBX_SR_STATE obx_sa_save_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - if (p_scb->p_next_req) - { - GKI_freebuf(p_scb->p_next_req); - } - p_scb->p_next_req = p_pkt; - p_scb->api_evt = OBX_NULL_EVT; - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_rej_req -** Description Send bad request response when request comes in bad state -*******************************************************************************/ -tOBX_SR_STATE obx_sa_rej_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - UINT8 msg[OBX_HDR_OFFSET]; - UINT8 *p = msg; - - OBX_TRACE_DEBUG0( "obx_sa_rej_req" ) ; - if (p_pkt) - GKI_freebuf(p_pkt); - - /* response packets always have the final bit set */ - *p++ = (OBX_RSP_SERVICE_UNAVL | OBX_FINAL); - p += OBX_PKT_LEN_SIZE; - - /* add session sequence number, if session is active */ - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - *p++ = OBX_HI_SESSION_SN; - *p++ = (p_scb->ssn+1); - } - - /* add connection ID, if needed */ - if (p_scb->conn_id) - { - *p++ = OBX_HI_CONN_ID; - UINT32_TO_BE_STREAM(p, p_scb->conn_id); - } - - p_pkt = obx_sr_prepend_msg(NULL, msg, (UINT16)(p - msg) ); - p_pkt->event = OBX_PUT_RSP_EVT; /* any response */ - p_scb->api_evt = OBX_NULL_EVT; - - return obx_sa_snd_rsp(p_scb, p_pkt); -} - -/******************************************************************************* -** Function obx_sa_get_ind -** Description received a GET request from the client. Check if SRM is engaged. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_get_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - - if ((p_scb->srm & OBX_SRM_REQING) && (p_scb->srm & OBX_SRM_ENABLE)) - { - state = OBX_CS_GET_SRM; - } - - /* the GET request does not set the final bit. - * Save this request, send response automatically and do not report the event */ - if ((!p_scb->param.get.final) && ((p_scb->srmp & OBX_SRMP_NONF_EVT) == 0)) - { - p_scb->srmp |= OBX_SRMP_NONF; - if (p_scb->p_saved_msg) - GKI_freebuf(p_scb->p_saved_msg); - p_scb->p_saved_msg = p_pkt; - p_scb->api_evt = OBX_NULL_EVT; - OBX_GetRsp(p_scb->ll_cb.comm.handle, OBX_RSP_CONTINUE, NULL); - } - return state; -} - -/******************************************************************************* -** Function obx_merge_get_req -** Description merge the given 2 GET request packets and return the merged result -*******************************************************************************/ -BT_HDR * obx_merge_get_req(BT_HDR *p_pkt1, BT_HDR *p_pkt2) -{ - BT_HDR *p_ret = p_pkt1; - UINT16 size, need; - UINT8 *p1, *p2; - UINT8 *p, pre_size = OBX_GET_HDRS_OFFSET; - - /* skip the connection ID header */ - p = (UINT8 *)(p_pkt2 + 1) + p_pkt2->offset; - if (*p == OBX_HI_CONN_ID) - pre_size += 5; - - need = p_pkt1->len + p_pkt2->len; - if ((p_pkt2->len == pre_size) || (need >= OBX_LRG_DATA_POOL_SIZE)) - { - GKI_freebuf (p_pkt2); - return p_pkt1; - } - - /* get rid of the GET request header - opcode(1) + packet len(2) (and maybe connection ID) before merging */ - p_pkt2->len -= pre_size; - p_pkt2->offset += pre_size; - size = GKI_get_buf_size(p_pkt1); - - if (size < need) - { - /* the original p_pkt1 is too small. - * Allocate a bigger GKI buffer, p_ret, and copy p_pkt1 into p_ret */ - if (need < GKI_MAX_BUF_SIZE) - { - /* Use the largest general pool to allow challenge tags appendage */ - p_ret = (BT_HDR *)GKI_getbuf(GKI_MAX_BUF_SIZE); - } - else - { - p_ret = (BT_HDR *) GKI_getpoolbuf(OBX_LRG_DATA_POOL_ID); - } - memcpy (p_ret, p_pkt1, sizeof (BT_HDR)); - p_ret->offset = 0; - p1 = (UINT8 *)(p_ret + 1); - p2 = (UINT8 *)(p_pkt1 + 1) + p_pkt1->offset; - memcpy (p1, p2, p_pkt1->len); - GKI_freebuf (p_pkt1); - } - - /* adjust the actualy packet length to reflect the combined packet and copy p_pkt2 into p_ret */ - p1 = (UINT8 *)(p_ret + 1) + p_ret->offset + 1; - size = p_ret->len + p_pkt2->len; - UINT16_TO_BE_STREAM(p1, size); - p1 = (UINT8 *)(p_ret + 1) + p_ret->offset + p_ret->len; - p2 = (UINT8 *)(p_pkt2 + 1) + p_pkt2->offset; - p_ret->len = size; - memcpy (p1, p2, p_pkt2->len); - GKI_freebuf (p_pkt2); - - return p_ret; -} - -/******************************************************************************* -** Function obx_sa_get_req -** Description -*******************************************************************************/ -tOBX_SR_STATE obx_sa_get_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - tOBX_SR_CB *p_cb; - - OBX_TRACE_DEBUG2("obx_sa_get_req srmp:0x%x final:%d", p_scb->srmp, p_scb->param.get.final); - if (p_scb->srmp & OBX_SRMP_NONF) - { - /* the GET request does not set the final bit yet. - * merge this request, send response automatically and do not report the event */ - if (!p_scb->param.get.final) - { - p_scb->p_saved_msg = obx_merge_get_req(p_scb->p_saved_msg, p_pkt); - p_scb->api_evt = OBX_NULL_EVT; - OBX_GetRsp(p_scb->ll_cb.comm.handle, OBX_RSP_CONTINUE, NULL); - } - else - { - p_scb->srmp &= ~OBX_SRMP_NONF; - p_pkt = obx_merge_get_req(p_scb->p_saved_msg, p_pkt); - p_scb->p_saved_msg = NULL; - p_scb->api_evt = OBX_NULL_EVT; - p_cb = &obx_cb.server[p_scb->handle - 1]; - (p_cb->p_cback) (p_scb->ll_cb.comm.handle, OBX_GET_REQ_EVT, p_scb->param, p_pkt); - memset(&p_scb->param, 0, sizeof (p_scb->param) ); - } - } - - return state; -} - -/******************************************************************************* -** Function obx_sa_make_sess_id -** Description compute the session id -*******************************************************************************/ -static tOBX_STATUS obx_sa_make_sess_id (tOBX_SR_SESS_CB *p_scb, UINT8 *p_sess_info, - tOBX_TRIPLET *p_triplet, UINT8 num_triplet) -{ - UINT8 data[10]; - UINT8 ind; - UINT8 *p; - - /* check the device address session parameter */ - ind = obx_read_triplet(p_triplet, num_triplet, OBX_TAG_SESS_PARAM_ADDR); - OBX_TRACE_DEBUG2("addr ind:%d, num:%d", ind, num_triplet); - if (ind == num_triplet || p_triplet[ind].len != BD_ADDR_LEN) - { - OBX_TRACE_ERROR0("No Device Addr parameter"); - return OBX_BAD_PARAMS; - } - - if (memcmp (p_scb->peer_addr, p_triplet[ind].p_array, BD_ADDR_LEN) != 0) - { - OBX_TRACE_ERROR0("Bad Device Addr parameter"); - return OBX_BAD_PARAMS; - } - - /* check the nonce session parameter */ - ind = obx_read_triplet(p_triplet, num_triplet, OBX_TAG_SESS_PARAM_NONCE); - OBX_TRACE_DEBUG2("nonce ind:%d, num:%d", ind, num_triplet); - if (ind == num_triplet || (p_triplet[ind].len < OBX_MIN_NONCE_SIZE) || (p_triplet[ind].len > OBX_NONCE_SIZE)) - { - OBX_TRACE_ERROR0("No Nonce parameter"); - return OBX_BAD_PARAMS; - } - p = data; - BTM_GetLocalDeviceAddr (p); - - /* compute the session ID */ - obx_session_id (p_sess_info, p_scb->peer_addr, p_triplet[ind].p_array, p_triplet[ind].len, - data, &p_scb->sess_info[OBX_SESSION_ID_SIZE], OBX_LOCAL_NONCE_SIZE); - - return OBX_SUCCESS; -} - -/******************************************************************************* -** Function obx_sa_session_ind -** Description process session request from client -** when the session request is received is not OBX_SS_NOT_CONNECTED -*******************************************************************************/ -tOBX_SR_STATE obx_sa_session_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_TRIPLET triplet[OBX_MAX_SESS_PARAM_TRIP]; - UINT8 num = OBX_MAX_SESS_PARAM_TRIP, ind; - UINT8 *p; - tOBX_SR_CB *p_cb = obx_sr_get_cb(p_scb->handle); - UINT8 rsp_code = OBX_RSP_FORBIDDEN; - BOOLEAN now = FALSE; -#if (BT_USE_TRACES == TRUE) - tOBX_SESS_ST old_sess_st = p_scb->sess_st; -#endif - tOBX_EVENT old_api_evt; - UINT32 obj_offset = 0; - UINT8 ind_to; - UINT32 timeout = OBX_INFINITE_TIMEOUT; - tOBX_SR_STATE state = OBX_SS_NULL; - - OBX_TRACE_DEBUG0("obx_sa_session_ind"); - OBX_ReadTriplet(p_pkt, OBX_HI_SESSION_PARAM, triplet, &num); - if (p_cb->nonce == 0) - { - OBX_TRACE_ERROR0("reliable session is not supported by this server"); - /* do not report the session_req_evt */ - p_scb->api_evt = OBX_NULL_EVT; - obx_prepend_rsp_msg(p_scb->handle, OBX_SESSION_CFM_SEVT, OBX_RSP_NOT_IMPLEMENTED, NULL); - return OBX_SS_NULL; - } - else if (num) - { - ind = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_SESS_OP); - OBX_TRACE_DEBUG2("sess_op ind:%d, num:%d", ind, num); - if ((ind != num) && (triplet[ind].len == OBX_LEN_SESS_PARAM_SESS_OP)) - { - p = triplet[ind].p_array; - p_scb->param.sess.sess_op = *p; - OBX_TRACE_DEBUG1("sess_op :%d", *p); - switch (*p) - { - case OBX_SESS_OP_CREATE: - /* do not report the API event */ - p_scb->api_evt = OBX_NULL_EVT; - /* the session is already active; reject with Service Unavailable */ - rsp_code = OBX_RSP_SERVICE_UNAVL; - break; - - case OBX_SESS_OP_CLOSE: - /* verify that the session ID matches an existing one. Otherwise, FORBIDDEN */ - if (p_scb->sess_st != OBX_SESS_NONE) - { - ind = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_SESS_ID); - if (ind == num || triplet[ind].len != OBX_SESSION_ID_SIZE) - break; - if (memcmp (p_scb->sess_info, triplet[ind].p_array, OBX_SESSION_ID_SIZE) != 0) - { - /* bad session id */ - break; - } - /* must be closing a good session 0 send the response now */ - now = TRUE; - rsp_code = OBX_RSP_OK; - p_scb->sess_st = OBX_SESS_CLOSE; - } - break; - - case OBX_SESS_OP_SUSPEND: - /* verify that a session is active. Otherwise, FORBIDDEN */ - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - rsp_code = OBX_RSP_OK; - p_scb->sess_st = OBX_SESS_SUSPEND; - p_scb->sess_info[OBX_SESSION_INFO_ST_IDX] = p_scb->prev_state; - p_scb->sess_info[OBX_SESSION_INFO_SRM_IDX] = p_scb->srm; - /* save the session state in a GKI buffer on OBX_SessionRsp */ - if (p_scb->prev_state == OBX_SS_PUT_INDICATED || p_scb->prev_state == OBX_SS_GET_INDICATED) - { - /* out of sequence suspend: - * report the suspend event when the PutRsp or GetRsp is called - * this would allow server to resume the session in the right state */ - p_scb->api_evt = OBX_NULL_EVT; - p_scb->sess_st = OBX_SESS_SUSPENDING; - state = p_scb->prev_state; - } - } - break; - - case OBX_SESS_OP_RESUME: - rsp_code = OBX_RSP_SERVICE_UNAVL; - /* do not report the API event */ - p_scb->api_evt = OBX_NULL_EVT; - break; - - case OBX_SESS_OP_SET_TIME: - /* respond SET_TIME right away */ - now = TRUE; - - if (p_scb->sess_st == OBX_SESS_NONE) - { - rsp_code = OBX_RSP_FORBIDDEN; - } - break; - } - } - } - OBX_TRACE_DEBUG6("obx_sa_session_ind tx_mtu: %d, sess_st:%d->%d, rsp_code:0x%x, now:%d pstate:%d", - p_scb->ll_cb.comm.tx_mtu, old_sess_st, p_scb->sess_st, rsp_code, now, p_scb->prev_state); - - if (rsp_code == OBX_RSP_OK) - { - obx_read_timeout (triplet, num, &timeout, &p_scb->sess_info[OBX_SESSION_INFO_TO_IDX]); - } - - if ((rsp_code != OBX_RSP_OK) || now) - { - /* hold the original api_evt temporarily, so it's not reported at this obx_ssm_event */ - old_api_evt = p_scb->api_evt; - p_scb->api_evt = OBX_NULL_EVT; - /* send the response now */ - obx_prepend_rsp_msg(p_scb->handle, OBX_SESSION_CFM_SEVT, rsp_code, NULL); - /* restore the api event */ - p_scb->api_evt = old_api_evt; - } - else - { - ind_to = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_SESS_OP); - if ((ind_to != num) && (triplet[ind_to].len == OBX_TIMEOUT_SIZE)) - { - p = triplet[ind_to].p_array; - BE_STREAM_TO_UINT32(timeout, p); - } - p_scb->param.sess.p_sess_info = p_scb->sess_info; - p_scb->param.sess.sess_st = p_scb->sess_st; - p_scb->param.sess.ssn = p_scb->ssn; - p_scb->param.sess.obj_offset = obj_offset; - p_scb->param.sess.timeout = timeout; - memcpy(p_scb->param.sess.peer_addr , p_scb->peer_addr, BD_ADDR_LEN); - - } - return state; -} - -/******************************************************************************* -** Function obx_sa_sess_conn_ind -** Description process session request from client -** when the session request is received in OBX_SS_NOT_CONNECTED -*******************************************************************************/ -tOBX_SR_STATE obx_sa_sess_conn_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - UINT8 sess_info[OBX_SESSION_INFO_SIZE]; /* session id + local nonce */ - tOBX_TRIPLET triplet[OBX_MAX_SESS_PARAM_TRIP]; - UINT8 num = OBX_MAX_SESS_PARAM_TRIP, ind; - UINT8 *p; - tOBX_SR_CB *p_cb = obx_sr_get_cb(p_scb->handle); - UINT8 rsp_code = OBX_RSP_FORBIDDEN; - BOOLEAN now = FALSE; -#if (BT_USE_TRACES == TRUE) - tOBX_SESS_ST old_sess_st = p_scb->sess_st; -#endif - tOBX_SESS_OP sess_op = OBX_SESS_OP_CREATE; - tOBX_EVENT old_api_evt; - UINT32 obj_offset = 0;/* to report in evt param */ - UINT8 op_ssn; - UINT8 num_trip = 0; - BT_HDR *p_rsp = NULL; - UINT8 data[12]; - UINT8 ind_to; - UINT32 timeout = OBX_INFINITE_TIMEOUT; - UINT32 offset = 0; /* if non-0, add to triplet on resume */ - tOBX_SPND_CB *p_spndcb; - tOBX_EVT_PARAM param; /* The event parameter. */ - - OBX_TRACE_DEBUG0("obx_sa_sess_conn_ind"); - OBX_ReadTriplet(p_pkt, OBX_HI_SESSION_PARAM, triplet, &num); - if (p_cb->nonce == 0) - { - OBX_TRACE_ERROR0("reliable session is not supported by this server"); - /* do not report the session_req_evt */ - p_scb->api_evt = OBX_NULL_EVT; - obx_prepend_rsp_msg(p_scb->handle, OBX_SESSION_CFM_SEVT, OBX_RSP_NOT_IMPLEMENTED, NULL); - return OBX_SS_NULL; - } - else if (num) - { - ind = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_SESS_OP); - OBX_TRACE_DEBUG2("sess_op ind:%d, num:%d", ind, num); - if ((ind != num) && (triplet[ind].len == OBX_LEN_SESS_PARAM_SESS_OP)) - { - p = triplet[ind].p_array; - p_scb->param.sess.sess_op = sess_op = *p; - OBX_TRACE_DEBUG1("sess_op :%d", *p); - switch (*p) - { - case OBX_SESS_OP_CREATE: - /* do not report the API event */ - p_scb->api_evt = OBX_NULL_EVT; - - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - /* the session is already active; reject with OBX_RSP_FORBIDDEN */ - break; - } - - /* check if we still have room for one more session */ - if (obx_find_suspended_session (p_scb, NULL, 0) == NULL) - { - rsp_code = OBX_RSP_DATABASE_FULL; - break; - } - - p = &p_scb->sess_info[OBX_SESSION_INFO_NONCE_IDX]; - UINT32_TO_BE_STREAM(p, p_cb->nonce); - p_cb->nonce++; - /* make sure it's not 0 (which means reliable session is disabled) */ - if (!p_cb->nonce) - p_cb->nonce++; - - if (obx_sa_make_sess_id (p_scb, p_scb->sess_info, triplet, num) == OBX_SUCCESS) - { - rsp_code = OBX_RSP_OK; - p_scb->ssn = 0; - p_scb->sess_st = OBX_SESS_CREATE; - } - break; - - case OBX_SESS_OP_RESUME: - /* verify that a previously interrupted session exists with the same session parameters. - Otherwise, OBX_RSP_SERVICE_UNAVL. - */ - p_spndcb = obx_find_suspended_session (p_scb, triplet, num); - if (p_spndcb) - { - op_ssn = p_spndcb->ssn; - memcpy (p_scb->sess_info, p_spndcb->sess_info, OBX_SESSION_INFO_SIZE); - if (obx_sa_make_sess_id (p_scb, sess_info, triplet, num) == OBX_SUCCESS && - memcmp (sess_info, p_scb->sess_info, OBX_SESSION_ID_SIZE) == 0) - { - /* clear the suspend cb info */ - p_spndcb->state = OBX_SS_NULL; - if (p_spndcb->stle.param) - { - btu_stop_timer (&p_spndcb->stle); - p_spndcb->stle.param = 0; - } - rsp_code = OBX_RSP_OK; - p_scb->sess_st = OBX_SESS_RESUME; - p_scb->srmp |= OBX_SRMP_SESS_FST; - ind = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_NSEQNUM); - if (ind != num) - { - /* ssn exists - must be immediate suspend */ - p = triplet[ind].p_array; - op_ssn = *p; - obj_offset = obx_read_obj_offset(triplet, num); - } - } - obxu_dump_hex (p_scb->sess_info, "sess info", OBX_SESSION_INFO_SIZE); - OBX_TRACE_DEBUG4("p_spndcb->offset: 0x%x srm:x%x op_ssn %d ssn %d", p_spndcb->offset, p_scb->sess_info[OBX_SESSION_INFO_SRM_IDX],op_ssn,p_scb->ssn); - - if (p_scb->sess_info[OBX_SESSION_INFO_SRM_IDX] & OBX_SRM_ENGAGE) - { - /* - If offset in the request is smaller which only happens when it is a get operation, then client's offset and ssn matters. - So server's offset and ssn should be set to the client's ones. - If offset in the request is greater which only happens when it is a put operation, then server's offset and ssn matters. - So server keeps its offset(do nothing) and ssn and send it back to client in the resume reponse. - If offset are equal, either side's offset & ssn is fine, we choose to use the one in the reqeust - */ - - offset = p_spndcb->offset; - if (obj_offset && (obj_offset <= offset)) - { - offset = obj_offset; - p_scb->ssn = op_ssn; - /* Adjust ssn in the next continue to be the same as nssn in the resume request */ - if (p_scb->sess_info[OBX_SESSION_INFO_ST_IDX] ==OBX_CS_GET_SRM) - p_scb->ssn--; - - - } - - } - /* SRM is not enabled */ - else - { - p_scb->ssn = op_ssn; - } - - OBX_TRACE_DEBUG4("offset: 0x%x ssn:%d obj_offset:0x%x srm:0x%x", offset, p_scb->ssn, obj_offset, p_scb->sess_info[OBX_SESSION_INFO_SRM_IDX]); - } - - - if (rsp_code != OBX_RSP_OK) - { - rsp_code = OBX_RSP_SERVICE_UNAVL; - } - /* do not report the API event for RESUME. - * if OBX_RSP_OK, the event is reported in this function. - * p_rsp is used to call obx_ssm_event, and can not be reported to cback */ - p_scb->api_evt = OBX_NULL_EVT; - break; - } - } - } - else - { - /* do not have session parameters - bad req do not report the API event */ - p_scb->api_evt = OBX_NULL_EVT; - rsp_code = OBX_RSP_BAD_REQUEST; - } - OBX_TRACE_DEBUG5("obx_sa_sess_conn_ind tx_mtu: %d, sess_st:%d->%d, rsp_code:0x%x, now:%d", - p_scb->ll_cb.comm.tx_mtu, old_sess_st, p_scb->sess_st, rsp_code, now); - - if (rsp_code == OBX_RSP_OK) - { - /* send the session response now. - * do not report OBX_SESSION_REQ_EVT until connect indication, - * so connection id can be reported at the same time in sess_info */ - if ( (p_rsp = OBX_HdrInit(p_scb->handle, OBX_MIN_MTU))== NULL) - { - rsp_code = OBX_RSP_INTRNL_SRVR_ERR; - } - else - { - obx_read_timeout (triplet, num, &timeout, &p_scb->sess_info[OBX_SESSION_INFO_TO_IDX]); - - p = (UINT8 *) (p_rsp + 1) + p_rsp->offset; - /* response packet always has the final bit set */ - *p++ = (OBX_RSP_OK | OBX_FINAL); - p_rsp->len = 3; - p = data; - - /* add address */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_ADDR; - triplet[num_trip].len = BD_ADDR_LEN; - triplet[num_trip].p_array = p; - BTM_GetLocalDeviceAddr (p); - p += BD_ADDR_LEN; - num_trip++; - - /* add nonce 4 - 16 bytes */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_NONCE; - triplet[num_trip].len = OBX_LOCAL_NONCE_SIZE; - triplet[num_trip].p_array = &p_scb->sess_info[OBX_SESSION_INFO_NONCE_IDX]; - num_trip++; - - /* add session id */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_SESS_ID; - triplet[num_trip].len = OBX_SESSION_ID_SIZE; - triplet[num_trip].p_array = p_scb->sess_info; - num_trip++; - - if (sess_op == OBX_SESS_OP_RESUME) - { - /* add session id */ - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_NSEQNUM; - triplet[num_trip].len = 1; - triplet[num_trip].p_array = p; - /* Adjust ssn in the resume response to be the same as nssn in the resume request */ - if (p_scb->sess_info[OBX_SESSION_INFO_ST_IDX] == OBX_CS_GET_SRM) - *p++ = p_scb->ssn+1; - else - *p++ = p_scb->ssn; - num_trip++; - if (offset) - { - triplet[num_trip].tag = OBX_TAG_SESS_PARAM_OBJ_OFF; - triplet[num_trip].len = OBX_LEN_SESS_PARAM_OBJ_OFF; - triplet[num_trip].p_array = p; - UINT32_TO_BE_STREAM(p, offset); - num_trip++; - obj_offset = offset; - } - } - - /* add timeout */ - if (timeout != OBX_INFINITE_TIMEOUT && obx_cb.sess_tout_val != OBX_INFINITE_TIMEOUT && (obx_cb.sess_tout_val > timeout)) - { - timeout = obx_cb.sess_tout_val; - triplet[num_trip].p_array = p; - num_trip += obx_add_timeout (&triplet[num_trip], obx_cb.sess_tout_val, &p_scb->param.sess); - p = &p_scb->sess_info[OBX_SESSION_INFO_TO_IDX]; - UINT32_TO_BE_STREAM(p, timeout); - } - OBX_AddTriplet(p_rsp, OBX_HI_SESSION_PARAM, triplet, num_trip); - - /* adjust the packet len */ - p = (UINT8 *) (p_rsp + 1) + p_rsp->offset + 1; - UINT16_TO_BE_STREAM(p, p_rsp->len); - p_rsp->event = OBX_SESSION_CFM_SEVT + 1; - p_scb->sess_st = OBX_SESS_ACTIVE; - p_scb->param.sess.p_sess_info = p_scb->sess_info; - p_scb->param.sess.sess_st = p_scb->sess_st; - p_scb->param.sess.ssn = p_scb->ssn; - p_scb->param.sess.nssn = p_scb->ssn; - p_scb->param.sess.obj_offset = obj_offset; - p_scb->param.sess.timeout = timeout; - memcpy(p_scb->param.sess.peer_addr , p_scb->peer_addr, BD_ADDR_LEN); - obx_ssm_event(p_scb, OBX_SESSION_CFM_SEVT, p_rsp); - - if (sess_op == OBX_SESS_OP_RESUME) - { - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_SESSION_REQ_EVT, p_scb->param, NULL); - memset(&p_scb->param, 0, sizeof (p_scb->param) ); - param.conn.ssn = p_scb->ssn; - memcpy (param.conn.peer_addr, p_scb->peer_addr, BD_ADDR_LEN); - p = &p_scb->sess_info[OBX_SESSION_INFO_MTU_IDX]; - BE_STREAM_TO_UINT16(param.conn.mtu, p); - p_scb->ll_cb.comm.tx_mtu = param.conn.mtu; - param.conn.handle = p_scb->ll_cb.comm.handle; - OBX_TRACE_DEBUG1("RESUME tx_mtu: %d", p_scb->ll_cb.comm.tx_mtu); - /* report OBX_CONNECT_REQ_EVT to let the client know the MTU */ - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_CONNECT_REQ_EVT, param, NULL); - } - } - } - - if ((rsp_code != OBX_RSP_OK) || now) - { - /* hold the original api_evt temporarily, so it's not reported at this obx_ssm_event */ - old_api_evt = p_scb->api_evt; - p_scb->api_evt = OBX_NULL_EVT; - /* send the response now */ - obx_prepend_rsp_msg(p_scb->handle, OBX_DISCNT_CFM_SEVT, rsp_code, NULL); - /* restore the api event */ - p_scb->api_evt = old_api_evt; - } - else - { - ind_to = obx_read_triplet(triplet, num, OBX_TAG_SESS_PARAM_SESS_OP); - if ((ind_to != num) && (triplet[ind_to].len == OBX_TIMEOUT_SIZE)) - { - p = triplet[ind_to].p_array; - BE_STREAM_TO_UINT32(timeout, p); - } - p_scb->param.sess.p_sess_info = p_scb->sess_info; - p_scb->param.sess.sess_st = p_scb->sess_st; - p_scb->param.sess.ssn = p_scb->ssn; - p_scb->param.sess.nssn = p_scb->ssn; - p_scb->param.sess.obj_offset = obj_offset; - p_scb->param.sess.timeout = timeout; - memcpy(p_scb->param.sess.peer_addr , p_scb->peer_addr, BD_ADDR_LEN); - - } - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_wc_sess_ind -** Description process session request from client -** when the session request is received in OBX_SS_WAIT_CLOSE -*******************************************************************************/ -tOBX_SR_STATE obx_sa_wc_sess_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_EVT_PARAM param; - tOBX_SR_CB *p_cb = obx_sr_get_cb(p_scb->handle); - - OBX_TRACE_DEBUG1("obx_sa_wc_sess_ind sess_st:%d", p_scb->sess_st); - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - /* processing CloseSession */ - obx_sa_session_ind(p_scb, p_pkt); - } - else - { - /* probably CreateSession */ - obx_sa_sess_conn_ind(p_scb, p_pkt); - OBX_TRACE_DEBUG1("obx_sa_wc_sess_ind (after obx_sa_sess_conn_ind) sess_st:%d", p_scb->sess_st); - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - /* after session command and still is Active - * a session must have been created during Wait_close state. - * need to report a OBX_CLOSE_IND_EVT to clean up the profiles */ - memset(¶m, 0, sizeof(tOBX_EVT_PARAM)); - if (p_cb && p_cb->p_cback) - (*p_cb->p_cback)(p_scb->ll_cb.comm.handle, OBX_CLOSE_IND_EVT, param, NULL); - } - } - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_session_rsp -** Description process Session response API. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_session_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE new_state = OBX_SS_NULL; - UINT8 *p; - tOBX_L2C_CB *p_lcb; - tOBX_L2C_EVT_PARAM evt_param; - - OBX_TRACE_DEBUG1("obx_sa_session_rsp pstate:%d", p_scb->prev_state); - new_state = obx_sa_snd_rsp(p_scb, p_pkt); - OBX_TRACE_DEBUG2("sess_st: %d op:%d", p_scb->sess_st, p_scb->param.sess.sess_op); - if (p_scb->sess_st == OBX_SESS_ACTIVE && p_scb->param.sess.sess_op == OBX_SESS_OP_RESUME) - { - p_scb->srm = p_scb->sess_info[OBX_SESSION_INFO_SRM_IDX]; - new_state = p_scb->sess_info[OBX_SESSION_INFO_ST_IDX]; - p = &p_scb->sess_info[OBX_SESSION_INFO_ID_IDX]; - BE_STREAM_TO_UINT32(p_scb->conn_id, p); - OBX_TRACE_DEBUG3("new_state; %d Connection ID: 0x%x, srm:0x%x", new_state, p_scb->conn_id, p_scb->srm); - if ((p_scb->srm & OBX_SRM_ENGAGE) && (new_state == OBX_SS_GET_SRM)) - { - p_lcb = &p_scb->ll_cb.l2c; - evt_param.any = 0; - obx_l2c_snd_evt (p_lcb, evt_param, OBX_L2C_EVT_RESUME); - } - /* report OBX_CONNECT_REQ_EVT in obx_sa_sess_conn_ind() - if (new_state == OBX_SS_CONNECTED) - { - } */ - } - else if (p_scb->sess_st == OBX_SESS_CLOSE) - { - new_state = OBX_SS_WAIT_CLOSE; - } - - return new_state; -} - -/******************************************************************************* -** Function obx_sa_put_ind -** Description received a PUT request from the client. Check if SRM is engaged. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_put_ind(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - if ((p_scb->srm & OBX_SRM_REQING) && (p_scb->srm & OBX_SRM_ENABLE)) - { - state = OBX_CS_PUT_SRM; - } - return state; -} - -/******************************************************************************* -** Function obx_sa_srm_put_req -** Description received a PUT request from the client when SRM is engaged. -*******************************************************************************/ -tOBX_SR_STATE obx_sa_srm_put_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - if (!p_scb->param.put.final) - p_scb->srm |= OBX_SRM_WAIT_UL; - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_srm_put_rsp -** Description process PUT response API function. -** report PUT request event, if any is queued -*******************************************************************************/ -tOBX_SR_STATE obx_sa_srm_put_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - tOBX_COMM_CB *p_comm = &p_scb->ll_cb.comm; - UINT8 rsp_code = OBX_RSP_DEFAULT; - BOOLEAN ret = TRUE; - - obx_access_rsp_code(p_pkt, &rsp_code); - rsp_code &= ~OBX_FINAL; - if (rsp_code != OBX_RSP_CONTINUE ) - { - p_scb->srm |= OBX_SRM_NEXT; - if (rsp_code != OBX_RSP_OK) - p_scb->srm |= OBX_SRM_ABORT; - } - - p_scb->srm &= ~OBX_SRM_WAIT_UL; - OBX_TRACE_DEBUG2("obx_sa_srm_put_rsp srm:0x%x rsp_code:0x%x", p_scb->srm, rsp_code); - if (p_scb->srm & OBX_SRM_NEXT) - { - p_scb->srm &= ~OBX_SRM_NEXT; - state = obx_sa_snd_rsp (p_scb, p_pkt); - } - else - { - if (p_scb->sess_st == OBX_SESS_ACTIVE) - { - p_scb->ssn++; - } - obx_start_timer(&p_scb->ll_cb.comm); - if (p_pkt) - GKI_freebuf(p_pkt); - } - OBX_TRACE_DEBUG1("obx_sa_srm_put_rsp srm:0x%x", p_scb->srm); - - while (ret && (p_pkt = (BT_HDR *)GKI_dequeue (&p_comm->rx_q)) != NULL) - { - if (state != OBX_SS_NULL) - { - p_scb->state = state; - state = OBX_SS_NULL; - } - ret = obx_sr_proc_pkt (p_scb, p_pkt); - if ((p_scb->srm & OBX_SRM_ABORT) == 0) - ret = FALSE; - obx_flow_control(p_comm); - OBX_TRACE_DEBUG3("obx_sa_srm_put_rsp rx_q.count: %d srm:0x%x, ret:%d", p_comm->rx_q.count, p_scb->srm, ret ); - } - - return state; -} - -/******************************************************************************* -** Function obx_sa_srm_get_fcs -** Description Process L2CAP congestion event -*******************************************************************************/ -tOBX_SR_STATE obx_sa_srm_get_fcs(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - BOOLEAN not_cong = TRUE; - if (p_scb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_l2c_snd_msg) - { - OBX_TRACE_DEBUG1("obx_sa_srm_get_fcs cong:%d", p_scb->ll_cb.l2c.cong); - if (p_scb->ll_cb.l2c.cong) - not_cong = FALSE; - } - if (not_cong) - p_scb->api_evt = OBX_GET_REQ_EVT; - return OBX_SS_NULL; -} - -/******************************************************************************* -** Function obx_sa_srm_get_rsp -** Description send GET response to client -*******************************************************************************/ -tOBX_SR_STATE obx_sa_srm_get_rsp(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state; - OBX_TRACE_DEBUG1("obx_sa_srm_get_rsp srm:0x%x", p_scb->srm); - state = obx_sa_snd_rsp(p_scb, p_pkt); - return state; -} - - - -/******************************************************************************* -** Function obx_sa_srm_get_req -** Description process GET request from client -*******************************************************************************/ -tOBX_SR_STATE obx_sa_srm_get_req(tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_SR_STATE state = OBX_SS_NULL; - tOBX_SR_CB *p_cb; - - OBX_TRACE_DEBUG3("obx_sa_srm_get_req srm:0x%x srmp:0x%x final:%d", p_scb->srm, p_scb->srmp, p_scb->param.get.final); - if (p_scb->srmp & OBX_SRMP_NONF) - { - /* the GET request does not set the final bit yet. - * merge this request, send response automatically and do not report the event */ - if (!p_scb->param.get.final) - { - p_scb->p_saved_msg = obx_merge_get_req(p_scb->p_saved_msg, p_pkt); - p_scb->api_evt = OBX_NULL_EVT; - } - else - { - p_scb->srmp &= ~OBX_SRMP_NONF; - p_pkt = obx_merge_get_req(p_scb->p_saved_msg, p_pkt); - p_scb->p_saved_msg = NULL; - p_scb->api_evt = OBX_NULL_EVT; - p_cb = &obx_cb.server[p_scb->handle - 1]; - (p_cb->p_cback) (p_scb->ll_cb.comm.handle, OBX_GET_REQ_EVT, p_scb->param, p_pkt); - memset(&p_scb->param, 0, sizeof (p_scb->param) ); - } - } - - return state; -} - diff --git a/stack/obx/obx_sapi.c b/stack/obx/obx_sapi.c deleted file mode 100644 index 7815947..0000000 --- a/stack/obx/obx_sapi.c +++ /dev/null @@ -1,591 +0,0 @@ -/***************************************************************************** -** -** Name: obx_sapi.c -** -** File: OBEX Server Application Programming Interface functions -** -** Copyright (c) 2003-2009, Broadcom Corp., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "bt_target.h" - -#if defined(OBX_INCLUDED) && (OBX_INCLUDED == TRUE) - -#include "wcassert.h" -#include "btu.h" -#include "port_api.h" -#include "obx_int.h" -#include "l2c_api.h" -#include "btm_api.h" - -/******************************************************************************* -** -** Function OBX_StartServer -** -** Description This function is to register a server entity to OBEX. -** -** Returns OBX_SUCCESS, if successful. -** OBX_NO_RESOURCES, if OBX does not have resources. -** -*******************************************************************************/ -tOBX_STATUS OBX_StartServer(tOBX_StartParams *p_params, tOBX_HANDLE *p_handle) -{ - tOBX_SR_CB *p_cb = NULL; - tOBX_STATUS status = OBX_NO_RESOURCES; -// btla-specific ++ - tOBX_SR_SESS_CB *p_scb = NULL; -// btla-specific -- - tOBX_HANDLE obx_handle; - UINT8 size; - - WC_ASSERT(p_params); - WC_ASSERT(p_params->p_cback); - WC_ASSERT(p_handle); - - if (p_params->max_sessions > OBX_MAX_SR_SESSION) - { - OBX_TRACE_ERROR2("OBX_StartServer bad max_sessions:%d (1-%d)", - p_params->max_sessions, OBX_MAX_SR_SESSION); - return OBX_BAD_PARAMS; - } - - if (p_params->scn == 0 && L2C_INVALID_PSM(p_params->psm)) - { - OBX_TRACE_ERROR2("OBX_StartServer bad scn:%d and psm:0x%x", p_params->scn, p_params->psm); - return OBX_BAD_PARAMS; - } - - if (p_params->max_sessions == 0) - p_params->max_sessions = 1; - - /* allocate a server control block */ - obx_handle = obx_sr_alloc_cb(p_params); - if (obx_handle) - p_cb = &obx_cb.server[obx_handle-1]; - - if (p_cb != NULL) - { - p_scb = &obx_cb.sr_sess[p_cb->sess[0]-1]; - p_scb->ll_cb.port.rx_mtu = p_params->mtu; - if (p_cb->scn) - { - /* open an RFCOMM port to listen for incoming messages */ - /* allocate the port for the first session now. The others will be allocated when needed */ - status = obx_open_port(&p_scb->ll_cb.port, BT_BD_ANY, p_cb->scn); - } - else - { - status = OBX_SUCCESS; - } - - if (status == OBX_SUCCESS) - { - /* If authentication is needed for this server, save the parameters in control block */ - if (p_params->authenticate) - { - p_cb->p_auth = (tOBX_AUTH_PARAMS *)GKI_getbuf(sizeof(tOBX_AUTH_PARAMS)+OBX_MAX_REALM_LEN+1); - if (p_cb->p_auth) - { - p_cb->p_auth->auth_option = p_params->auth_option; - /* adjust realm len, if the given realm is too big */ - size = (p_params->realm_len>OBX_MAX_REALM_LEN) ? OBX_MAX_REALM_LEN : p_params->realm_len; - p_cb->p_auth->realm_len = size; - p_cb->p_auth->realm[0] = p_params->realm_charset; - if (p_params->realm_len && p_params->p_realm) - memcpy(&p_cb->p_auth->realm[1], p_params->p_realm, size); - } - else - status = OBX_NO_RESOURCES; - } - } - - if (status == OBX_SUCCESS) - { - /* if everything is OK, save the other parameters for this server */ - memset(p_cb->target.target, 0, OBX_MAX_TARGET_LEN); - if (p_params->p_target) - { - if (p_params->p_target->len) - { - /* OBX handles who, connection ID headers */ - p_cb->target.len = p_params->p_target->len; - memcpy(p_cb->target.target, p_params->p_target->target, p_params->p_target->len); - } - else - { - /* the regular default server */ - /* the user handles target, who headers. - * OBX handles connection ID header */ - p_cb->target.len = OBX_DEFAULT_TARGET_LEN; - } - } - else - { - /* the one and only default server */ - /* no target, who, connection id headers for this case */ - p_cb->target.len = 0; - } - -// btla-specific ++ - if (p_scb) - { - OBX_TRACE_DEBUG3("OBX_StartServer target len:%d, authenticate:%d handle:0x%x", - p_cb->target.len, p_params->authenticate, p_scb->ll_cb.port.handle); - p_cb->p_cback = p_params->p_cback; - p_scb->state = OBX_SS_NOT_CONNECTED; - - /* give the handle to application */ - *p_handle = p_scb->ll_cb.port.handle; - } -// btla-specific -- - } - else - { - /* otherwise, free the control block */ - obx_sr_free_cb(obx_handle); - } - } - - return status; -} - - -/******************************************************************************* -** -** Function OBX_StopServer -** -** Description This function is to stop this OBEX server from receiving any -** more incoming requests. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_StopServer(tOBX_HANDLE handle) -{ - tOBX_STATUS status = OBX_SUCCESS; - tOBX_SR_CB *p_cb = obx_sr_get_cb(handle); - tOBX_SR_SESS_CB *p_scb; - int xx; - tOBX_SPND_CB *p_spndcb; - - if (p_cb) - { - /* Process suspended session if necessary */ - if (p_cb->p_suspend) - { - for (xx=0, p_spndcb=p_cb->p_suspend; xx<p_cb->max_suspend; xx++, p_spndcb++) - { - if (p_spndcb->state) - { - btu_stop_timer (&p_spndcb->stle); - } - } - GKI_freebuf (p_cb->p_suspend); - } - - for (xx=0; xx < p_cb->num_sess && p_cb->sess[xx]; xx ++) - { - p_scb = &obx_cb.sr_sess[p_cb->sess[xx]-1]; - if (p_scb->ll_cb.comm.id) - { - OBX_DisconnectRsp(handle, OBX_RSP_SERVICE_UNAVL, NULL); - if (p_scb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg) - RFCOMM_RemoveServer(p_scb->ll_cb.port.port_handle); - } - } - - if (p_cb->psm) - L2CA_DEREGISTER (p_cb->psm); - - obx_sr_free_cb (handle); - } - else - status = OBX_BAD_HANDLE; - return status; -} - -/******************************************************************************* -** -** Function OBX_AddSuspendedSession -** -** Description This function is to add the session information for a previously -** suspended reliable session to the server control block -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_AddSuspendedSession(tOBX_HANDLE shandle, BD_ADDR peer_addr, UINT8 *p_sess_info, - UINT32 timeout, UINT8 ssn, UINT32 offset) -{ - tOBX_STATUS status = OBX_SUCCESS; - tOBX_SR_CB *p_cb = obx_sr_get_cb(shandle); - UINT16 size; - UINT8 xx; - tOBX_SPND_CB *p_spndcb; - INT32 ticks = 0x7FFFFFFF, remain_ticks; - BOOLEAN added = FALSE; - UINT8 saved_xx = 0; - - OBX_TRACE_DEBUG2("OBX_AddSuspendedSession BDA: %06x%06x", - (peer_addr[0]<<16)+(peer_addr[1]<<8)+peer_addr[2], - (peer_addr[3]<<16)+(peer_addr[4]<<8)+peer_addr[5]); - if (p_cb && p_sess_info && p_cb->max_suspend) - { - if (p_cb->p_suspend == NULL) - { - size = p_cb->max_suspend * sizeof (tOBX_SPND_CB); - p_cb->p_suspend = (tOBX_SPND_CB *)GKI_getbuf( size); - memset (p_cb->p_suspend, 0, size); - } - - if (p_cb->p_suspend) - { - for (xx=0, p_spndcb=p_cb->p_suspend; xx<p_cb->max_suspend; xx++, p_spndcb++) - { - OBX_TRACE_DEBUG4("[%d] state: %d, ssn:%d BDA: %08x", xx, p_spndcb->state, p_spndcb->ssn, - (p_spndcb->peer_addr[2]<<24)+(p_spndcb->peer_addr[3]<<16)+(p_spndcb->peer_addr[4]<<8)+p_spndcb->peer_addr[5]); - if (p_spndcb->state == OBX_SS_NULL || memcmp(p_spndcb->peer_addr, peer_addr, BD_ADDR_LEN) == 0) - { - added = TRUE; - break; - } - else if (p_spndcb->state != OBX_SS_NULL && ticks) - { - if (p_spndcb->stle.param == 0) - { - /* this entry has infinite timeout; just use it */ - ticks = 0; - saved_xx = xx; - OBX_TRACE_DEBUG1("[%d] infinite timeout", xx ); - } - /* find the entry the expires in the shortest time */ - else - { - remain_ticks = btu_remaining_time(&p_spndcb->stle); - OBX_TRACE_DEBUG2("[%d] remain_ticks: %d", xx, remain_ticks ); - if (remain_ticks < ticks) - { - ticks = remain_ticks; - saved_xx = xx; - } - } - } - } - - if (!added) - { - /* if cannot use an empty/or reuse an existing entry, use the one expires soon */ - added = TRUE; - xx = saved_xx; /* this is for debug trace; don't optimize */ - p_spndcb = &p_cb->p_suspend[xx]; - OBX_TRACE_DEBUG1("reuse entry [%d]", xx ); - } - - if (added) - { - memcpy (p_spndcb->sess_info, p_sess_info, OBX_SESSION_INFO_SIZE); - p_spndcb->state = p_sess_info[OBX_SESSION_INFO_ST_IDX]; - p_spndcb->ssn = ssn; - p_spndcb->offset = offset; - OBX_TRACE_DEBUG6("[%d] timeout: %d state:%d ssn:%d offset:%d, BDA: %08x", - xx, timeout, p_spndcb->state, ssn, offset, - (peer_addr[2]<<24)+(peer_addr[3]<<16)+(peer_addr[4]<<8)+peer_addr[5]); - memcpy(p_spndcb->peer_addr, peer_addr, BD_ADDR_LEN); - if (timeout != OBX_INFINITE_TIMEOUT) - { - p_spndcb->stle.param = (UINT32)p_spndcb; - btu_start_timer(&p_spndcb->stle, BTU_TTYPE_OBX_SVR_SESS_TO, timeout); - OBX_TRACE_DEBUG2("timeout: %d ticks:%d", timeout, p_spndcb->stle.ticks); - } - else - p_spndcb->stle.param = 0; - } - } - } - else - status = OBX_BAD_HANDLE; - return status; -} - -/******************************************************************************* -** -** Function OBX_ConnectRsp -** -** Description This function is called to send the response to a Connect -** Request from an OBEX client. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_ConnectRsp(tOBX_HANDLE shandle, UINT8 rsp_code, BT_HDR *p_pkt) -{ - tOBX_STATUS status = OBX_SUCCESS; - tOBX_SR_SESS_CB *p_scb = obx_sr_get_scb(shandle); - tOBX_SR_CB *p_cb = obx_sr_get_cb(shandle); - - if (p_scb) - { - p_pkt = obx_conn_rsp(p_cb, p_scb, rsp_code, p_pkt); - - obx_ssm_event(p_scb, OBX_CONNECT_CFM_SEVT, p_pkt); - } - else - { - OBX_TRACE_DEBUG1("OBX_ConnectRsp Bad Handle: 0x%x", shandle); - status = OBX_BAD_HANDLE; - } - return status; -} - -/******************************************************************************* -** -** Function OBX_SessionRsp -** -** Description This function is called to respond to a request to create a reliable session. -** -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_SessionRsp(tOBX_HANDLE shandle, UINT8 rsp_code, UINT8 ssn, UINT32 offset, BT_HDR *p_pkt) -{ - tOBX_STATUS status = OBX_SUCCESS; - tOBX_SR_SESS_CB *p_scb = obx_sr_get_scb(shandle); - UINT8 *p; - BT_HDR *p_rsp = NULL; - tOBX_TRIPLET triplet[5]; - UINT8 data[12]; - UINT8 num_trip = 0; - UINT32 timeout; - tOBX_SESS_ST old_sess_st; - - OBX_TRACE_API0("OBX_SessionRsp"); - if (p_scb) - { - old_sess_st = p_scb->sess_st; - p_rsp = OBX_HdrInit(p_scb->handle, OBX_MIN_MTU); - if (p_rsp) - { - p = (UINT8 *) (p_rsp + 1) + p_rsp->offset; - /* response packet always has the final bit set */ - *p++ = (rsp_code | OBX_FINAL); - p_rsp->len = 3; - p = data; - if (rsp_code == OBX_RSP_OK) - { - switch (p_scb->sess_st) - { - case OBX_SESS_CREATE: - case OBX_SESS_RESUME: - GKI_freebuf (p_rsp); - if (p_pkt) - GKI_freebuf (p_pkt); - OBX_TRACE_DEBUG0("OBX_SessionRsp do not need to be called for CREATE and RESUME"); - return OBX_SUCCESS; - case OBX_SESS_SUSPEND: - p_scb->sess_st = OBX_SESS_SUSPENDED; - p = &p_scb->sess_info[OBX_SESSION_INFO_TO_IDX]; - BE_STREAM_TO_UINT32(timeout, p); - OBX_AddSuspendedSession(p_scb->handle, p_scb->peer_addr, p_scb->sess_info, timeout, ssn, offset); - break; - case OBX_SESS_CLOSE: - p_scb->sess_st = OBX_SESS_NONE; - break; - } - - if (num_trip) - OBX_AddTriplet(p_rsp, OBX_HI_SESSION_PARAM, triplet, num_trip); - if (p_pkt) - { - p = (UINT8 *) (p_rsp + 1) + p_rsp->offset + p_rsp->len; - memcpy (p, ((UINT8 *) (p_pkt + 1) + p_pkt->offset), p_pkt->len); - p_rsp->len += p_pkt->len; - } - } - p = (UINT8 *) (p_rsp + 1) + p_rsp->offset + 1; - UINT16_TO_BE_STREAM(p, p_rsp->len); - - p_rsp->event = OBX_SESSION_CFM_SEVT + 1; - } - OBX_TRACE_DEBUG3("Rsp sess_st:%d->%d status:%d", old_sess_st, p_scb->sess_st, status); - - obx_ssm_event(p_scb, OBX_SESSION_CFM_SEVT, p_rsp); - /* clear the "previous" session state as required by earlier comment */ - p_scb->param.sess.sess_st = 0; - } - else - status = OBX_BAD_HANDLE; - - if (p_pkt) - { - GKI_freebuf (p_pkt); - } - return status; -} - -/******************************************************************************* -** -** Function obx_prepend_rsp_msg -** -** Description This function is called to add response code and connection ID -** to the given OBEX message -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS obx_prepend_rsp_msg(tOBX_HANDLE shandle, tOBX_SR_EVENT event, UINT8 rsp_code, BT_HDR *p_pkt) -{ - tOBX_STATUS status = OBX_SUCCESS; - tOBX_SR_SESS_CB *p_scb = obx_sr_get_scb(shandle); - UINT8 msg[OBX_HDR_OFFSET]; - UINT8 *p = msg; - - if (p_scb) - { - /* response packets always have the final bit set */ - *p++ = (rsp_code | OBX_FINAL); - p += OBX_PKT_LEN_SIZE; - - /* add session sequence number, if session is active */ - if (p_scb->sess_st == OBX_SESS_ACTIVE || p_scb->sess_st == OBX_SESS_SUSPENDING) - { - *p++ = OBX_HI_SESSION_SN; - *p++ = (p_scb->ssn+1); - } - - if (event == OBX_DISCNT_CFM_SEVT) - p_scb->conn_id = 0; - - if (p_scb->srm & OBX_SRM_REQING) - { - p_scb->srm &= ~OBX_SRM_REQING; - if (rsp_code == OBX_RSP_CONTINUE) - { - p_scb->srm |= OBX_SRM_ENGAGE; - *p++ = OBX_HI_SRM; - *p++ = OBX_HV_SRM_ENABLE; - - if (event == OBX_PUT_CFM_SEVT) - p_scb->srm |= OBX_SRM_NEXT; - } - } - - p_pkt = obx_sr_prepend_msg(p_pkt, msg, (UINT16)(p - msg) ); - /* this event code needs to be set up properly for flow control reasons */ - p_pkt->event = event+1; - obx_ssm_event(p_scb, event, p_pkt); - } - else - status = OBX_BAD_HANDLE; - - return status; -} - -/******************************************************************************* -** -** Function OBX_SetPathRsp -** -** Description This function is called to send the response to a Set Path -** Request from an OBEX client. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_SetPathRsp(tOBX_HANDLE shandle, UINT8 rsp_code, BT_HDR *p_pkt) -{ - return obx_prepend_rsp_msg(shandle, OBX_SETPATH_CFM_SEVT, rsp_code, p_pkt); -} - - -/******************************************************************************* -** -** Function OBX_PutRsp -** -** Description This function is called to send the response to a Put -** Request from an OBEX client. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_PutRsp(tOBX_HANDLE shandle, UINT8 rsp_code, BT_HDR *p_pkt) -{ - return obx_prepend_rsp_msg(shandle, OBX_PUT_CFM_SEVT, rsp_code, p_pkt); -} - - -/******************************************************************************* -** -** Function OBX_GetRsp -** -** Description This function is called to send the response to a Get -** Request from an OBEX client. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_GetRsp(tOBX_HANDLE shandle, UINT8 rsp_code, BT_HDR *p_pkt) -{ - return obx_prepend_rsp_msg(shandle, OBX_GET_CFM_SEVT, rsp_code, p_pkt); -} - - -/******************************************************************************* -** -** Function OBX_AbortRsp -** -** Description This function is called to send the response to an Abort -** Request from an OBEX client. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_AbortRsp(tOBX_HANDLE shandle, UINT8 rsp_code, BT_HDR *p_pkt) -{ - return obx_prepend_rsp_msg(shandle, OBX_ABORT_CFM_SEVT, rsp_code, p_pkt); -} - -/******************************************************************************* -** -** Function OBX_ActionRsp -** -** Description This function is called to respond to an Action command Request -** from an OBEX client. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_ActionRsp(tOBX_HANDLE shandle, UINT8 rsp_code, BT_HDR *p_pkt) -{ - return obx_prepend_rsp_msg(shandle, OBX_ACTION_CFM_SEVT, rsp_code, p_pkt); -} - -/******************************************************************************* -** -** Function OBX_DisconnectRsp -** -** Description This function is called to send the response to a Disconnect -** Request from an OBEX client. -** This function can also be used to force close the transport -** to a connected client. -** -** Returns OBX_SUCCESS, if successful. -** OBX_BAD_HANDLE, if the handle is not valid. -** -*******************************************************************************/ -tOBX_STATUS OBX_DisconnectRsp(tOBX_HANDLE shandle, UINT8 rsp_code, BT_HDR *p_pkt) -{ - return obx_prepend_rsp_msg(shandle, OBX_DISCNT_CFM_SEVT, rsp_code, p_pkt); -} -#endif diff --git a/stack/obx/obx_ssm.c b/stack/obx/obx_ssm.c deleted file mode 100644 index 2e06404..0000000 --- a/stack/obx/obx_ssm.c +++ /dev/null @@ -1,365 +0,0 @@ -/***************************************************************************** -** -** Name: obx_ssm.c -** -** File: OBEX Server State Machine and Control Block Access Functions -** -** Copyright (c) 2003-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> - -#include "btu.h" /* for timer */ -#include "obx_int.h" - -/* OBEX Server Action Functions Enums (must match obx_sr_action [below] */ -enum -{ - OBX_SA_CLOSE_PORT, - OBX_SA_CONNECTION_ERROR, - OBX_SA_STATE, - OBX_SA_CONNECT_IND, - OBX_SA_WC_CONN_IND, - OBX_SA_NC_TO, - OBX_SA_CONNECT_RSP, - OBX_SA_AUTH_IND, - OBX_SA_SND_RSP, - OBX_SA_SAVE_REQ, - OBX_SA_SND_PART, - OBX_SA_REJ_REQ, - OBX_SA_ABORT_RSP, - OBX_SA_OP_RSP, - OBX_SA_GET_IND, - OBX_SA_GET_REQ, - OBX_SA_SESSION_IND, - OBX_SA_SESS_CONN_IND, - OBX_SA_WC_SESS_IND, - OBX_SA_SESSION_RSP, - OBX_SA_PUT_IND, - OBX_SA_SRM_PUT_REQ, - OBX_SA_SRM_PUT_RSP, - OBX_SA_SRM_GET_FCS, - OBX_SA_SRM_GET_RSP, - OBX_SA_SRM_GET_REQ, - OBX_SA_CLEAN_PORT -}; - -/* OBEX Server Action Functions */ -static const tOBX_SR_ACT obx_sr_action[] = -{ - obx_sa_close_port, - obx_sa_connection_error, - obx_sa_state, - obx_sa_connect_ind, - obx_sa_wc_conn_ind, - obx_sa_nc_to, - obx_sa_connect_rsp, - obx_sa_auth_ind, - obx_sa_snd_rsp, - obx_sa_save_req, - obx_sa_snd_part, - obx_sa_rej_req, - obx_sa_abort_rsp, - obx_sa_op_rsp, - obx_sa_get_ind, - obx_sa_get_req, - obx_sa_session_ind, - obx_sa_sess_conn_ind, - obx_sa_wc_sess_ind, - obx_sa_session_rsp, - obx_sa_put_ind, - obx_sa_srm_put_req, - obx_sa_srm_put_rsp, - obx_sa_srm_get_fcs, - obx_sa_srm_get_rsp, - obx_sa_srm_get_req, - obx_sa_clean_port -}; - -/************ OBX Server FSM State/Event Indirection Table **************/ -/* obx_ssm_event() first looks at obx_ssm_entry_map[][] to get an entry of the event of a particular state - * 0 means the event in the current state is ignored. - * a number with 0x80 bit set, use obx_sr_all_table[][] as the "state table". - * other numbers, look up obx_sr_main_state_table[] for the state table of current state. - * - * once the state table is determined, - * look up the "action" column to find the associated action function - * and the "next state" column to find the "next state" candidate. - * - * The actual next state could be either the state in the "next state" column - * or the state returned from the action function. - */ -static const UINT8 obx_ssm_entry_map[][OBX_SS_MAX-1] = -{ -/* state name: NtCon SesIn CntIn WtAut AutIn Conn DscIn StpIn ActIn AbtIn PutIn GetIn Put Get PutS GetS Part WtCls */ -/* CONN_R */{ 1, 0x82, 0x82, 1, 0x82, 0x86, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82 ,1 }, -/* SESS_R */{ 3, 0x82, 0x82, 0x82, 0x82, 0x88, 3, 0x85, 0x85, 0x85, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 1 ,3 }, -/* DISCNT_R */{ 0x86, 0x82, 0x82, 0x82, 0x82, 0x85, 0x82, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 1 ,0x86 }, -/* PUT_R */{ 0x86, 0x82, 0x82, 0x82, 0x82, 1, 0x87, 0x87, 0x87, 0x82, 0x87, 0x87, 1, 0x82, 1, 0x82, 0x82 ,0x86 }, -/* GET_R */{ 0x86, 0x82, 0x82, 0x82, 0x82, 2, 0x87, 0x87, 0x87, 0x82, 0x87, 0x87, 0x82, 1, 0x82, 1, 0x82 ,0x86 }, -/* SETPATH_R*/{ 0x86, 0x82, 0x82, 0x82, 0x82, 3, 0x87, 0x87, 0x87, 0x82, 0x87, 0x87, 0x82, 0x82, 0x82, 0x82, 0x82 ,0x86 }, -/* ACTION_R */{ 0x86, 0x82, 0x82, 0x82, 0x82, 4, 0x87, 0x87, 0x87, 0x82, 0x87, 0x87, 0x82, 0x82, 0x82, 0x82, 0x82 ,0x86 }, -/* ABORT_R */{ 0x86, 0x82, 0x82, 0x82, 0x82, 0x86, 0x82, 0x82, 0x82, 0x82, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 1 ,0x86 }, -/* CONN_C */{ 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 }, -/* SESS_C */{ 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 }, -/* DISCNT_C */{ 0, 0x82, 0x82, 0x82, 0x82, 0x82, 1, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82 ,0 }, -/* PUT_C */{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 2, 0, 0 ,0 }, -/* GET_C */{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 2, 0 ,0 }, -/* SETPATH_C*/{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 }, -/* ACTION_C */{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ,0 }, -/* ABORT_C */{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 ,0 }, -/* PORT_CLS */{ 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83 ,0x83 }, -/* FCS_SET */{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2 ,0 }, -/* STATE */{ 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84 ,0x84 }, -/* TIMEOUT */{ 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,2 }, -/* BAD_REQ */{ 0x86, 0x82, 0x82, 0x82, 0x82, 0x86, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82 ,0x86 }, -/* TX_EMPTY */{ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 } -}; - -static const UINT8 obx_sr_all_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* ABORT_R */{OBX_SM_NO_ACTION, OBX_SS_ABORT_INDICATED }, -/* misc */{OBX_SA_CLOSE_PORT, OBX_SS_NOT_CONNECTED }, -/* PORT_CLS */{OBX_SA_CONNECTION_ERROR, OBX_SS_NOT_CONNECTED }, -/* STATE */{OBX_SA_STATE, OBX_SS_NULL }, -/* DISCNT_R */{OBX_SM_NO_ACTION, OBX_SS_DISCNT_INDICATED }, -/* misc */{OBX_SA_REJ_REQ, OBX_SS_NULL }, -/* illegalop*/{OBX_SA_CLEAN_PORT, OBX_SS_NOT_CONNECTED }, -/* SESS_R */{OBX_SA_SESSION_IND, OBX_SS_SESS_INDICATED } -}; - -static const UINT8 obx_sr_not_conn_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONN_R */{OBX_SA_CONNECT_IND, OBX_SS_CONN_INDICATED }, -/* TIMEOUT */{OBX_SA_NC_TO, OBX_SS_NOT_CONNECTED}, -/* SESS_R */{OBX_SA_SESS_CONN_IND, OBX_SS_SESS_INDICATED } -}; - -static const UINT8 obx_sr_connect_ind_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONN_C */{OBX_SA_CONNECT_RSP, OBX_SS_CONNECTED } -}; - -static const UINT8 obx_sr_session_ind_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* SESS_R */{OBX_SA_SESSION_RSP, OBX_SS_NOT_CONNECTED } -}; - -static const UINT8 obx_sr_wait_auth_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONN_R */{OBX_SA_AUTH_IND, OBX_SS_AUTH_INDICATED }, -/* TIMEOUT */{OBX_SA_CLOSE_PORT, OBX_SS_NOT_CONNECTED} -}; - -static const UINT8 obx_sr_conn_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* PUT_R */{OBX_SA_PUT_IND, OBX_SS_PUT_INDICATED }, -/* GET_R */{OBX_SA_GET_IND, OBX_SS_GET_INDICATED }, -/* SETPATH_R*/{OBX_SM_NO_ACTION, OBX_SS_SETPATH_INDICATED }, -/* ACTION_R */{OBX_SM_NO_ACTION, OBX_SS_ACTION_INDICATED } -}; - -static const UINT8 obx_sr_disconnect_ind_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* DISCNT_C */{OBX_SA_SND_RSP, OBX_SS_WAIT_CLOSE }, -/* TIMEOUT */{OBX_SA_CLOSE_PORT, OBX_SS_NOT_CONNECTED}, -/* SESS_R */{OBX_SA_SESSION_IND, OBX_SS_DISCNT_INDICATED} -}; - -static const UINT8 obx_sr_setpath_ind_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* SETPATH_C*/{OBX_SA_SND_RSP, OBX_SS_CONNECTED } -}; - -static const UINT8 obx_sr_abort_ind_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* GET/PUT_C*/{OBX_SA_OP_RSP, OBX_SS_ABORT_INDICATED }, -/* ABORT_C */{OBX_SA_ABORT_RSP, OBX_SS_CONNECTED } -}; - -static const UINT8 obx_sr_put_ind_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* PUT_C */{OBX_SA_SND_RSP, OBX_SS_PUT_TRANSACTION } -}; - -static const UINT8 obx_sr_get_ind_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* GET_C */{OBX_SA_SND_RSP, OBX_SS_GET_TRANSACTION } -}; - -static const UINT8 obx_sr_put_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* PUT_R */{OBX_SM_NO_ACTION, OBX_SS_PUT_INDICATED } -}; - -static const UINT8 obx_sr_get_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* GET_R */{OBX_SA_GET_REQ, OBX_SS_GET_INDICATED } -}; - -static const UINT8 obx_sr_put_s_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* PUT_R */{OBX_SA_SRM_PUT_REQ, OBX_SS_PUT_SRM }, -/* PUT_C */{OBX_SA_SRM_PUT_RSP, OBX_SS_PUT_SRM } -}; - -static const UINT8 obx_sr_get_s_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* GET_R */{OBX_SA_SRM_GET_REQ, OBX_SS_GET_SRM }, -/* GET_C */{OBX_SA_SRM_GET_RSP, OBX_SS_GET_SRM }, -/* FCS_SET */{OBX_SA_SRM_GET_FCS, OBX_SS_GET_SRM } -}; - -static const UINT8 obx_sr_part_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* ABORT_R */{OBX_SA_SAVE_REQ, OBX_SS_NULL },/* and DISCNT_R */ -/* FCS_SET */{OBX_SA_SND_PART, OBX_SS_NULL } -}; - -static const UINT8 obx_sr_wait_close_table[][OBX_SM_NUM_COLS] = { -/* Event Action Next State */ -/* CONN_R */{OBX_SA_WC_CONN_IND, OBX_SS_CONN_INDICATED }, -/* TIMEOUT */{OBX_SA_NC_TO, OBX_SS_NOT_CONNECTED}, -/* SESS_R */{OBX_SA_WC_SESS_IND, OBX_SS_SESS_INDICATED } -}; - -static const tOBX_SM_TBL obx_sr_main_state_table[] = { - obx_sr_not_conn_table, - obx_sr_session_ind_table, - obx_sr_connect_ind_table, - obx_sr_wait_auth_table, - obx_sr_connect_ind_table, /* same table for auth ind */ - obx_sr_conn_table, - obx_sr_disconnect_ind_table, - obx_sr_setpath_ind_table, - obx_sr_setpath_ind_table, /* same action table for action_ind */ - obx_sr_abort_ind_table, - obx_sr_put_ind_table, - obx_sr_get_ind_table, - obx_sr_put_table, - obx_sr_get_table, - obx_sr_put_s_table, - obx_sr_get_s_table, - obx_sr_part_table, - obx_sr_wait_close_table -}; - -/******************************************************************************* -** -** Function obx_ssm_event -** -** Description Handle events to the server state machine. It looks up the entry -** in the obx_ssm_entry_map array. If it is a valid entry, it gets -** the state table.Set the next state, if not NULL state.Execute -** the action function according to the state table. If the state -** returned by action function is not NULL state, adjust the new -** state to the returned state.If (api_evt != MAX), call callback -** function. -** -** Returns void. -** -*******************************************************************************/ -void obx_ssm_event(tOBX_SR_SESS_CB *p_scb, tOBX_SR_EVENT event, BT_HDR *p_msg) -{ - UINT8 curr_state = p_scb->state; - tOBX_SM_TBL state_table; - UINT8 action, entry; - tOBX_SR_STATE act_state = OBX_SS_NULL; - UINT8 *p_data; - UINT16 len; - BT_HDR *p_dummy; - tOBX_EVENT api_evt; - tOBX_SR_CB *p_cb; -#if 0 - UINT8 srm; -#endif - - if( curr_state == OBX_SS_NULL || curr_state >= OBX_SS_MAX) - { - OBX_TRACE_WARNING1( "Invalid state: %d", curr_state) ; - if(p_msg) - GKI_freebuf(p_msg); - return; - } - - OBX_TRACE_DEBUG6( "For Server SHandle 0x%x, State: %s, Event: %s/%d srm:0x%x ssn:%d", - p_scb->ll_cb.comm.handle, obx_sr_get_state_name( p_scb->state ), - obx_sr_get_event_name(event), event, p_scb->srm, p_scb->ssn ) ; - - /* look up the state table for the current state */ - /* lookup entry /w event & curr_state */ - /* If entry is ignore, return. - * Otherwise, get state table (according to curr_state or all_state) */ - /* coverity [index_parm] */ - if( (entry = obx_ssm_entry_map[event][curr_state-1]) != OBX_SM_IGNORE ) - { - if(entry&OBX_SM_ALL) - { - entry &= OBX_SM_ENTRY_MASK; - state_table = obx_sr_all_table; - } - else - state_table = obx_sr_main_state_table[curr_state-1]; - } - else - { - OBX_TRACE_WARNING2( "Ignore event %d in state %d", event, curr_state ); - if(p_msg) - GKI_freebuf(p_msg); - return; - } - - /* Get possible next state from state table. */ - if( state_table[entry-1][OBX_SME_NEXT_STATE] != OBX_CS_NULL ) - p_scb->state = state_table[entry-1][OBX_SME_NEXT_STATE]; - p_scb->prev_state = curr_state; - OBX_TRACE_DEBUG3( "possible new state = %s/%s/%d", - obx_sr_get_state_name(p_scb->state), obx_sr_get_state_name( p_scb->prev_state ), p_scb->prev_state) ; - - /* If action is not ignore, clear param, exec action and get next state. - * The action function may set the Param for cback. - * Depending on param, call cback or free buffer. */ - /* execute action */ - action = state_table[entry-1][OBX_SME_ACTION]; - if (action != OBX_SM_NO_ACTION) - { - act_state = (*obx_sr_action[action])(p_scb, p_msg); - } - - /* adjust next state, if it needs to use the new state returned from action function */ - if( act_state != OBX_CS_NULL) - { - p_scb->state = act_state; - OBX_TRACE_DEBUG1( "new state = %s (action)", obx_sr_get_state_name( p_scb->state ) ) ; - } - - if(p_scb->api_evt) - { - api_evt = p_scb->api_evt; - p_scb->api_evt = OBX_NULL_EVT; - /* we do not want the operation to be challenged by the client */ - if( event <= OBX_SEVT_MAX_REQ && event != OBX_CONNECT_REQ_SEVT && - OBX_ReadByteStrHdr(p_msg, OBX_HI_CHALLENGE, &p_data, &len, 0) == TRUE) - { - /* send bad request response */ - p_dummy = obx_build_dummy_rsp(p_scb, OBX_RSP_BAD_REQUEST); - event += OBX_SEVT_DIFF_REQ_CFM; - obx_ssm_event(p_scb, event, p_dummy); - GKI_freebuf(p_msg); - } - else - { - p_cb = &obx_cb.server[p_scb->handle - 1]; - (p_cb->p_cback) (p_scb->ll_cb.comm.handle, api_evt, p_scb->param, p_msg); - } - memset(&p_scb->param, 0, sizeof (p_scb->param) ); - } - else if(action == OBX_SM_NO_ACTION && p_msg) - GKI_freebuf(p_msg); - - - OBX_TRACE_DEBUG2( "result state = %s ssn:%d", obx_sr_get_state_name( p_scb->state ), p_scb->ssn ) ; -} - - diff --git a/stack/obx/obx_utils.c b/stack/obx/obx_utils.c deleted file mode 100644 index 785df18..0000000 --- a/stack/obx/obx_utils.c +++ /dev/null @@ -1,979 +0,0 @@ -/***************************************************************************** -** -** Name: obx_utils.c -** -** File: OBEX common utility functions -** -** Copyright (c) 2003-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include <string.h> -#include <stdio.h> -#include "wcassert.h" - - -#include "bt_target.h" -#include "obx_int.h" -#include "port_api.h" -#include "sdpdefs.h" -#include "l2c_api.h" - -const tOBX_EVENT obx_sm_evt_to_api_evt[OBX_MAX_EVT_MAP_NUM] = -{ - OBX_CONNECT_REQ_EVT, - OBX_SESSION_REQ_EVT, /* A Crease Session or Resume Session request is received by the server. Call OBX_SessionRsp(). */ - OBX_DISCONNECT_REQ_EVT, - OBX_PUT_REQ_EVT, - OBX_GET_REQ_EVT, - OBX_SETPATH_REQ_EVT, - OBX_ACTION_REQ_EVT, /* An Action request is received by the server. Call OBX_ActionRsp(). */ - OBX_ABORT_REQ_EVT -}; - - -const UINT8 obx_rsp_code[] = -{ - OBX_RSP_CONTINUE, /* 0x10 Continue */ - OBX_RSP_OK, /* 0x20 OK, Success */ - OBX_RSP_CREATED, /* 0x21 Created */ - OBX_RSP_ACCEPTED, /* 0x22 Accepted */ - OBX_RSP_NON_AUTH_INFO, /* 0x23 Non-Authoritative Information */ - OBX_RSP_NO_CONTENT, /* 0x24 No Content */ - OBX_RSP_RESET_CONTENT, /* 0x25 Reset Content */ - OBX_RSP_PART_CONTENT, /* 0x26 Partial Content */ - OBX_RSP_MULTI_CHOICES, /* 0x30 Multiple Choices */ - OBX_RSP_MVD_PERM, /* 0x31 Moved Permanently */ - OBX_RSP_MVD_TEMP, /* 0x32 Moved temporarily */ - OBX_RSP_SEE_OTHER, /* 0x33 See Other */ - OBX_RSP_NOT_MODIFIED, /* 0x34 Not modified */ - OBX_RSP_USE_PROXY, /* 0x35 Use Proxy */ - OBX_RSP_BAD_REQUEST, /* 0x40 Bad Request - server couldn't understand request */ - OBX_RSP_UNAUTHORIZED, /* 0x41 Unauthorized */ - OBX_RSP_PAYMENT_REQD, /* 0x42 Payment required */ - OBX_RSP_FORBIDDEN, /* 0x43 Forbidden - operation is understood but refused */ - OBX_RSP_NOT_FOUND, /* 0x44 Not Found */ - OBX_RSP_NOT_ALLOWED, /* 0x45 Method not allowed */ - OBX_RSP_NOT_ACCEPTABLE, /* 0x46 Not Acceptable */ - OBX_RSP_PROXY_AUTH_REQD, /* 0x47 Proxy Authentication required */ - OBX_RSP_REQUEST_TIMEOUT, /* 0x48 Request Time Out */ - OBX_RSP_CONFLICT, /* 0x49 Conflict */ - OBX_RSP_GONE, /* 0x4A Gone */ - OBX_RSP_LENGTH_REQD, /* 0x4B Length Required */ - OBX_RSP_PRECONDTN_FAILED, /* 0x4C Precondition failed */ - OBX_RSP_REQ_ENT_2_LARGE, /* 0x4D Requested entity too large */ - OBX_RSP_REQ_URL_2_LARGE, /* 0x4E Request URL too large */ - OBX_RSP_UNSUPTD_TYPE, /* 0x4F Unsupported media type */ - OBX_RSP_INTRNL_SRVR_ERR, /* 0x50 Internal Server Error */ - OBX_RSP_NOT_IMPLEMENTED, /* 0x51 Not Implemented */ - OBX_RSP_BAD_GATEWAY, /* 0x52 Bad Gateway */ - OBX_RSP_SERVICE_UNAVL, /* 0x53 Service Unavailable */ - OBX_RSP_GATEWAY_TIMEOUT, /* 0x54 Gateway Timeout */ - OBX_RSP_HTTP_VER_NOT_SUPTD, /* 0x55 HTTP version not supported */ - OBX_RSP_DATABASE_FULL, /* 0x60 Database Full */ - OBX_RSP_DATABASE_LOCKED, /* 0x61 Database Locked */ - OBX_RSP_DEFAULT -}; - -static void obx_read_mtu(BT_HDR *p_pkt, tOBX_HANDLE handle, tOBX_CONN_EVT *p_evt); - -/******************************************************************************* -** Function obx_read_srm -** Description read the SRM and SRM_PARAM headers from the packet received from -** peer and set the control block data member accordingly -** Return UINT8 -*******************************************************************************/ -UINT8 obx_read_srm (tOBX_SRM *p_srm, BOOLEAN is_client, BT_HDR *p_pkt) -{ - UINT8 srm, srmp = 0, ret_srmp=0; - UINT8 old_srm = *p_srm; - BOOLEAN allowed = FALSE, clear = TRUE; - - OBX_TRACE_DEBUG1("obx_read_srm srm:0x%x", *p_srm ); - if (*p_srm) - { - /* if the SRM enable request is not granted in the next packet, the request is not valid any more - * clear the requesting flag */ - *p_srm &= ~OBX_SRM_REQING; - - if (OBX_Read1ByteHdr(p_pkt, OBX_HI_SRM, &srm)) - { - if (srm == OBX_HV_SRM_ENABLE) - { - if (is_client) - { - if (old_srm & OBX_SRM_REQING) - { - *p_srm |= OBX_SRM_ENGAGE; - allowed = TRUE; - } - } - else /* is server */ - { - *p_srm |= OBX_SRM_REQING; - allowed = TRUE; - } - } - OBX_TRACE_DEBUG3("SRM :0x%x srm:0x%x old_srm:0x%x", srm, *p_srm, old_srm ); - } - - if (!allowed) - allowed = old_srm & OBX_SRM_PARAM_AL; - - if (OBX_Read1ByteHdr(p_pkt, OBX_HI_SRM_PARAM, &srmp)) - { - if ((srmp == OBX_HV_SRM_PARAM_WAIT) && allowed) - { - ret_srmp = OBX_SRMP_WAIT; - *p_srm |= OBX_SRM_PARAM_AL; - clear = FALSE; - } - } - OBX_TRACE_DEBUG4("SRM_PARAM :0x%x srm:0x%x allowed:%d clear:%d", srmp, *p_srm, allowed, clear ); - - /* once the SRMP header is not used, it should be ignored for the rest of the transaction */ - if (clear) - *p_srm &= ~OBX_SRM_PARAM_AL; - } - - return ret_srmp; -} - -/******************************************************************************* -** Function obx_add_timeout -** Description add the timeout triplet -** -** Return UINT8 -*******************************************************************************/ -UINT8 obx_add_timeout (tOBX_TRIPLET *p_trip, UINT32 timeout, tOBX_SESS_EVT *p_param) -{ - UINT8 *p; - UINT8 ret = 0; - - if (timeout != OBX_INFINITE_TIMEOUT) - { - p_trip->tag = OBX_TAG_SESS_PARAM_TOUT; - p_trip->len = OBX_TIMEOUT_SIZE; - p = p_trip->p_array; - UINT32_TO_BE_STREAM(p, timeout); - ret = 1; - } - p_param->timeout = timeout; - return ret; -} - -/******************************************************************************* -** Function obx_read_timeout -** Description add the timeout triplet -** -** Return void -*******************************************************************************/ -void obx_read_timeout (tOBX_TRIPLET *p_trip, UINT8 num, UINT32 *p_timeout, UINT8 *p_toa) -{ - UINT8 ind; - UINT8 *p; - UINT32 tmp; - - p = p_toa; - BE_STREAM_TO_UINT32(tmp, p); - OBX_TRACE_DEBUG2("obx_read_timeout %d/%d", *p_timeout, tmp); - if (*p_timeout == 0) - *p_timeout = tmp; - ind = obx_read_triplet(p_trip, num, OBX_TAG_SESS_PARAM_TOUT); - if ((ind != num) && (p_trip[ind].len == OBX_TIMEOUT_SIZE)) - { - p = p_trip[ind].p_array; - BE_STREAM_TO_UINT32(tmp, p); - if (tmp < (*p_timeout)) - { - (*p_timeout) = tmp; - OBX_TRACE_DEBUG1("new timeout %d", tmp); - } - } - UINT32_TO_BE_STREAM(p_toa, (*p_timeout)); -} - -#if (OBX_CLIENT_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_verify_response -** Description -** Return OBX_BAD_SM_EVT, if bad. -*******************************************************************************/ -UINT8 obx_verify_response(UINT8 opcode, tOBX_RX_HDR *p_rxh) -{ - UINT8 final = (opcode & OBX_FINAL) ? TRUE : FALSE; - int xx = 0; - UINT8 res_code = opcode & ~OBX_FINAL; - - p_rxh->sm_evt = OBX_BAD_SM_EVT; - - /* response packet must have the final bit set */ - if (final == TRUE) - { - if (res_code == OBX_RSP_CONTINUE) - { - p_rxh->sm_evt = OBX_CONT_CFM_CEVT; - } - else - { - /* figure out the kind of response, Continue, OK, or Error */ - while(obx_rsp_code[xx] != OBX_RSP_DEFAULT) - { - if (obx_rsp_code[xx] == res_code) - break; - xx++; - } - - if (obx_rsp_code[xx] != OBX_RSP_DEFAULT) - { - if (obx_rsp_code[xx] <= OBX_MAX_OK_RSP) - p_rxh->sm_evt = OBX_OK_CFM_CEVT; - else - p_rxh->sm_evt = OBX_FAIL_CFM_CEVT; - } - /* else bad response code */ - } - if (p_rxh->sm_evt != OBX_BAD_SM_EVT) - { - p_rxh->code = opcode; - } - } - /* - else final bit not set in response packet -> bad response code - */ - - return p_rxh->sm_evt; -} - -/******************************************************************************* -** -** Function obx_cl_proc_pkt -** -** Description process a packet received from the connected server -** verify that the response is valid -** fill in event parameters -** call csm to process the event -** -** Returns void -** -*******************************************************************************/ -void obx_cl_proc_pkt (tOBX_CL_CB *p_cb, BT_HDR *p_pkt) -{ - tOBX_RX_HDR *p_rxh; - UINT32 conn_id; - BOOLEAN pass = FALSE; - UINT8 xx; - tOBX_TRIPLET triplet[OBX_MAX_NUM_AUTH_TRIPLET]; - UINT8 num_trip = OBX_MAX_NUM_AUTH_TRIPLET; - tOBX_CL_EVENT sm_evt; - UINT8 ssn; - - OBX_TRACE_DEBUG3("obx_cl_proc_pkt 0x%x srm:0x%x, sess_st:%d", p_pkt, p_cb->srm, p_cb->sess_st); - OBX_TRACE_DEBUG1("csm offset:%d", p_cb->param.sess.obj_offset); - - p_rxh = (tOBX_RX_HDR *)(p_pkt + 1); - p_cb->rsp_code = p_rxh->code & ~OBX_FINAL; - - p_pkt->event = OBX_PUT_RSP_EVT; /* any response */ - /* setup callback event param - memset(&p_cb->param, 0, sizeof(tOBX_EVT_PARAM)); */ - - if (p_cb->state == OBX_CS_CONNECT_REQ_SENT ) - { - /* when a response packet is received in conn_rs state, - * it must be a connect response packet */ - p_pkt->event = OBX_CONNECT_RSP_EVT; - p_cb->param.conn.handle = p_cb->ll_cb.port.handle; - obx_read_mtu(p_pkt, p_cb->ll_cb.port.handle, &(p_cb->param.conn)); - p_cb->ll_cb.port.tx_mtu = p_cb->param.conn.mtu; - - /* save Connection ID */ - if (OBX_Read4ByteHdr(p_pkt, OBX_HI_CONN_ID, &conn_id) == TRUE) - p_cb->conn_id = conn_id; - OBX_TRACE_DEBUG1("Connection ID: 0x%x", p_cb->conn_id ); - } - - if (p_cb->sess_st == OBX_SESS_ACTIVE) - { - /* verify the session sequence number */ - if (OBX_Read1ByteHdr (p_pkt, OBX_HI_SESSION_SN, &ssn)) - { - OBX_TRACE_DEBUG1("ssn:%d", ssn); - p_cb->param.ssn = ssn; - } - } - - sm_evt = p_rxh->sm_evt; - - if (p_cb->wait_auth == TRUE) - { - /* this can only happen for CONNECT */ - if (p_cb->rsp_code == OBX_RSP_OK) - { - /* successful according to server */ - /* verify the digest */ - p_cb->wait_auth = FALSE; - /* The coverity complaints on this function is not correct. - * The value in triplet[] is set/initialized by OBX_ReadTriplet if num_trip returns TRUE. - * leave this unnecessary memset here */ - memset(triplet,0,sizeof(triplet)); - if (OBX_ReadTriplet(p_pkt, OBX_HI_AUTH_RSP, triplet, &num_trip)) - { - for (xx=0; xx<num_trip; xx++) - { - if (triplet[xx].tag == OBX_DIGEST_RSP_TAG) - { - if (memcmp (p_cb->p_auth, triplet[xx].p_array, OBX_DIGEST_SIZE) == 0) - pass = TRUE; - break; - } - } - } - if (pass == FALSE) - { - OBX_TRACE_ERROR0("Failed - server does not provide good digest" ); - p_cb->wait_auth = OBX_WAIT_AUTH_FAIL; - p_cb->rsp_code = OBX_RSP_FAILED; - } - } - } - if (p_cb->p_auth) - GKI_freebuf(p_cb->p_auth); - p_cb->p_auth = NULL; - - p_cb->srmp = obx_read_srm (&p_cb->srm, TRUE, p_pkt); - obx_csm_event(p_cb, sm_evt, p_pkt); -} - -/******************************************************************************* -** -** Function obx_cl_prepend_msg -** -** Description This function is used by API functions to add the data in the -** reserved space in the OBEX packet -** -** Returns void. -** -*******************************************************************************/ -BT_HDR * obx_cl_prepend_msg(tOBX_CL_CB *p_cb, BT_HDR *p_pkt, UINT8 * p_data, UINT16 data_len) -{ - UINT8 *p; - UINT16 len; - - if (p_pkt == NULL) - { - p_pkt = OBX_HdrInit(OBX_HANDLE_NULL, OBX_MIN_MTU); - len = data_len; - } - else - { - len = p_pkt->len + data_len; - } - - WC_ASSERT(p_pkt->offset >= data_len); - p = (UINT8 *)(p_pkt + 1) + p_pkt->offset - data_len; - memcpy(p, p_data, data_len); - p++; - /* adjust the packet len */ - UINT16_TO_BE_STREAM(p, len); - p_pkt->len += data_len; - p_pkt->offset -= data_len; - p_pkt->layer_specific -= data_len; - - return p_pkt; -} -#endif /* OBX_CLIENT_INCLUDED */ - -#if (OBX_SERVER_INCLUDED == TRUE) -/******************************************************************************* -** Function obx_verify_request -** Description -** Return OBX_BAD_SM_EVT, if bad. -*******************************************************************************/ -UINT8 obx_verify_request(UINT8 opcode, tOBX_RX_HDR *p_rxh) -{ - UINT8 final = (opcode & OBX_FINAL) ? TRUE : FALSE; - UINT8 req_code = opcode & ~OBX_FINAL; - p_rxh->sm_evt = OBX_BAD_SM_EVT; - - OBX_TRACE_DEBUG2("obx_verify_request opcode 0x%x: final:%d", opcode, final); - switch (req_code) - { - case OBX_REQ_CONNECT: - /* this request must have the final bit set */ - if (final == TRUE) - p_rxh->sm_evt = OBX_CONNECT_REQ_SEVT; - break; - - case OBX_REQ_SESSION: - /* this request must have the final bit set */ - if (final == TRUE) - p_rxh->sm_evt = OBX_SESSION_REQ_SEVT; - break; - - case OBX_REQ_ACTION: - /* this request must have the final bit set */ - if (final == TRUE) - p_rxh->sm_evt = OBX_ACTION_REQ_SEVT; - break; - - case OBX_REQ_DISCONNECT: - /* this request must have the final bit set */ - if (final == TRUE) - p_rxh->sm_evt = OBX_DISCNT_REQ_SEVT; - break; - - case OBX_REQ_PUT: - p_rxh->sm_evt = OBX_PUT_REQ_SEVT; - break; - - case OBX_REQ_GET: - p_rxh->sm_evt = OBX_GET_REQ_SEVT; - break; - - case OBX_REQ_SETPATH: - /* this request must have the final bit set */ - if (final == TRUE) - p_rxh->sm_evt = OBX_SETPATH_REQ_SEVT; - break; - - case OBX_REQ_ABORT: - /* this request must have the final bit set */ - if (final == TRUE) - p_rxh->sm_evt = OBX_ABORT_REQ_SEVT; - break; - } - - if (p_rxh->sm_evt != OBX_BAD_SM_EVT) - { - p_rxh->code = opcode; - } - return p_rxh->sm_evt; -} - -/******************************************************************************* -** -** Function obx_is_get_or_put_cont -** -** Returns TRUE, if it's a GET/PUT continuing continuing -** TRUE, if it's an ABORT -** -*******************************************************************************/ -BOOLEAN obx_is_get_or_put_cont (tOBX_SR_SESS_CB *p_scb, UINT8 req_code) -{ - BOOLEAN is_cont = FALSE; - - if (req_code == OBX_REQ_ABORT) - { - is_cont = TRUE; - } - else if (req_code == OBX_REQ_PUT) - { - if (p_scb->state == OBX_SS_PUT_TRANSACTION || p_scb->state == OBX_SS_PUT_SRM) - { - is_cont = TRUE; - } - } - else if (req_code == OBX_REQ_GET) - { - if (p_scb->state == OBX_SS_GET_TRANSACTION || p_scb->state == OBX_SS_GET_SRM) - { - is_cont = TRUE; - } - } - - return is_cont; -} - -/******************************************************************************* -** -** Function obx_sr_proc_pkt -** -** Description process a packet received from the connected client -** verify that the request is valid -** fill in event parameters -** call ssm to process the event -** -** Returns TRUE, if abort -** -*******************************************************************************/ -BOOLEAN obx_sr_proc_pkt (tOBX_SR_SESS_CB *p_scb, BT_HDR *p_pkt) -{ - tOBX_RX_HDR *p_rxh; - UINT8 *p_body; - UINT16 len; - BOOLEAN end; - UINT32 conn_id = 0; - UINT8 req_code; - BOOLEAN final; - UINT8 ssn, tmp_ssn; - UINT8 num_hdrs, num_body, num_ssn; - UINT8 rsp_code = OBX_RSP_OK; - UINT8 num_id; - BOOLEAN chk_add = FALSE; - - p_rxh = (tOBX_RX_HDR *)(p_pkt + 1); - final = (p_rxh->code & OBX_FINAL) ? TRUE : FALSE; - req_code = p_rxh->code & ~OBX_FINAL; - p_scb->api_evt = (UINT8)p_pkt->event; - memset(&p_scb->param, 0, sizeof(tOBX_EVT_PARAM)); - p_scb->param.get.final = final; - - num_id = OBX_Read4ByteHdr (p_pkt, OBX_HI_CONN_ID, &conn_id); - - OBX_TRACE_DEBUG6("obx_sr_proc_pkt 0x%x srm:0x%x sess_st:%d req_code:0x%x, sm_evt:%d ssn:%d", - p_pkt, p_scb->srm, p_scb->sess_st, req_code, p_rxh->sm_evt, p_scb->ssn); - - num_ssn = OBX_Read1ByteHdr (p_pkt, OBX_HI_SESSION_SN, &ssn); - if (p_scb->srm & OBX_SRM_ABORT) - { - /* OBX_SRM_ABORT bit is set by server only when PUT req /w SRM is rejected before transaction actually ends - * this means we need to ignore follow packets until the next transaction starts */ - if (req_code == OBX_REQ_PUT) - { - /* check if this is the put for the previous transaction */ - num_hdrs = OBX_ReadNumHdrs(p_pkt, &num_body); - OBX_TRACE_DEBUG4("num_hdrs:%d num_body:%d num_id:%d num_ssn:%d", num_hdrs, num_body, num_id, num_ssn); - num_body += num_ssn; - num_body += num_id; - if (num_hdrs <= num_body) - { - p_scb->ssn = ssn+1; - /* it is left-over, drop it. */ - if (p_pkt) - GKI_freebuf (p_pkt); - p_scb->api_evt = OBX_NULL_EVT; - return TRUE; - } - } - /* clear the SRM bits; leave only the enabled bit */ - p_scb->srm &= OBX_SRM_ENABLE; - } - - if ((p_scb->sess_st == OBX_SESS_ACTIVE) && (req_code != OBX_REQ_SESSION) && (req_code != OBX_REQ_ABORT)) - { - rsp_code = OBX_RSP_BAD_REQUEST; - /* verify the session sequence number */ - if (num_ssn) - { - OBX_TRACE_DEBUG2("ssn pkt/cb=%d/%d", ssn, p_scb->ssn); - if (ssn == p_scb->ssn) - { - p_scb->param.ssn = p_scb->ssn; - rsp_code = OBX_RSP_OK; - } - else if (p_scb->srmp & OBX_SRMP_SESS_FST) - { - tmp_ssn = ssn+1; - if (tmp_ssn == p_scb->ssn) - { - p_scb->param.ssn = ssn; - p_scb->ssn = ssn; - rsp_code = OBX_RSP_OK; - } - } - } - p_scb->srmp &= ~OBX_SRMP_SESS_FST; - } - - /* fill event parameter */ - if (req_code == OBX_REQ_CONNECT) - { - p_scb->param.conn.handle = p_scb->handle; - obx_read_mtu(p_pkt, p_scb->ll_cb.comm.handle, &(p_scb->param.conn)); - - p_scb->ll_cb.port.tx_mtu = p_scb->param.conn.mtu; - /* verify the target header and connection ID - * in obx_sa_connect_ind() for OBX_SS_NOT_CONNECTED */ - /* verify the connection ID in obx_sa_auth_ind() for OBX_SS_WAIT_AUTH */ - chk_add = TRUE; - } - else if (req_code == OBX_REQ_SESSION) - { - /* do nothing */ - if (conn_id != 0) - { - OBX_TRACE_ERROR1("Session command should not use Connection ID: 0x%x", conn_id); - p_rxh->sm_evt = OBX_BAD_REQ_SEVT; - } - } - else - { - OBX_TRACE_DEBUG3("Connection ID: 0x%x/0x%x state:%d", p_scb->conn_id, conn_id, p_scb->state ); - /* verify the connection ID */ - if ( (conn_id == p_scb->conn_id) || - (conn_id == 0 && p_scb->conn_id != 0 && obx_is_get_or_put_cont(p_scb, req_code))) - { - /* match: both non-exist or both exist and equal */ - /* connection ID header does not exist, but control block uses connection ID, - * if this is continuation packets for PUT and GET, it's OK */ - if (req_code == OBX_REQ_PUT) - { - p_scb->param.put.final = final; - - /* determine the PUT type */ - p_scb->param.put.type = OBX_PT_PUT; - if (p_scb->state == OBX_SS_CONNECTED && final == TRUE) - { - if (OBX_ReadBodyHdr(p_pkt, &p_body, &len, &end) == FALSE) - { - /* final is set, no BODY or End-of-Body - * -> Delete request */ - p_scb->param.put.type = OBX_PT_DELETE; - } - else if (end == TRUE && len == 0) - { - /* an empty End-of-Body header - * -> Create-Empty request */ - p_scb->param.put.type = OBX_PT_CREATE; - } - } - OBX_TRACE_EVENT1("Put request type: %d", p_scb->param.put.type); - } - else if (req_code == OBX_REQ_SETPATH) - { - p_scb->param.sp.flag = *((UINT8 *)(p_pkt + 1) + p_pkt->offset + OBX_SETPATH_FLAG_OFFSET); - } - } - else - { - /* does not have good connection ID */ - p_rxh->sm_evt = OBX_BAD_REQ_SEVT; - p_scb->api_evt = OBX_NULL_EVT; - } - } - - /* process the SRM header */ - p_scb->srmp |= obx_read_srm (&p_scb->srm, FALSE, p_pkt); - - if (p_rxh->sm_evt != OBX_BAD_REQ_SEVT && req_code != OBX_REQ_ABORT) - { - p_scb->cur_op = req_code; - if (final) - p_scb->cur_op |= OBX_FINAL; - } - - if (rsp_code != OBX_RSP_OK) - { - p_rxh->sm_evt = OBX_BAD_REQ_SEVT; - } - - OBX_TRACE_DEBUG2("rsp_code:0x%x, sm_evt:%d", rsp_code, p_rxh->sm_evt); - - obx_ssm_event(p_scb, p_rxh->sm_evt, p_pkt); - if (chk_add) - { - if (p_scb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg) - obx_add_port(p_scb->handle); - } - return FALSE; -} - -/******************************************************************************* -** -** Function obx_sr_prepend_msg -** -** Description This function is used by API functions to add the data in the -** reserved space in the OBEX packet -** -** Returns void. -** -*******************************************************************************/ -BT_HDR * obx_sr_prepend_msg(BT_HDR *p_pkt, UINT8 * p_data, UINT16 data_len) -{ - UINT8 *p; - UINT16 len; - - if (p_pkt == NULL) - { - p_pkt = OBX_HdrInit(OBX_HANDLE_NULL, OBX_MIN_MTU); - len = data_len; - } - else - { - len = p_pkt->len + data_len; - } - - WC_ASSERT(p_pkt->offset >= data_len); - p = (UINT8 *)(p_pkt + 1) + p_pkt->offset - data_len; - memcpy(p, p_data, data_len); - p++; - /* adjust the packet len */ - UINT16_TO_BE_STREAM(p, len); - p_pkt->len += data_len; - p_pkt->offset -= data_len; - p_pkt->layer_specific -= data_len; - - return p_pkt; -} -#endif /* OBX_SERVER_INCLUDED */ - -/******************************************************************************* -** -** Function obx_read_mtu -** -** Description This function is used to access the MTU in CONNECT packets -** -** Returns void. -** -*******************************************************************************/ -void obx_read_mtu(BT_HDR *p_pkt, tOBX_HANDLE handle, tOBX_CONN_EVT *p_evt) -{ - UINT8 *p = (UINT8 *)(p_pkt + 1) + p_pkt->offset + OBX_CONNECT_MTU_OFFSET; - - BE_STREAM_TO_UINT16(p_evt->mtu, p); - if (p_evt->mtu > OBX_MAX_MTU) - p_evt->mtu = OBX_MAX_MTU; - if (p_evt->mtu == 0) - p_evt->mtu = OBX_MIN_MTU; - - /* Get the Bd_Addr */ - OBX_GetPeerAddr (handle, p_evt->peer_addr); -} - -/******************************************************************************* -** -** Function obx_free_buf -** -** Description This function is used to free the GKI buffers of the given -** lower layer control block -** -** Returns void. -** -*******************************************************************************/ -void obx_free_buf(tOBX_LL_CB *p_ll_cb) -{ - void *p_pkt; - - - if (p_ll_cb->comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg) - { - if (p_ll_cb->port.p_rxmsg) - { - OBX_TRACE_WARNING0("obx_free_buf release p_rxmsg"); - GKI_freebuf(p_ll_cb->port.p_rxmsg); - p_ll_cb->port.p_rxmsg = 0; - } - } - - if (!GKI_queue_is_empty(&p_ll_cb->comm.rx_q)) - { - while((p_pkt = GKI_dequeue (&p_ll_cb->comm.rx_q)) != NULL) - { - OBX_TRACE_WARNING0("obx_free_buf release rx_q"); - GKI_freebuf(p_pkt); - } - } - - if (p_ll_cb->comm.p_txmsg) - { - OBX_TRACE_WARNING0("obx_free_buf release p_txmsg"); - GKI_freebuf(p_ll_cb->comm.p_txmsg); - p_ll_cb->comm.p_txmsg = 0; - } -} - -/******************************************************************************* -** -** Function obx_flow_control -** -** Description If we had flowed control the peer, enable the data path now -** -** Returns void. -** -*******************************************************************************/ -void obx_flow_control(tOBX_COMM_CB *p_comm) -{ - OBX_TRACE_DEBUG1 ("obx_flow_control stopped:%d", p_comm->stopped ); - if (p_comm->stopped) - { - if (p_comm->p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg) - { - PORT_FlowControl(p_comm->id, TRUE); - } - else - { - L2CA_FlowControl(p_comm->id, TRUE); - } - p_comm->stopped = FALSE; - } -} - -/***************************************************************************** -* Function: obx_read_triplet -* Purpose: Read the application parameters with the given tag -*****************************************************************************/ -UINT8 obx_read_triplet(tOBX_TRIPLET *p_trip, UINT8 num_trip, UINT8 tag) -{ - UINT8 xx = 0; - - for (xx=0; xx<num_trip; xx++, p_trip++) - { - if (p_trip->tag == tag) - { - break; - } - } - - return xx; -} -/***************************************************************************** -* Function: obx_read_obj_offset -* Purpose: Read the application parameters with the object offset tag -*****************************************************************************/ -UINT32 obx_read_obj_offset(tOBX_TRIPLET *p_trip, UINT8 num_trip) -{ - UINT32 obj_offset = 0; - UINT8 ind; - UINT8 *p = NULL, *pe; - UINT8 extra = 0, xx; - - ind = obx_read_triplet(p_trip, num_trip, OBX_TAG_SESS_PARAM_OBJ_OFF); - if (ind != num_trip) - { - if (p_trip[ind].len == 4) - { - p = p_trip[ind].p_array; - } - else if (p_trip[ind].len > 4) - { - extra = p_trip[ind].len - 4; - } - - if (extra) - { - /* the TLV is bigger than 4 bytes - * if the MSBs are all 0, we can still handle it with UINT32 */ - pe = p_trip[ind].p_array; - for (xx=0; xx<extra; xx++) - { - if (*pe == 0) - pe++; - else - break; - } - if (xx == extra) - p = pe; - } - - if (p) - BE_STREAM_TO_UINT32(obj_offset, p); - } - - return obj_offset; -} - -/******************************************************************************* -** -** Function obxu_dump_hex -** -** Description This function dumps hex data -** -*/ -#if (BT_USE_TRACES == TRUE) -void obxu_dump_hex (UINT8 *p, char *p_title, UINT16 len) -{ - UINT16 xx, yy; - char buff1[100], buff2[20]; - - if (p_title) - OBX_TRACE_DEBUG1 ("%s:", p_title); - - memset (buff2, ' ', 16); - buff2[16] = 0; - - yy = sprintf (buff1, "%04x: ", 0); - for (xx = 0; xx < len; xx++) - { - if ( (xx) && ((xx & 15) == 0) ) - { - OBX_TRACE_DEBUG2 (" %s %s", buff1, buff2); - yy = sprintf(buff1, "%04x: ", xx); - memset (buff2, ' ', 16); - } - yy += sprintf (&buff1[yy], "%02x ", *p); - - if ((*p >= ' ') && (*p <= 'z')) - buff2[xx & 15] = *p; - else - buff2[xx & 15] = '.'; - - p++; - } - - /* Pad out the remainder */ - for ( ; ; xx++) - { - if ((xx & 15) == 0) - { - OBX_TRACE_DEBUG2 (" %s %s", buff1, buff2); - break; - } - yy += sprintf (&buff1[yy], " "); - } - -} -#endif - -/******************************************************************************* -** -** Function OBX_GetPeerAddr -** -** Description This function is called to learn the Bluetooth address of the -** connected device. -** -** Returns L2CAP channel ID. -** -*******************************************************************************/ -UINT16 OBX_GetPeerAddr(tOBX_HANDLE shandle, BD_ADDR bd_addr) -{ - UINT16 lcid = 0; -#if (OBX_SERVER_INCLUDED == TRUE) - tOBX_SR_SESS_CB *p_scb; -#endif -#if (OBX_CLIENT_INCLUDED == TRUE) - tOBX_CL_CB *p_cb; - - if (shandle & OBX_CL_HANDLE_MASK) - { - p_cb = obx_cl_get_cb(shandle); - if (p_cb) - { - if (p_cb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg) - { - PORT_CheckConnection(p_cb->ll_cb.port.port_handle, p_cb->peer_addr, &lcid); - memcpy (bd_addr, p_cb->peer_addr, BD_ADDR_LEN); - lcid = p_cb->ll_cb.comm.id; - } - else if (p_cb->ll_cb.comm.id) - { - /* GetPeerAddr for l2c */ - memcpy (bd_addr, p_cb->peer_addr, BD_ADDR_LEN); - lcid = p_cb->ll_cb.comm.id; - } - } - } -#endif - -#if (OBX_SERVER_INCLUDED == TRUE) - if ((shandle & OBX_CL_HANDLE_MASK) == 0) - { - p_scb = obx_sr_get_scb(shandle); - if (p_scb) - { - if (p_scb->ll_cb.comm.p_send_fn == (tOBX_SEND_FN *)obx_rfc_snd_msg) - { - PORT_CheckConnection(p_scb->ll_cb.port.port_handle, bd_addr, &lcid); - } - else if (p_scb->ll_cb.comm.id) - { - /* GetPeerAddr for l2c */ - memcpy (bd_addr, p_scb->peer_addr, BD_ADDR_LEN); - lcid = p_scb->ll_cb.comm.id; - } - } - } -#endif - - return lcid; -} diff --git a/stack/xml/xml_bld.c b/stack/xml/xml_bld.c deleted file mode 100644 index 57a7347..0000000 --- a/stack/xml/xml_bld.c +++ /dev/null @@ -1,192 +0,0 @@ -/***************************************************************************** -** -** Name: xml_bld_api.c -** -** File: Implements the XML Builder -** -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> -#include <stdio.h> - -#include "bt_target.h" -#include "xml_bld_api.h" - -/* The XML Builder is dependent on the Object Store. At present -** the object store resides in GOEP and hence the builder is -** dependent on GOEP. The builder only uses the Object Store -** in GOEP, so if the Object Store is separated from GOEP in the -** future, the builder will not be dependent on GOEP. -*/ - -/***************************************************************************** -** Constants -*****************************************************************************/ -#define XML_ST "<" -#define XML_EM "/" -#define XML_SP " " -#define XML_CO ":" -#define XML_EQ "=" -#define XML_GT ">" -#define XML_QT "\"" - -#define XML_LF "\n" /* Line feed */ - -/***************************************************************************** -** Interface functions -*****************************************************************************/ - - -/***************************************************************************** -** -** Function: XML_BufAddTag -** -** Purpose: Write a start or end tag and optional prefix. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** GOEP_WriteStore. -** const UINT8* prefix tag prefix (namespace) -** const UINT8* tag tag name -** BOOLEAN start_tag TRUE = start tag, FALSE = end tag -** BOOLEAN has_attr TRUE if the tag contains attributes -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddTag (UINT8 **pp_buf, - const UINT8 *prefix, - const UINT8 *tag, - BOOLEAN start_tag, - BOOLEAN has_attr) -{ - UINT16 status = XML_BLD_ERROR; - int n; - - if (tag != NULL) - { - if(start_tag) - n = sprintf((char *)*pp_buf, XML_ST); - else - n = sprintf((char *)*pp_buf, XML_ST XML_EM); - *pp_buf += n; - - if (prefix != NULL) - { - n = sprintf((char *)*pp_buf, "%s" XML_CO, prefix ); - *pp_buf += n; - } - n = sprintf((char *)*pp_buf, "%s" , tag ); - *pp_buf += n; - if(!has_attr) - { - n = sprintf((char *)*pp_buf, XML_GT); - *pp_buf += n; - if (!start_tag) - { - n = sprintf((char *)*pp_buf, XML_LF); - *pp_buf += n; - } - } - - status = XML_BLD_SUCCESS; - } - return status; -} - - - -/***************************************************************************** -** -** Function: XML_BufAddAttribute -** -** Purpose: Write an attribute and optional prefix. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** const UINT8* prefix attribute prefix (namespace) -** const UINT8* attr_name attribute name -** const UINT8* attr_value attribute value -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddAttribute (UINT8 **pp_buf, - const UINT8 *prefix, - const UINT8 *attr_name, - const UINT8 *attr_value, - tXML_ATTR_END last_attr) -{ - UINT16 status = XML_BLD_ERROR; - int n; - - if (attr_name != NULL && attr_value != NULL) - { - n = sprintf((char *)*pp_buf, XML_SP); - *pp_buf += n; - if (prefix != NULL) - { - n = sprintf((char *)*pp_buf, "%s" XML_CO, prefix ); - *pp_buf += n; - } - n = sprintf((char *)*pp_buf, "%s" XML_EQ XML_QT "%s", attr_name, attr_value ); - *pp_buf += n; - switch(last_attr) - { - case XML_ATTR_CONT: - n = sprintf((char *)*pp_buf, XML_QT ); - break; - case XML_ATTR_LAST: - n = sprintf((char *)*pp_buf, XML_QT XML_GT XML_LF ); - break; - case XML_ATTR_ETAG: - n = sprintf((char *)*pp_buf, XML_QT XML_EM XML_GT XML_LF ); - break; - default: - n = 0; - break; - } - *pp_buf += n; - status = XML_BLD_SUCCESS; - } - else if(last_attr == XML_ATTR_ETAG) - { - /* allow the call to only add the closing attribute */ - n = sprintf((char *)*pp_buf, XML_EM XML_GT XML_LF ); - *pp_buf += n ; - status = XML_BLD_SUCCESS; - } - return status; -} - -/***************************************************************************** -** -** Function: XML_BufAddCharData -** -** Purpose: Write the element content. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** const UINT8* content element content -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddCharData (UINT8 **pp_buf, const UINT8 *charData) -{ - UINT16 status = XML_BLD_ERROR; - int n; - - if (charData != NULL) - { - n = sprintf((char *)*pp_buf, "%s", charData); - *pp_buf += n; - status = XML_BLD_SUCCESS; - } - return status; -} - diff --git a/stack/xml/xml_erp.c b/stack/xml/xml_erp.c deleted file mode 100644 index 90711e2..0000000 --- a/stack/xml/xml_erp.c +++ /dev/null @@ -1,907 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_erp.c - ** - ** Description: This module contains xml parser of MAP event report object - ** - ** Copyright (c) 2004-2011, Broadcom Corporation, All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#include "bt_target.h" -#include "gki.h" -#include "xml_erp_api.h" - -#include <string.h> -#include <stdlib.h> - -#ifndef EVT_RPT_DEBUG_XML -#define EVT_RPT_DEBUG_XML TRUE -#endif -#define EVT_RPT_DEBUG_LEN 50 -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - -#define XML_PERM_LEN_MAX 4 - -/***************************************************************************** -** Constants -*****************************************************************************/ - -const UINT8 xml_evt_rpt_elem[] = "MAP-event-report"; -const UINT8 xml_evt_rpt_event_elem[] = "event"; -const UINT8 xml_evt_rpt_type_attr[] = "type"; -const UINT8 xml_evt_rpt_handle_attr[] = "handle"; -const UINT8 xml_evt_rpt_folder_attr[] = "folder"; -const UINT8 xml_evt_rpt_old_folder_attr[] = "old_folder"; -const UINT8 xml_evt_rpt_msg_type_attr[] = "msg_type"; -const UINT8 xml_evt_rpt_version_attr[] = "version"; -const UINT8 xml_evt_rpt_unknown[] = "unknown"; - -#define XML_EVT_RPT_ELEM_ID 0x01 -#define XML_EVT_RPT_EVT_ELEM_ID 0x02 -#define XML_EVT_RPT_MAX_OBJ_TAG_ID XML_EVT_RPT_ELEM_ID -#define XML_EVT_RPT_TYPE_ATTR_ID 0x03 -#define XML_EVT_RPT_HANDLE_ATTR_ID 0x04 -#define XML_EVT_RPT_FOLDER_ATTR_ID 0x05 -#define XML_EVT_RPT_OLD_FOLDER_ATTR_ID 0x06 -#define XML_EVT_RPT_MSG_TYPE_ATTR_ID 0x07 -#define XML_EVT_RPT_VERSION_ATTR_ID 0x08 -#define XML_EVT_RPT_UNKNOWN_ID 0x09 -#define XML_EVT_RPT_MAX_ID 0x0a /* keep in sync with above */ -#define XML_EVT_RPT_TAG_END_ID 0x0b /* closing tag found end=true */ -#define XML_EVT_RPT_PAUSE_ID 0x0c /* closing tag found end=false */ - - -#define XML_EVT_RPT_TTBL_SIZE (XML_EVT_RPT_MAX_ID+1) - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -typedef struct -{ - const UINT8 *p_name; - UINT8 len; -} tXML_EVT_RPT_TTBL_ELEM; - -typedef tXML_EVT_RPT_TTBL_ELEM tXML_EVT_RPT_TTBL[]; /* Tag Table */ - - -static const tXML_EVT_RPT_TTBL_ELEM xml_erp_ttbl[XML_EVT_RPT_TTBL_SIZE] = -{ /* index (EVT_RPT_XP_*_ID) & name */ - {(UINT8*) "", XML_EVT_RPT_MAX_ID-1}, /* \x00 Number of elements in array */ - /* XML EVT_RPT element (TAG) name */ - {xml_evt_rpt_elem, 16}, /* x01 MAP-event-report */ - {xml_evt_rpt_event_elem, 5}, /* 0x02 event */ - {xml_evt_rpt_type_attr, 4}, /* x03 type */ - {xml_evt_rpt_handle_attr, 6}, /* x04 handle */ - {xml_evt_rpt_folder_attr, 6}, /* x05 folder */ - {xml_evt_rpt_old_folder_attr, 10}, /* x06 old_folder */ - {xml_evt_rpt_msg_type_attr, 8}, /* x07 msg_type */ - {xml_evt_rpt_version_attr, 7}, /* x08 version */ - {xml_evt_rpt_unknown, 7} /* x09 unknown */ -}; - -#define XML_MAP_EVT_RPT_PTBL_SIZE 0x03 -typedef UINT8 * tXML_MAP_EVT_RPT_PTBL_ELEM; - -static const tXML_MAP_EVT_RPT_PTBL_ELEM xml_erp_ptbl[XML_MAP_EVT_RPT_PTBL_SIZE] = -{ - (UINT8 *) "\x01", /* index x00, all valide attributes in above list */ - (UINT8 *) "\x08\x02", /* x01 attributes and sub-tags supported */ - (UINT8 *) "\x03\x04\x05\x06\x07" /* x02: event report attributes */ -}; - - -#if (EVT_RPT_DEBUG_XML == TRUE) -void xml_erp_debug_str(tXML_STR *p_str, UINT8 *p_buf) -{ - int dbg_len; - if ( (p_str == NULL) || (NULL==p_str->p)) - BCM_STRNCPY_S( (char *)p_buf, EVT_RPT_DEBUG_LEN, "(NULL)", EVT_RPT_DEBUG_LEN-1 ); - else - { - dbg_len = p_str->len; - if ( dbg_len >= EVT_RPT_DEBUG_LEN) - dbg_len = EVT_RPT_DEBUG_LEN - 1; - BCM_STRNCPY_S( (char *)p_buf, EVT_RPT_DEBUG_LEN, (char *)p_str->p, dbg_len); - p_buf[dbg_len] = 0; - } -} - -#else -#define xml_erp_debug_str(p_str, p_buf) -#endif - -/***************************************************************************** - ** Function xml_erp_proc_tag - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_erp_proc_tag( tXML_EVT_RPT_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - UINT8 dbg_name[EVT_RPT_DEBUG_LEN]; -#endif - - - if (curr < XML_MAP_EVT_RPT_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_erp_ptbl[curr]; p_stag && *p_stag ; p_stag++) - { - if (*p_stag >= XML_EVT_RPT_TTBL_SIZE) - continue; - if (p_name->len == xml_erp_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_erp_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_erp_proc_tag: bad name:%s", dbg_name ); -#endif - - return XML_EVT_RPT_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_erp_proc_attr - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_erp_proc_attr(tXML_EVT_RPT_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (EVT_RPT_DEBUG_XML == TRUE) - UINT8 dbg_name[EVT_RPT_DEBUG_LEN]; -#endif - if (curr < XML_MAP_EVT_RPT_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_erp_ptbl[curr]; p_stag && *p_stag; p_stag++) - { - if (*p_stag >= XML_EVT_RPT_TTBL_SIZE) - continue; - if (p_name->len == xml_erp_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_erp_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_erp_proc_attr: bad name:%s", dbg_name); -#endif - return XML_EVT_RPT_UNKNOWN_ID; -} - -/***************************************************************************** - ** Function xml_erp_find_ch_n_copy - ** Description copy any chacter till one char in p_str. Any char in p_str - ** will stop copy pointed by p_begin - ** Parameters - ** Returns - *****************************************************************************/ -static void xml_erp_find_ch_n_copy( tXML_MCOPY *p_copy ) -{ - const UINT8 *p_tmp; - const UINT8 *p_str = (UINT8 *)">"; /* was: ":=/> \t\n\r". i think we should copy till - closing flag */ - unsigned int last = XML_EVT_RPT_CARRY_OVER_LEN; /* maximum carry over len we can support */ - UINT8 *p_last = p_copy->last.p + p_copy->last.len - 1; /* point to the last char of carry - over buffer */ - BOOLEAN found = FALSE; - /* check if the last char in p_last is in p_str */ - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_last == *p_tmp) - { - found = TRUE; - break; - } - } /* for */ - - if (found == FALSE) - { - /* if not in p_str, move chars from p_begin to p_last - * until reached last_len or any char in p_str */ - p_last++; - last -= p_copy->last.len; /* calculate the maximum number of chars we can copy */ - while (*(p_copy->p_begin) && last) /* rl: not sure that this buffer is termninated by a 0 */ - { - /* copy from source (new buffer) to carry over. adjust only carry over ptr. */ - *p_last++ = *p_copy->p_begin; - last--; - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_copy->p_begin == *p_tmp) - { - p_copy->p_begin++; /* adjust pointer to point to next char to read */ - /* calculate new length of carry over buffer contents */ - p_copy->last.len = XML_EVT_RPT_CARRY_OVER_LEN-last; - *p_last = 0; /* NULL terminate p_last. rl: not really neccessary. */ - return; - } - } /* for */ - p_copy->p_begin++; /* update now to next char. this way abort char is also copied */ - } /* while */ - } /* !found */ -} - -/***************************************************************************** -** Function xml_evt_rpt_cback -** Description -** -** Parameters -** Returns -*****************************************************************************/ -static BOOLEAN xml_evt_rpt_cback( tXML_EVENT event, void *p_event_data, void *p_usr_data) -{ - tXML_MEVT_DATA *p_ed = (tXML_MEVT_DATA*) p_event_data; - tXML_EVT_RPT_STATE *p_st = (tXML_EVT_RPT_STATE *) p_usr_data; - tXML_PROP *p_cp = &p_st->p_prop[p_st->prop_index]; - BOOLEAN ret = TRUE; - UINT8 next; /* next element */ - UINT8 curr = p_ed->stack.stack[p_ed->stack.top]; /* current element */ -#if (EVT_RPT_DEBUG_XML == TRUE) - UINT8 dbg_name[EVT_RPT_DEBUG_LEN]; - UINT8 dbg_prefix[EVT_RPT_DEBUG_LEN]; - UINT8 dbg_value[EVT_RPT_DEBUG_LEN]; -#endif - -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("xml_evt_rpt_cback:%d", event); -#endif - - switch (event) - { - case XML_TAG : /* <tag-name */ - next = xml_erp_proc_tag(p_st, &p_ed->tag.name, &p_ed->stack); -#if (EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(&p_ed->tag.name, dbg_name); - xml_erp_debug_str(&p_ed->tag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("XML_TAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - -#endif - if (next != 0) - { - if (next <= XML_EVT_RPT_MAX_OBJ_TAG_ID) - p_st->obj = next; - - if (p_st->prop_index <p_st->max_num_prop) - { - /* we do not use prefix in FTC */ - p_cp->name = next; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - } - break; - - case XML_ATTRIBUTE : /* attr-name="attr-value" */ - curr = xml_erp_proc_attr(p_st, &p_ed->attr.name, &p_ed->stack); -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(&p_ed->attr.name, dbg_name); - xml_erp_debug_str(&p_ed->attr.prefix, dbg_prefix); - xml_erp_debug_str(&p_ed->attr.value, dbg_value); - XML_TRACE_DEBUG4("[xml evt_rpt] XML_ATTRIBUTE: p:%s, name:%s, v:%s, curr:%x", - dbg_prefix, dbg_name, dbg_value, curr ); - XML_TRACE_DEBUG2("top 1:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - if ((curr != 0) && (curr != XML_EVT_RPT_UNKNOWN_ID)) - { - if (p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = curr; - p_cp->p_data = p_ed->attr.value.p; - p_cp->len = p_ed->attr.value.len; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - p_ed->stack.top--; - XML_TRACE_DEBUG2("top 2:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - } - break; - - case XML_CHARDATA : -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(&p_ed->ch_data.value, dbg_value); - XML_TRACE_DEBUG2("XML_CHARDATA: v:%s, last:%d", dbg_value, p_ed->ch_data.last); -#endif - break; - - case XML_ETAG : /* </tag-name> */ - if (p_ed->stack.top > 0) - { - p_ed->stack.stack[p_ed->stack.top] = 0; - p_ed->stack.top--; - p_st->ended = (BOOLEAN) (p_ed->stack.top == 0); - } -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(&p_ed->etag.name, dbg_name); - xml_erp_debug_str(&p_ed->etag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("[xml evt_rpt] XML_ETAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("[xml evt_rpt] top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - break; - - case XML_TAG_END: /* /> */ - curr = p_ed->stack.stack[p_ed->stack.top]; - - if (p_st->prop_index <p_st->max_num_prop) - { - if (p_ed->empty_elem.end) - p_cp->name = XML_EVT_RPT_TAG_END_ID; - else - p_cp->name = XML_EVT_RPT_PAUSE_ID; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - if (p_ed->empty_elem.end && p_ed->stack.top > 0) - { - p_ed->stack.top--; - } - } - else - ret = FALSE; - -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4("[xml evt_rpt] XML_TAG_END: %d, top:x%x, stk:x%x, curr:x%x", - p_ed->empty_elem.end, p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top], curr); -#endif - break; - - case XML_PARTIAL: - if (p_st->p_prop[p_st->prop_index-1].name != XML_EVT_RPT_TAG_END_ID) - { - p_ed->stack.top--; -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("[xml evt_rpt] adjust due to XML_PARTIAL"); -#endif - } - break; - - case XML_COPY: - xml_erp_find_ch_n_copy( &p_ed->copy ); - XML_TRACE_DEBUG1("[xml evt_rpt] XML_COPY: %s", p_ed->copy.last.p); - break; - - default : -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("[xml evt_rpt] default: XML event: %d", event); -#endif - break; - } - - return ret; -} - - - - -/********************************************************************************** -** Function xml_erp_int_fill_file_folder -** Description fill in file/folder structure. -** -** Parameters -** Returns xx: > 0 : number of properties scanned, folder entry is added -** = 0 : no end tag found, carry over to next parse -** = -1: no dst_resource avaibale, all prop left to next parse -** = -2: exceed max entry, no folder entry added -**********************************************************************************/ -static INT16 xml_erp_int_fill_evt_rpt( tXML_EVT_RPT_STATE * p_xud, - tXML_PROP *p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - INT16 xx; - UINT16 len; - BOOLEAN end = FALSE; - tXML_PROP *cur_prop = p_prop; - UINT8 *p_cur_offset = *p_dst_data; - BOOLEAN copy_attr_info; - BOOLEAN no_buf_left; - UINT8 **p_attr_data = NULL; - UINT16 *p_attr_len = NULL; - - if ( p_xud->current_entry >= p_xud->max_entry ) - return -2; - - for (xx=0; (xx < *num_prop) && !end; xx++, cur_prop++) - { -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - /* XML_TRACE_DEBUG5( "[xml evt_rpt] fill: num_prop:%d, name id: x%x, p_prop: x%x, len: %d p_data:%s", - (*num_prop-xx) , cur_prop->name, cur_prop, cur_prop->len, cur_prop->p_data, ); */ -#endif - copy_attr_info = TRUE; - no_buf_left = FALSE; - len = cur_prop->len; - - switch (cur_prop->name) - { - case XML_EVT_RPT_TYPE_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].type) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].type_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - - case XML_EVT_RPT_HANDLE_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].handle) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].handle_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_EVT_RPT_FOLDER_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].folder) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].folder_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_EVT_RPT_OLD_FOLDER_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].old_folder) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].old_folder_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_EVT_RPT_MSG_TYPE_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].msg_type) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].msg_type_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_EVT_RPT_TAG_END_ID: - /* -------------------- CUSTOMER SPECIFIC ---------------------- */ - p_xud->current_entry++; /* increment only when end tag (/>) found */ - copy_attr_info = FALSE; - XML_TRACE_DEBUG1("[xml ml]: current_entry=%d",p_xud->current_entry); - break; - /* case XML_VERSION_ATTR_ID: */ - default: - copy_attr_info = FALSE; - XML_TRACE_DEBUG1("[xml evt_rpt] unknown attrib: %d", cur_prop->name ); - break; - } - - if (copy_attr_info && p_attr_data && p_attr_len) - { - *p_attr_data = p_cur_offset; - *p_attr_len = len; - - memcpy( (void *)*p_attr_data, - (const void *)cur_prop->p_data, - len ); - (*p_attr_data)[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - - #if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - - XML_TRACE_DEBUG5("[xml evt_rpt]: Attr ID=%d val=[%s] len=%d level=%d dst_len lef=%d", - cur_prop->name, - *p_attr_data, - *p_attr_len, - cur_prop->level, - *dst_len); - #endif - } - - if (no_buf_left) - { - return -1; - } - - } -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("[xml evt_rpt] fill_evt_rpt: end:%d, xx:%d", end, xx); -#endif -#if 0 - /* if end tag not found -> split over two buffers. but parser will still show rest of - found properties. so return still found properties. */ - if (end == FALSE) - xx = 0; -#endif - - /* keep track of current data buffer offset */ - *p_dst_data = p_cur_offset; - return xx; -} /* xml_erp_int_fill_file_evt_rpt() */ - - -/********************************************************************************** -** Function xml_erp_int_fill_evt_data -** -** Description fill in MAP event report structure. -** -** Parameters -** Returns -**********************************************************************************/ -static tXML_EVT_RPT_RES xml_erp_int_fill_evt_data( UINT8 op, - void *p_evt_data, - tXML_PROP **p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - tXML_EVT_RPT_STATE *p_xud = (tXML_EVT_RPT_STATE *)p_evt_data; - INT16 inc_prop; - UINT8 prop_name; /* Property name. */ - tXML_PROP *cur_prop = *p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - tXML_EVT_RPT_RES x_res = XML_EVT_RPT_OK; - BOOLEAN x_no_res = FALSE; /* guard dest buffer resource */ - - if ( op == 0 || op > XML_EVT_RPT_MAX_OBJ_TAG_ID || *num_prop == 0) - return XML_EVT_RPT_ERROR; - -#if EVT_RPT_DEBUG_XML - XML_TRACE_DEBUG2( "[xml evt_rpt] xml_erp_int_fill_evt_data op:%d, num_prop:%d", - op, *num_prop); -#endif - - - - while ( *num_prop > 0 && !x_no_res ) - { -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("end_prop:%d, name id: x%x", *num_prop, cur_prop->name); -#endif - prop_name = cur_prop->name; - cur_prop++; - *num_prop -= 1; - - - switch ( prop_name ) - { - case XML_EVT_RPT_ELEM_ID: - XML_TRACE_DEBUG0("[xml evt_rpt] xml_etag_elem"); - /* skip over version attribute which should always be 1.0. this is the top level */ - break; - - case XML_EVT_RPT_EVT_ELEM_ID: - XML_TRACE_DEBUG0("[xml evt_rpt] xml_etag_elem"); - inc_prop = xml_erp_int_fill_evt_rpt( p_xud, - cur_prop, - num_prop, - &p_cur_offset, - dst_len); - if (inc_prop == -1) /* no dst_buf available */ - { - /* backup one more prop to obtain the skipped evt_rpt/file entry header */ - cur_prop --; - *num_prop += 1; - - x_res = XML_EVT_RPT_DST_NO_RES; - x_no_res = TRUE; - } - else if (inc_prop == -2) /* exceed max entry */ - { - x_no_res = TRUE; - x_res = XML_EVT_RPT_OUT_FULL; - } - else /* found evt_rpt entry */ - { - cur_prop += inc_prop; - *num_prop -= inc_prop; - } - break; - - case XML_EVT_RPT_PAUSE_ID: - XML_TRACE_DEBUG0("[xml evt_rpt] xml_etag_elem"); - -#if (EVT_RPT_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml evt_rpt] xml_erp_int_fill_evt_data(): XML_EVT_RPT_PAUSE_ID" ); -#endif - break; - - case XML_EVT_RPT_TAG_END_ID: - XML_TRACE_DEBUG0("[xml evt_rpt] xml_etag_elem"); -#if (EVT_RPT_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml evt_rpt] xml_erp_int_fill_evt_data(): XML_EVT_RPT_TAG_END_ID" ); -#endif - break; - - default: - XML_TRACE_DEBUG1( "[xml evt_rpt] xml_erp_int_fill_evt_data():unknown element: %d", prop_name ); - break; - } - } - - /* keep track of current filling position, and current available dst buffer */ - *p_prop = cur_prop; - *p_dst_data = p_cur_offset; - - return x_res; -} /* xml_erp_int_fill_evt_data() */ - - -/************************************************************************************** -** Function XML_EvtRptInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of an xml parser state machine to be initialized, -** allocate an additional space of size XML_EVT_RPT_CARRY_OVER_LEN -** right after *p_xml_state to hold carry over data. -** p_entry : points start of output directory entry. caller needs do -** free this memory -** max_entry : max is 16 bit integer value which is the maximum number -** of evt_rpt entries. - -** -** Returns void -**************************************************************************************/ - -void XML_EvtRptInit( tXML_EVT_RPT_PARSER *p_xml_state, - tXML_EVT_RPT_ENTRY *p_entry, - const UINT16 max_entry ) -{ - XML_TRACE_DEBUG0("[xml evt_rpt] XML_EvtRptInit"); - /* Initialize the generic xml parser state machine.*/ - XML_InitPars( &p_xml_state->xml, xml_evt_rpt_cback, &p_xml_state->xml_user_data ); - - /* User need to allocate an additional space of size XML_EVT_RPT_CARRY_OVER_LEN */ - /* right after *p_xml_state to hold carry over data. */ - /* point to the end of the allocated buffer for p_xml_state, which is the */ - /* beginning of buffer(XML_EVT_RPT_CARRY_OVER_LEN) */ - p_xml_state->xml.last_bfr.p = (UINT8 *)(p_xml_state + 1); - p_xml_state->xml.last_bfr.len = XML_EVT_RPT_CARRY_OVER_LEN; - - /* Initialize user data */ - p_xml_state->xml_user_data.p_entry = p_entry; - p_xml_state->xml_user_data.current_entry = 0; - p_xml_state->xml_user_data.max_name_len = XML_UI_ENTRY_MAX_NAME_LEN + 1; - p_xml_state->xml_user_data.max_entry = (UINT16)max_entry; - p_xml_state->xml_user_data.prop_num = 0; -} - - -/************************************************************************************** -** Function XML_EvtRptParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_EvtRptInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. - When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: pointer to the length of dst_data buffer, its carry out value -** is the number of bytes remaining buffer.When dst_len is NULL, -** it will cause to flush the internal data in the parser. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_EVT_RPT_RES (see xml_erp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_EVT_RPT_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_EVT_RPT_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -tXML_EVT_RPT_RES XML_EvtRptParse( tXML_EVT_RPT_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ) -{ - tXML_OS xos; - BOOLEAN is_remain = TRUE; - tXML_MUL_STATE *p_xml = &p_xml_state->xml; - tXML_EVT_RPT_STATE *p_st = &p_xml_state->xml_user_data; - tXML_EVT_RPT_RES x_res = XML_EVT_RPT_OK; - tXML_RESULT res = XML_NO_PROP; - UINT16 max_num_prop = GKI_BUF3_SIZE/sizeof(tXML_PROP); /* i hope this is sufficient for 1 */ - - -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - int xx; - UINT8 dbg_buf[EVT_RPT_DEBUG_LEN]; - tXML_STR str; -#endif - - XML_TRACE_DEBUG0("[xml evt_rpt] XML_EvtRptParse"); - /* if dst_data is NULL, clean up remaining data */ - if (!dst_data || !dst_len) - { - /* clean out remained xml data left over from last parse */ - if (p_xml_state->xml_user_data.p_prop ) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = p_st->offset_prop = NULL; - p_st->prop_num = 0; - } -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml evt_rpt] XML_EvtRptParse() Clean up left over!"); -#endif - return x_res; - } - - /* if illegal OBEX data or dst buffer pointer received, return ERROR */ - if (xml_len == 0 || !xml_data) - { - return XML_EVT_RPT_ERROR; - } - - /* XML_EvtRptParse receive new xml data, allocate buffer to hold parsed prop */ - if (p_st->offset_prop == NULL) - { - -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml evt_rpt] XML_EvtRptParse() Receive New Data!"); - XML_TRACE_DEBUG2( "[xml evt_rpt] XML_data start[%x] end [%x]",xml_data, xml_data+xml_len); -#endif - is_remain = FALSE; - if ( NULL!= (p_st->p_prop = (tXML_PROP *)GKI_getbuf( GKI_BUF3_SIZE ) ) ) - { - /* pointing next prop to be converted into file entry */ - p_st->prop_num = 0; - } - else - { - GKI_freebuf( p_xml_state ); - x_res = XML_EVT_RPT_NO_RES; - return x_res; - } - } -#if (EVT_RPT_DEBUG_XML == TRUE) - else - { - XML_TRACE_DEBUG0( "[xml evt_rpt] XML_EvtRptParse(): Keep cleaning up old xml data !"); - } -#endif - /* update the data address */ - xos.p_begin = xml_data; - xos.p_end = xml_data + xml_len; - - while ( res == XML_NO_PROP ) - { - /* if no remaining data in p_st->p_prop, parse new xml data */ - if (!is_remain) - { - p_st->max_num_prop = max_num_prop; - p_st->prop_index = 0; - res = XML_MulParse( p_xml, &xos ); - - -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4( "xml_evt_rpt_parse obj: %x, max: %d, num: %d, res: %d", - p_st->obj, max_num_prop, p_st->prop_index, res); - - if (res != 0) - { - XML_TRACE_DEBUG1( "XML_MulParse Parsing: %d !!!", res); - } - - for (xx=0; xx<p_st->prop_index; xx++) - { - if ( p_st->p_prop[xx].name < XML_EVT_RPT_MAX_ID ) - { - str.p = p_st->p_prop[xx].p_data; - str.len = p_st->p_prop[xx].len; - xml_erp_debug_str(&str, dbg_buf); - XML_TRACE_DEBUG5( "[xml evt_rpt] parsed: index[%d]:%d:%s: %s(%d)", p_st->prop_index-xx, p_st->p_prop[xx].level, - xml_erp_ttbl[p_st->p_prop[xx].name].p_name, dbg_buf, p_st->p_prop[xx].len); - } - else - { - XML_TRACE_DEBUG3( "[xml evt_rpt] internal prop: %d:%d:%d", xx, p_st->p_prop[xx].level, - p_st->p_prop[xx].name ); - } - } -#endif - p_st->prop_num = p_st->prop_index ; - p_st->offset_prop = p_st->p_prop; - } - else - { - /* This is left over data, pick up the result from the previous parse */ - res = p_xml->pars_res; - } - - if ( res != XML_OBJ_ST_EMPTY ) - { - x_res = xml_erp_int_fill_evt_data( p_st->obj, p_st, &p_st->offset_prop, &p_st->prop_num, &dst_data, dst_len ); - - if ( (XML_EVT_RPT_OK == x_res) && (XML_NO_END == res) ) - { - /* XML_NO_END means that the xml is not completly finished and fill returns - ok when when partial filling has been ok */ - x_res = XML_EVT_RPT_PENDING; - } - - /* all parsed xml data has been converted into file entry */ - /* or exceed max entry number , break the parsing loop */ - if (XML_EVT_RPT_OUT_FULL != x_res && XML_EVT_RPT_DST_NO_RES != x_res) - { - is_remain = FALSE; - } - else - break; - } - } /* while */ - - /* free property table. at next call a new one is allocated */ - if ((x_res != XML_EVT_RPT_DST_NO_RES && p_st->p_prop) || - XML_EVT_RPT_OUT_FULL == x_res) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = NULL; - p_st->offset_prop = NULL; - } - - if ( x_res != XML_EVT_RPT_DST_NO_RES && p_st->ended) - { - /* this should happen on the same time as final flag in fact */ - x_res = XML_EVT_RPT_END_LIST; /* found closing /evt_rpt-listing */ - } - - - *num_entries = p_st->current_entry; /* report number of entries found. only when ended is true - application really should be interested! */ - return x_res; -} - diff --git a/stack/xml/xml_flp.c b/stack/xml/xml_flp.c deleted file mode 100644 index 688f1b5..0000000 --- a/stack/xml/xml_flp.c +++ /dev/null @@ -1,971 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_flp.c - ** - ** Description: This module contains xml parser of obex folder listing - ** - ** Copyright (c) 2004-2011, Broadcom Corporation, All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#include "bt_target.h" -#include "gki.h" -#include "xml_flp_api.h" - -#include <string.h> -#include <stdlib.h> - -#ifndef FOLDER_DEBUG_XML -#define FOLDER_DEBUG_XML FALSE -#endif -#define FOLDER_DEBUG_LEN 50 -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - -#define XML_PERM_LEN_MAX 4 - -/***************************************************************************** -** Constants -*****************************************************************************/ - -const UINT8 xml_folder_listing_elem[] = "folder-listing"; -const UINT8 xml_file_elem[] = "file"; -const UINT8 xml_folder_elem[] = "folder"; -const UINT8 xml_parent_folder_elem[] = "parent-folder"; -const UINT8 xml_name_attr[] = "name"; -const UINT8 xml_size_attr[] = "size"; -const UINT8 xml_type_attr[] = "type"; -const UINT8 xml_modified_attr[] = "modified"; -const UINT8 xml_created_attr[] = "created"; -const UINT8 xml_accessed_attr[] = "accessed"; -const UINT8 xml_user_perm_attr[] = "user-perm"; -const UINT8 xml_group_perm_attr[] = "group-perm"; -const UINT8 xml_other_perm_attr[] = "other-perm"; -const UINT8 xml_group_attr[] = "group"; -const UINT8 xml_owner_attr[] = "owner"; -const UINT8 xml_version_attr[] = "version"; -const UINT8 xml_lang_attr[] = "xml:lang"; -const UINT8 xml_unknown[] = "unknown"; - -#define XML_FOLDER_LISTING_ELEM_ID 0x01 -#define XML_FILE_ELEM_ID 0x02 -#define XML_FOLDER_ELEM_ID 0x03 -#define XML_PARENT_FOLDER_ELEM_ID 0x04 -#define XML_MAX_OBJ_TAG_ID XML_FOLDER_LISTING_ELEM_ID -#define XML_NAME_ATTR_ID 0x05 -#define XML_SIZE_ATTR_ID 0x06 -#define XML_TYPE_ATTR_ID 0x07 -#define XML_MODIFIED_ATTR_ID 0x08 -#define XML_CREATED_ATTR_ID 0x09 -#define XML_ACCESSED_ATTR_ID 0x0a -#define XML_USER_PERM_ATTR_ID 0x0b -#define XML_GROUP_PERM_ATTR_ID 0x0c -#define XML_OTHER_PERM_ATTR_ID 0x0d -#define XML_GROUP_ATTR_ID 0x0e -#define XML_OWNER_ATTR_ID 0x0f -#define XML_VERSION_ATTR_ID 0x10 -#define XML_LANG_ATTR_ID 0x11 -#define XML_XP_UNKNOWN_ID 0x12 -#define XML_FOLDER_MAX_ID 0x13 /* keep in sync with above */ -#define XML_FOLDER_TAG_END_ID 0x13 /* closing tag found end=true */ -#define XML_FOLDER_PAUSE_ID 0x14 /* closing tag found end=false */ - - -#define XML_FOLDER_TTBL_SIZE (XML_FOLDER_MAX_ID+1) - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -typedef struct -{ - const UINT8 *p_name; - UINT8 len; -} tXML_FOLDER_TTBL_ELEM; - -typedef tXML_FOLDER_TTBL_ELEM tXML_FOLDER_TTBL[]; /* Tag Table */ - - -static const tXML_FOLDER_TTBL_ELEM xml_flp_ttbl[XML_FOLDER_TTBL_SIZE] = -{ /* index (FOLDER_XP_*_ID) & name */ - {(UINT8*) "", XML_FOLDER_MAX_ID-1}, /* \x00 Number of elements in array */ - /* XML FOLDER element (TAG) name */ - {xml_folder_listing_elem, 14}, /* x01 folder-listing */ - {xml_file_elem, 4}, /* 0x02 file */ - {xml_folder_elem, 6}, /* x03 folder */ - {xml_parent_folder_elem, 13}, /* x04 parent-folder */ - {xml_name_attr, 4}, /* x05 name */ - {xml_size_attr, 4}, /* x06 size */ - {xml_type_attr, 4}, /* x07 type */ - {xml_modified_attr, 8}, /* x08 modified */ - {xml_created_attr, 7}, /* x09 created */ - {xml_accessed_attr, 8}, /* x0a accessed */ - {xml_user_perm_attr, 9}, /* x0b user-perm */ - {xml_group_perm_attr, 10}, /* x0c group-perm */ - {xml_other_perm_attr, 10}, /* x0d other-perm */ - {xml_group_attr, 5}, /* x0e group */ - {xml_owner_attr, 5}, /* x0f owner */ - {xml_version_attr, 7}, /* x10 version */ - {xml_lang_attr, 8}, /* x11 xml:lang */ - {xml_unknown, 7 } /* x12 unknown */ -}; - -#define XML_FOLDER_PTBL_SIZE 0x10 -typedef UINT8 * tXML_FOLDER_PTBL_ELEM; - -static const tXML_FOLDER_PTBL_ELEM xml_flp_ptbl[XML_FOLDER_PTBL_SIZE] = -{ - (UINT8 *) "\x01\x02\x03\x04", /* index x00, all valide attributes in above list */ - (UINT8 *) "\x10\x02\x03\x04", /* x01 attributes and sub-tags supported */ - (UINT8 *) "\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x11", /* x02: file attributes */ - (UINT8 *) "\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x11", /* x03: folder attributes */ - (UINT8 *) "" /* x04 parent folder has no attributes */ -}; - - -#if (FOLDER_DEBUG_XML == TRUE) -void xml_flp_debug_str(tXML_STR *p_str, UINT8 *p_buf) -{ - int dbg_len; - if ( (p_str == NULL) || (NULL==p_str->p)) - BCM_STRCPY_S( (char *)p_buf, FOLDER_DEBUG_LEN, "(NULL)" ); - else - { - dbg_len = p_str->len; - if ( dbg_len >= FOLDER_DEBUG_LEN) - dbg_len = FOLDER_DEBUG_LEN - 1; - BCM_STRNCPY_S( (char *)p_buf, FOLDER_DEBUG_LEN, (char *)p_str->p, dbg_len); - p_buf[dbg_len] = 0; - } -} - -#else -#define xml_flp_debug_str(p_str, p_buf) -#endif - -/***************************************************************************** - ** Function xml_flp_proc_tag - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_flp_proc_tag( tXML_FOLDER_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - UINT8 dbg_name[FOLDER_DEBUG_LEN]; -#endif - - if (curr < XML_FOLDER_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_flp_ptbl[curr]; p_stag && *p_stag ; p_stag++) - { - if (*p_stag >= XML_FOLDER_TTBL_SIZE) - continue; - if(p_name->len == xml_flp_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_flp_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_flp_proc_tag: bad name:%s", dbg_name ); -#endif - - p_stk->top++; - p_stk->stack[p_stk->top] = XML_XP_UNKNOWN_ID; - return XML_XP_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_flp_proc_attr - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_flp_proc_attr(tXML_FOLDER_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (FOLDER_DEBUG_XML == TRUE) - UINT8 dbg_name[FOLDER_DEBUG_LEN]; -#endif - - if (curr < XML_FOLDER_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_flp_ptbl[curr]; p_stag && *p_stag; p_stag++) - { - if (*p_stag >= XML_FOLDER_TTBL_SIZE) - continue; - if(p_name->len == xml_flp_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_flp_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_flp_proc_attr: bad name:%s", dbg_name); -#endif - return XML_XP_UNKNOWN_ID; -} -/***************************************************************************** - ** Function xml_flp_get_perm - ** Description Translate permission character into XML_PERM_MASK - ** Returns XML_PERM_MASK: permission mask - *****************************************************************************/ -static XML_PERM_MASK xml_flp_get_perm(char *right, UINT16 len ) -{ - XML_PERM_MASK mask = 0; - UINT8 perm_str[XML_PERM_LEN_MAX] = {0}; - - memcpy(perm_str, right, XML_PERM_LEN_MAX); - perm_str[len] = '\0'; - - if (strchr((char *)perm_str, 'R')) - mask |= XML_PERM_READ_B; - if (strchr((char *)perm_str, 'W')) - mask |= XML_PERM_WRITE_B; - if (strchr((char *)perm_str, 'D')) - mask |= XML_PERM_DELETE_B; - -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("xml_flp_get_perm [%s] -> %d",perm_str, mask); -#endif - return mask; -} - -/***************************************************************************** - ** Function xml_flp_find_ch_n_copy - ** Description copy any chacter till one char in p_str. Any char in p_str - ** will stop copy pointed by p_begin - ** Parameters - ** Returns - *****************************************************************************/ -static void xml_flp_find_ch_n_copy( tXML_MCOPY *p_copy ) -{ - const UINT8 *p_tmp; - const UINT8 *p_str = (UINT8 *)">"; /* was: ":=/> \t\n\r". i think we should copy till - closing flag */ - unsigned int last = XML_FOLDER_CARRY_OVER_LEN; /* maximum carry over len we can support */ - UINT8 *p_last = p_copy->last.p + p_copy->last.len - 1; /* point to the last char of carry - over buffer */ - BOOLEAN found = FALSE; - - /* check if the last char in p_last is in p_str */ - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_last == *p_tmp) - { - found = TRUE; - break; - } - } /* for */ - - if (found == FALSE) - { - /* if not in p_str, move chars from p_begin to p_last - * until reached last_len or any char in p_str */ - p_last++; - last -= p_copy->last.len; /* calculate the maximum number of chars we can copy */ - while (*(p_copy->p_begin) && last) /* rl: not sure that this buffer is termninated by a 0 */ - { - /* copy from source (new buffer) to carry over. adjust only carry over ptr. */ - *p_last++ = *p_copy->p_begin; - last--; - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_copy->p_begin == *p_tmp) - { - p_copy->p_begin++; /* adjust pointer to point to next char to read */ - /* calculate new length of carry over buffer contents */ - p_copy->last.len = XML_FOLDER_CARRY_OVER_LEN-last; - *p_last = 0; /* NULL terminate p_last. rl: not really neccessary. */ - return; - } - } /* for */ - p_copy->p_begin++; /* update now to next char. this way abort char is also copied */ - } /* while */ - } /* !found */ -} - -/***************************************************************************** -** Function xml_folder_cback -** Description -** -** Parameters -** Returns -*****************************************************************************/ -static BOOLEAN xml_folder_cback( tXML_EVENT event, void *p_event_data, void *p_usr_data) -{ - tXML_MEVT_DATA *p_ed = (tXML_MEVT_DATA*) p_event_data; - tXML_FOLDER_STATE *p_st = (tXML_FOLDER_STATE *) p_usr_data; - tXML_PROP *p_cp = &p_st->p_prop[p_st->prop_index]; - BOOLEAN ret = TRUE; - UINT8 next; /* next element */ - UINT8 curr = p_ed->stack.stack[p_ed->stack.top]; /* current element */ -#if (FOLDER_DEBUG_XML == TRUE) - UINT8 dbg_name[FOLDER_DEBUG_LEN]; - UINT8 dbg_prefix[FOLDER_DEBUG_LEN]; - UINT8 dbg_value[FOLDER_DEBUG_LEN]; -#endif - -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("xml_folder_cback:%d", event); -#endif - - switch (event) - { - case XML_TAG : /* <tag-name */ - next = xml_flp_proc_tag(p_st, &p_ed->tag.name, &p_ed->stack); -#if (FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(&p_ed->tag.name, dbg_name); - xml_flp_debug_str(&p_ed->tag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("XML_TAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - -#endif - if (next != 0) - { - if (next <= XML_MAX_OBJ_TAG_ID) - p_st->obj = next; - - if(p_st->prop_index <p_st->max_num_prop) - { - /* we do not use prefix in FTC */ - p_cp->name = next; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - } - break; - - case XML_ATTRIBUTE : /* attr-name="attr-value" */ - curr = xml_flp_proc_attr(p_st, &p_ed->attr.name, &p_ed->stack); -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(&p_ed->attr.name, dbg_name); - xml_flp_debug_str(&p_ed->attr.prefix, dbg_prefix); - xml_flp_debug_str(&p_ed->attr.value, dbg_value); - XML_TRACE_DEBUG4("[xml folder] XML_ATTRIBUTE: p:%s, name:%s, v:%s, curr:%x", - dbg_prefix, dbg_name, dbg_value, curr); -#endif - if ((curr != 0) && (curr != XML_XP_UNKNOWN_ID)) - { - if(p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = curr; - p_cp->p_data = p_ed->attr.value.p; - p_cp->len = p_ed->attr.value.len; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - p_ed->stack.top--; - } - break; - - case XML_CHARDATA : -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(&p_ed->ch_data.value, dbg_value); - XML_TRACE_DEBUG2("XML_CHARDATA: v:%s, last:%d", dbg_value, p_ed->ch_data.last); -#endif - break; - - case XML_ETAG : /* </tag-name> */ - if(p_ed->stack.top > 0) - { - p_ed->stack.stack[p_ed->stack.top] = 0; - p_ed->stack.top--; - p_st->ended = (BOOLEAN) (p_ed->stack.top == 0); - } -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(&p_ed->etag.name, dbg_name); - xml_flp_debug_str(&p_ed->etag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("[xml folder] XML_ETAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("[xml folder] top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - break; - - case XML_TAG_END: /* /> */ - curr = p_ed->stack.stack[p_ed->stack.top]; - - if(p_st->prop_index <p_st->max_num_prop) - { - if(p_ed->empty_elem.end) - p_cp->name = XML_FOLDER_TAG_END_ID; - else - p_cp->name = XML_FOLDER_PAUSE_ID; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - if(p_ed->empty_elem.end && p_ed->stack.top > 0) - { - p_ed->stack.top--; - } - } - else - ret = FALSE; - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4("[xml folder] XML_TAG_END: %d, top:x%x, stk:x%x, curr:x%x", - p_ed->empty_elem.end, p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top], curr); -#endif - break; - - case XML_PARTIAL: - if(p_st->p_prop[p_st->prop_index-1].name != XML_FOLDER_TAG_END_ID) - { - p_ed->stack.top--; -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("[xml folder] adjust due to XML_PARTIAL"); -#endif - } - break; - - case XML_COPY: - xml_flp_find_ch_n_copy( &p_ed->copy ); - XML_TRACE_DEBUG1("[xml folder] XML_COPY: %s", p_ed->copy.last.p); - break; - - default : -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("[xml folder] XML event: %d", event); -#endif - break; - } - - return ret; -} - -/********************************************************************************** -** Function xml_flp_int_fill_file_folder -** Description fill in file/folder structure. -** -** Parameters -** Returns xx: > 0 : number of properties scanned, folder entry is added -** = 0 : no end tag found, carry over to next parse -** = -1: no dst_resource avaibale, all prop left to next parse -** = -2: exceed max entry, no folder entry added -**********************************************************************************/ -static INT16 xml_flp_int_fill_file_folder( const UINT8 type, - tXML_FOLDER_STATE * p_xud, - tXML_PROP *p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - INT16 xx; - UINT16 len; - BOOLEAN end = FALSE; - tXML_PROP *cur_prop = p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - for(xx=0; (xx < *num_prop) && !end; xx++, cur_prop++) - { -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG5( "[xml folder] fill: num_prop:%d, name id: x%x, p_prop: x%x, p_data:%s, len: %d", - (*num_prop-xx) , cur_prop->name, cur_prop, cur_prop->p_data, cur_prop->len); -#endif - switch (cur_prop->name) - { - case XML_NAME_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - /* as long as we do not exceed the number of entries in the ouput array copy name */ - p_xud->p_entry[p_xud->current_entry].type = type; - /* calculate the max length to copy */ - len = (cur_prop->len<=p_xud->max_name_len) ? cur_prop->len:p_xud->max_name_len; - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_xud->p_entry[p_xud->current_entry].data = p_cur_offset; - p_xud->p_entry[p_xud->current_entry].len = len; - - memcpy( (void *)p_xud->p_entry[p_xud->current_entry].data, - (const void *)cur_prop->p_data, - len ); - p_xud->p_entry[p_xud->current_entry].data[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG3("[xml folder]: catch filename [%s] len [%d] dst_len left:[%d]", - p_xud->p_entry[p_xud->current_entry].data, - len, - *dst_len); -#endif - } - else /* run out of dst buffer resource */ - { - xx = -1; - return xx; - } - } - else /* exceed max entry */ - return -2; - - break; - - case XML_SIZE_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - p_xud->p_entry[p_xud->current_entry].size = atol( (const char *)cur_prop->p_data ); - } - break; - - case XML_USER_PERM_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - p_xud->p_entry[p_xud->current_entry].user_perm = xml_flp_get_perm( (char *)cur_prop->p_data, cur_prop->len); - } - break; - case XML_TYPE_ATTR_ID: - case XML_MODIFIED_ATTR_ID: - case XML_CREATED_ATTR_ID: - case XML_ACCESSED_ATTR_ID: - case XML_GROUP_PERM_ATTR_ID: - case XML_OTHER_PERM_ATTR_ID: - case XML_GROUP_ATTR_ID: - case XML_OWNER_ATTR_ID: - case XML_LANG_ATTR_ID: - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1( "[xml folder] ignored attr: 0x%x", cur_prop->name ); -#endif - break; - - case XML_FOLDER_TAG_END_ID: - /* -------------------- CUSTOMER SPECIFIC ---------------------- */ - p_xud->current_entry++; /* increment only when end tag (/>) found */ - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1( "[xml folder] FOUND END TAG: 0x%x", cur_prop->name ); -#endif - - end = TRUE; - break; - - default: - XML_TRACE_DEBUG1("[xml folder] unknown attrib: %d", cur_prop->name ); - break; - } - } -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("[xml folder] fill_file_folder: end:%d, xx:%d", end, xx); -#endif -#if 0 - /* if end tag not found -> split over two buffers. but parser will still show rest of - found properties. so return still found properties. */ - if(end == FALSE) - xx = 0; -#endif - - /* keep track of current data buffer offset */ - *p_dst_data = p_cur_offset; - return xx; -} /* xml_flp_int_fill_file_folder() */ - - -/********************************************************************************** -** Function xml_flp_int_fill_evt_data -** -** Description fill in file/folder structure. -** -** Parameters -** Returns -**********************************************************************************/ -static tXML_FOLDER_RES xml_flp_int_fill_evt_data( UINT8 op, - void *p_evt_data, - tXML_PROP **p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - tXML_FOLDER_STATE *p_xud = (tXML_FOLDER_STATE *)p_evt_data; - INT16 inc_prop; - UINT8 prop_name; /* Property name. */ - UINT8 entry_type; - tXML_PROP *cur_prop = *p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - tXML_FOLDER_RES x_res = XML_FOLDER_OK; - BOOLEAN x_no_res = FALSE; /* guard dest buffer resource */ - - - if ( op == 0 || op > XML_MAX_OBJ_TAG_ID || *num_prop == 0) - return XML_FOLDER_ERROR; - -#if FOLDER_DEBUG_XML - XML_TRACE_DEBUG2( "[xml folder] xml_flp_int_fill_evt_data op:%d, num_prop:%d", - op, *num_prop); -#endif - - - - while ( *num_prop > 0 && !x_no_res ) - { -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("end_prop:%d, name id: x%x", *num_prop, cur_prop->name); -#endif - prop_name = cur_prop->name; - cur_prop++; - *num_prop -= 1; - - - switch( prop_name ) - { - case XML_FOLDER_LISTING_ELEM_ID: - /* skip over version attribute which should always be 1.0. this is the top level */ - break; - - case XML_FILE_ELEM_ID: - case XML_FOLDER_ELEM_ID: - /* folder or file: only type is the difference */ - entry_type = (XML_FILE_ELEM_ID==prop_name)?XML_OBX_FILE:XML_OBX_FOLDER; - inc_prop = xml_flp_int_fill_file_folder( entry_type, - p_xud, - cur_prop, - num_prop, - &p_cur_offset, - dst_len); - if (inc_prop == -1) /* no dst_buf available */ - { - /* backup one more prop to obtain the skipped folder/file entry header */ - cur_prop --; - *num_prop += 1; - - x_res = XML_FOLDER_DST_NO_RES; - x_no_res = TRUE; - } - else if (inc_prop == -2) /* exceed max entry */ - { - x_no_res = TRUE; - x_res = XML_FOLDER_OUT_FULL; - } - else /* found folder entry */ - { - cur_prop += inc_prop; - *num_prop -= inc_prop; - } - break; - - case XML_PARENT_FOLDER_ELEM_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - /* set type of entry (file, folder) */ - p_xud->p_entry[p_xud->current_entry].type = XML_OBX_FOLDER; - /* copy folder name if dst buffer is big enough, parent folder as ".." */ - if ((*dst_len - strlen(XML_PARENT_FOLDER)) > 0) - { - p_xud->p_entry[p_xud->current_entry].data = p_cur_offset; - p_xud->p_entry[p_xud->current_entry].len = 2; - memcpy( (void *)p_xud->p_entry[p_xud->current_entry].data, - (const void *)XML_PARENT_FOLDER, 2); - p_xud->p_entry[p_xud->current_entry].data[2] = '\0'; /* null terminate */ - p_xud->current_entry ++; - p_cur_offset += 3 ; - *dst_len -= 3; - } - else - { - x_no_res = TRUE; - x_res = XML_FOLDER_DST_NO_RES; - } - } - else - { - x_no_res = TRUE; - x_res = XML_FOLDER_OUT_FULL; - } - break; - - case XML_FOLDER_PAUSE_ID: - -#if (FOLDER_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml folder] xml_flp_int_fill_evt_data(): XML_FOLDER_PAUSE_ID" ); -#endif - break; - - case XML_FOLDER_TAG_END_ID: -#if (FOLDER_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml folder] xml_flp_int_fill_evt_data(): XML_FOLDER_TAG_END_ID" ); -#endif - break; - - default: - XML_TRACE_DEBUG1( "[xml folder] xml_flp_int_fill_evt_data():unknown element: %d", prop_name ); - break; - } - } - - /* keep track of current filling position, and current available dst buffer */ - *p_prop = cur_prop; - *p_dst_data = p_cur_offset; - - return x_res; -} /* xml_flp_int_fill_evt_data() */ - - -/************************************************************************************** -** Function XML_FolderInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of an xml parser state machine to be initialized, -** allocate an additional space of size XML_FOLDER_CARRY_OVER_LEN -** right after *p_xml_state to hold carry over data. -** p_entry : points start of output directory entry. caller needs do -** free this memory -** max_entry : max is 16 bit integer value which is the maximum number -** of folder entries. - -** -** Returns void -**************************************************************************************/ - -void XML_FolderInit( tXML_FOLDER_PARSER *p_xml_state, - tXML_FOLDER_ENTRY *p_entry, - const UINT16 max_entry ) -{ - /* Initialize the generic xml parser state machine.*/ - XML_InitPars( &p_xml_state->xml, xml_folder_cback, &p_xml_state->xml_user_data ); - - /* User need to allocate an additional space of size XML_FOLDER_CARRY_OVER_LEN */ - /* right after *p_xml_state to hold carry over data. */ - /* point to the end of the allocated buffer for p_xml_state, which is the */ - /* beginning of buffer(XML_FOLDER_CARRY_OVER_LEN) */ - p_xml_state->xml.last_bfr.p = (UINT8 *)(p_xml_state + 1); - p_xml_state->xml.last_bfr.len = XML_FOLDER_CARRY_OVER_LEN; - - /* Initialize user data */ - p_xml_state->xml_user_data.p_entry = p_entry; - p_xml_state->xml_user_data.current_entry = 0; - p_xml_state->xml_user_data.max_name_len = XML_UI_ENTRY_MAX_NAME_LEN + 1; - p_xml_state->xml_user_data.max_entry = (UINT16)max_entry; - p_xml_state->xml_user_data.prop_num = 0; -} - - -/************************************************************************************** -** Function XML_FolderParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_FolderInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. - When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: pointer to the length of dst_data buffer, its carry out value -** is the number of bytes remaining buffer.When dst_len is NULL, -** it will cause to flush the internal data in the parser. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_FOLDER_RES (see xml_flp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_FOLDER_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_FOLDER_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -tXML_FOLDER_RES XML_FolderParse( tXML_FOLDER_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ) -{ - tXML_OS xos; - BOOLEAN is_remain = TRUE; - tXML_MUL_STATE *p_xml = &p_xml_state->xml; - tXML_FOLDER_STATE *p_st = &p_xml_state->xml_user_data; - tXML_FOLDER_RES x_res = XML_FOLDER_OK; - tXML_RESULT res = XML_NO_PROP; - UINT16 max_num_prop = OBX_LRG_DATA_POOL_SIZE/sizeof(tXML_PROP); /* Changed to use the reserved buffer pool */ - - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - int xx; - UINT8 dbg_buf[FOLDER_DEBUG_LEN]; - tXML_STR str; -#endif - - /* if dst_data is NULL, clean up remaining data */ - if (!dst_data || !dst_len) - { - /* clean out remained xml data left over from last parse */ - if (p_xml_state->xml_user_data.p_prop ) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = p_st->offset_prop = NULL; - p_st->prop_num = 0; - } -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml folder] XML_FolderParse() Clean up left over!"); -#endif - return x_res; - } - - /* if illegal OBEX data or dst buffer pointer received, return ERROR */ - if (xml_len == 0 || !xml_data) - { - return XML_FOLDER_ERROR; - } - - /* XML_FolderParse receive new xml data, allocate buffer to hold parsed prop */ - if (p_st->offset_prop == NULL) - { - -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml folder] XML_FolderParse() Receive New Data!"); - XML_TRACE_DEBUG2( "[xml folder] XML_data start[%x] end [%x]",xml_data, xml_data+xml_len); -#endif - is_remain = FALSE; - if ( NULL!= (p_st->p_prop = (tXML_PROP *)GKI_getpoolbuf( OBX_LRG_DATA_POOL_ID ) ) ) - { - /* pointing next prop to be converted into file entry */ - p_st->prop_num = 0; - } - else - { - GKI_freebuf( p_xml_state ); - x_res = XML_FOLDER_NO_RES; - return x_res; - } - } -#if (FOLDER_DEBUG_XML == TRUE) - else - { - XML_TRACE_DEBUG0( "[xml folder] XML_FolderParse(): Keep cleaning up old xml data !"); - } -#endif - /* update the data address */ - xos.p_begin = xml_data; - xos.p_end = xml_data + xml_len; - - while( res == XML_NO_PROP ) - { - /* if no remaining data in p_st->p_prop, parse new xml data */ - if (!is_remain) - { - p_st->max_num_prop = max_num_prop; - p_st->prop_index = 0; - res = XML_MulParse( p_xml, &xos ); - - -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4( "xml_folder_parse obj: %x, max: %d, num: %d, res: %d", - p_st->obj, max_num_prop, p_st->prop_index, res); - - if (res != 0) - { - XML_TRACE_DEBUG1( "XML_MulParse Parsing: %d !!!", res); - } - - for(xx=0; xx<p_st->prop_index; xx++) - { - if ( p_st->p_prop[xx].name < XML_FOLDER_MAX_ID ) - { - str.p = p_st->p_prop[xx].p_data; - str.len = p_st->p_prop[xx].len; - xml_flp_debug_str(&str, dbg_buf); - XML_TRACE_DEBUG5( "[xml folder] parsed: index[%d]:%d:%s: %s(%d)", p_st->prop_index-xx, p_st->p_prop[xx].level, - xml_flp_ttbl[p_st->p_prop[xx].name].p_name, dbg_buf, p_st->p_prop[xx].len); - } - else - { - XML_TRACE_DEBUG3( "[xml folder] internal prop: %d:%d:%d", xx, p_st->p_prop[xx].level, - p_st->p_prop[xx].name ); - } - } -#endif - p_st->prop_num = p_st->prop_index ; - p_st->offset_prop = p_st->p_prop; - } - else - { - /* This is left over data, pick up the result from the previous parse */ - res = p_xml->pars_res; - } - - if ( res != XML_OBJ_ST_EMPTY ) - { - x_res = xml_flp_int_fill_evt_data( p_st->obj, p_st, &p_st->offset_prop, &p_st->prop_num, &dst_data, dst_len ); - - if ( (XML_FOLDER_OK == x_res) && (XML_NO_END == res) ) - { - /* XML_NO_END means that the xml is not completly finished and fill returns - ok when when partial filling has been ok */ - x_res = XML_FOLDER_PENDING; - } - - /* all parsed xml data has been converted into file entry */ - /* or exceed max entry number , break the parsing loop */ - if (XML_FOLDER_OUT_FULL != x_res && XML_FOLDER_DST_NO_RES != x_res) - { - is_remain = FALSE; - } - else - break; - } - } /* while */ - - /* free property table. at next call a new one is allocated */ - if ((x_res != XML_FOLDER_DST_NO_RES && p_st->p_prop) || - XML_FOLDER_OUT_FULL == x_res) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = NULL; - p_st->offset_prop = NULL; - } - - if ( x_res != XML_FOLDER_DST_NO_RES && p_st->ended) - { - /* this should happen on the same time as final flag in fact */ - x_res = XML_FOLDER_END_LIST; /* found closing /folder-listing */ - } - - - *num_entries = p_st->current_entry; /* report number of entries found. only when ended is true - application really should be interested! */ - return x_res; -} - diff --git a/stack/xml/xml_mlp.c b/stack/xml/xml_mlp.c deleted file mode 100644 index aca0cb5..0000000 --- a/stack/xml/xml_mlp.c +++ /dev/null @@ -1,1060 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_mlp.c - ** - ** Description: This module contains xml parser of MAP message list object - ** - ** Copyright (c) 2004-2011, Broadcom Corporation, All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#include "bt_target.h" -#include "gki.h" -#include "xml_mlp_api.h" - -#include <string.h> -#include <stdlib.h> - -#ifndef ML_DEBUG_XML -#define ML_DEBUG_XML TRUE -#endif -#define ML_DEBUG_LEN 50 -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - -#define XML_PERM_LEN_MAX 4 - -/***************************************************************************** -** Constants -*****************************************************************************/ -const UINT8 xml_ml_elem[] = "MAP-msg-listing"; -const UINT8 xml_ml_msg_elem[] = "msg"; -const UINT8 xml_ml_handle_attr[] = "handle"; -const UINT8 xml_ml_subject_attr[] = "subject"; -const UINT8 xml_ml_datetime_attr[] = "datetime"; -const UINT8 xml_ml_sender_name_attr[] = "sender_name"; -const UINT8 xml_ml_sender_addressing_attr[] = "sender_addressing"; -const UINT8 xml_ml_replyto_addressing_attr[] = "replyto_addressing"; -const UINT8 xml_ml_recipient_name_attr[] = "recipient_name"; -const UINT8 xml_ml_recipient_addressing_attr[] = "recipient_addressing"; -const UINT8 xml_ml_type_attr[] = "type"; -const UINT8 xml_ml_size_attr[] = "size"; -const UINT8 xml_ml_text_attr[] = "text"; -const UINT8 xml_ml_reception_status_attr[] = "reception_status"; -const UINT8 xml_ml_attachment_size_attr[] = "attachment_size"; -const UINT8 xml_ml_priority_attr[] = "priority"; -const UINT8 xml_ml_read_attr[] = "read"; -const UINT8 xml_ml_sent_attr[] = "sent"; -const UINT8 xml_ml_protected_attr[] = "protected"; -const UINT8 xml_ml_version_attr[] = "version"; -const UINT8 xml_ml_unknown[] = "unknown"; - -#define XML_ML_ELEM_ID 0x01 -#define XML_ML_MSG_ELEM_ID 0x02 -#define XML_ML_MAX_OBJ_TAG_ID XML_ML_ELEM_ID -#define XML_ML_HANDLE_ATTR_ID 0x03 -#define XML_ML_SUBJECT_ATTR_ID 0x04 -#define XML_ML_DATETIME_ATTR_ID 0x05 -#define XML_ML_SENDER_NAME_ATTR_ID 0x06 -#define XML_ML_SENDER_ADDRESSING_ATTR_ID 0x07 -#define XML_ML_REPLYTO_ADDRESSING_ATTR_ID 0x08 -#define XML_ML_RECIPIENT_NAME_ATTR_ID 0x09 -#define XML_ML_RECIPIENT_ADDRESSING_ATTR_ID 0x0a -#define XML_ML_TYPE_ATTR_ID 0x0b -#define XML_ML_SIZE_ATTR_ID 0x0c -#define XML_ML_TEXT_ATTR_ID 0x0d -#define XML_ML_RECEPTION_STATUS_ATTR_ID 0x0e -#define XML_ML_ATTACHMENT_SIZE_ATTR_ID 0x0f -#define XML_ML_PRIORITY_ATTR_ID 0x10 -#define XML_ML_READ_ATTR_ID 0x11 -#define XML_ML_SENT_ATTR_ID 0x12 -#define XML_ML_PROTECTED_ATTR_ID 0x13 -#define XML_ML_VERSION_ATTR_ID 0x14 -#define XML_ML_UNKNOWN_ID 0x15 -#define XML_ML_MAX_ID 0x16 /* keep in sync with above */ -#define XML_ML_TAG_END_ID 0x17 /* closing tag found end=true */ -#define XML_ML_PAUSE_ID 0x18 /* closing tag found end=false */ - -#define XML_ML_TTBL_SIZE (XML_ML_MAX_ID+1) - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -typedef struct -{ - const UINT8 *p_name; - UINT8 len; -} tXML_ML_TTBL_ELEM; - -typedef tXML_ML_TTBL_ELEM tXML_ML_TTBL[]; /* Tag Table */ - - -static const tXML_ML_TTBL_ELEM xml_ml_ttbl[XML_ML_TTBL_SIZE] = -{ /* index (ML_XP_*_ID) & name */ - {(UINT8*) "", XML_ML_MAX_ID-1}, /* \x00 Number of elements in array */ - /* XML EVT_RPT element (TAG) name */ - {xml_ml_elem, 15}, /* x01 MAP-msg-listing */ - {xml_ml_msg_elem, 3}, /* x02 msg */ - {xml_ml_handle_attr, 6}, /* x03 handle */ - {xml_ml_subject_attr, 7}, /* x04 subject */ - {xml_ml_datetime_attr, 8}, /* x05 datetime */ - {xml_ml_sender_name_attr, 11}, /* x06 sender_name */ - {xml_ml_sender_addressing_attr, 17}, /* x07 sender_addressing */ - {xml_ml_replyto_addressing_attr, 18}, /* x08 replyto_addressing */ - {xml_ml_recipient_name_attr, 14}, /* x09 recipient_name */ - {xml_ml_recipient_addressing_attr, 20}, /* x0a recipient_addressing */ - {xml_ml_type_attr, 4}, /* x0b type */ - {xml_ml_size_attr, 4}, /* x0c size */ - {xml_ml_text_attr, 4}, /* x0d text */ - {xml_ml_reception_status_attr, 16}, /* x0e reception_status */ - {xml_ml_attachment_size_attr, 15}, /* x0f attachment_size */ - {xml_ml_priority_attr, 8}, /* x10 priority */ - {xml_ml_read_attr, 4}, /* x11 read */ - {xml_ml_sent_attr, 4}, /* x12 sent */ - {xml_ml_protected_attr, 9}, /* x13 protected */ - {xml_ml_version_attr, 7}, /* x14 version */ - {xml_ml_unknown, 7} /* x15 unknown */ -}; - -#define XML_MAP_ML_PTBL_SIZE 0x03 -typedef UINT8 * tXML_MAP_ML_PTBL_ELEM; - -static const tXML_MAP_ML_PTBL_ELEM xml_ml_ptbl[XML_MAP_ML_PTBL_SIZE] = -{ - (UINT8 *) "\x01", /* index x00, all valide attributes in above list */ - (UINT8 *) "\x14\x02", /* x01 attributes and sub-tags supported */ - (UINT8 *) "\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13" -}; - - -#if (ML_DEBUG_XML == TRUE) -void xml_ml_debug_str(tXML_STR *p_str, UINT8 *p_buf) -{ - int dbg_len; - if ( (p_str == NULL) || (NULL==p_str->p)) - BCM_STRNCPY_S( (char *)p_buf, ML_DEBUG_LEN, "(NULL)", ML_DEBUG_LEN-1); - else - { - dbg_len = p_str->len; - if ( dbg_len >= ML_DEBUG_LEN) - dbg_len = ML_DEBUG_LEN - 1; - BCM_STRNCPY_S( (char *)p_buf, ML_DEBUG_LEN, (char *)p_str->p, dbg_len); - p_buf[dbg_len] = 0; - } -} - -#else -#define xml_ml_debug_str(p_str, p_buf) -#endif - -/***************************************************************************** - ** Function xml_ml_proc_tag - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_ml_proc_tag( tXML_ML_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - UINT8 dbg_name[ML_DEBUG_LEN]; -#endif - - - if (curr < XML_MAP_ML_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_ml_ptbl[curr]; p_stag && *p_stag ; p_stag++) - { - if (*p_stag >= XML_ML_TTBL_SIZE) - continue; - if (p_name->len == xml_ml_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_ml_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_ml_proc_tag: bad name:%s", dbg_name ); -#endif - - return XML_ML_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_ml_proc_attr - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_ml_proc_attr(tXML_ML_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (ML_DEBUG_XML == TRUE) - UINT8 dbg_name[ML_DEBUG_LEN]; -#endif - if (curr < XML_MAP_ML_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_ml_ptbl[curr]; p_stag && *p_stag; p_stag++) - { - if (*p_stag >= XML_ML_TTBL_SIZE) - continue; - if (p_name->len == xml_ml_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_ml_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_ml_proc_attr: bad name:%s", dbg_name); -#endif - return XML_ML_UNKNOWN_ID; -} - -/***************************************************************************** - ** Function xml_ml_find_ch_n_copy - ** Description copy any chacter till one char in p_str. Any char in p_str - ** will stop copy pointed by p_begin - ** Parameters - ** Returns - *****************************************************************************/ -static void xml_ml_find_ch_n_copy( tXML_MCOPY *p_copy ) -{ - const UINT8 *p_tmp; - const UINT8 *p_str = (UINT8 *)">"; /* was: ":=/> \t\n\r". i think we should copy till - closing flag */ - unsigned int last = XML_ML_CARRY_OVER_LEN; /* maximum carry over len we can support */ - UINT8 *p_last = p_copy->last.p + p_copy->last.len - 1; /* point to the last char of carry - over buffer */ - BOOLEAN found = FALSE; - /* check if the last char in p_last is in p_str */ - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_last == *p_tmp) - { - found = TRUE; - break; - } - } /* for */ - - if (found == FALSE) - { - /* if not in p_str, move chars from p_begin to p_last - * until reached last_len or any char in p_str */ - p_last++; - last -= p_copy->last.len; /* calculate the maximum number of chars we can copy */ - while (*(p_copy->p_begin) && last) /* rl: not sure that this buffer is termninated by a 0 */ - { - /* copy from source (new buffer) to carry over. adjust only carry over ptr. */ - *p_last++ = *p_copy->p_begin; - last--; - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_copy->p_begin == *p_tmp) - { - p_copy->p_begin++; /* adjust pointer to point to next char to read */ - /* calculate new length of carry over buffer contents */ - p_copy->last.len = XML_ML_CARRY_OVER_LEN-last; - *p_last = 0; /* NULL terminate p_last. rl: not really neccessary. */ - return; - } - } /* for */ - p_copy->p_begin++; /* update now to next char. this way abort char is also copied */ - } /* while */ - } /* !found */ -} - -/***************************************************************************** -** Function xml_ml_cback -** Description -** -** Parameters -** Returns -*****************************************************************************/ -static BOOLEAN xml_ml_cback( tXML_EVENT event, void *p_event_data, void *p_usr_data) -{ - tXML_MEVT_DATA *p_ed = (tXML_MEVT_DATA*) p_event_data; - tXML_ML_STATE *p_st = (tXML_ML_STATE *) p_usr_data; - tXML_PROP *p_cp = &p_st->p_prop[p_st->prop_index]; - BOOLEAN ret = TRUE; - UINT8 next; /* next element */ - UINT8 curr = p_ed->stack.stack[p_ed->stack.top]; /* current element */ -#if (ML_DEBUG_XML == TRUE) - UINT8 dbg_name[ML_DEBUG_LEN]; - UINT8 dbg_prefix[ML_DEBUG_LEN]; - UINT8 dbg_value[ML_DEBUG_LEN]; -#endif - -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("xml_ml_cback:%d", event); -#endif - - switch (event) - { - case XML_TAG : /* <tag-name */ - next = xml_ml_proc_tag(p_st, &p_ed->tag.name, &p_ed->stack); -#if (ML_DEBUG_XML == TRUE) - xml_ml_debug_str(&p_ed->tag.name, dbg_name); - xml_ml_debug_str(&p_ed->tag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("XML_TAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - -#endif - if (next != 0) - { - if (next <= XML_ML_MAX_OBJ_TAG_ID) - p_st->obj = next; - - if (p_st->prop_index <p_st->max_num_prop) - { - /* we do not use prefix in FTC */ - p_cp->name = next; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - } - break; - - case XML_ATTRIBUTE : /* attr-name="attr-value" */ - curr = xml_ml_proc_attr(p_st, &p_ed->attr.name, &p_ed->stack); -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(&p_ed->attr.name, dbg_name); - xml_ml_debug_str(&p_ed->attr.prefix, dbg_prefix); - xml_ml_debug_str(&p_ed->attr.value, dbg_value); - XML_TRACE_DEBUG4("[xml ml] XML_ATTRIBUTE: p:%s, name:%s, v:%s, curr:%x", - dbg_prefix, dbg_name, dbg_value, curr ); - XML_TRACE_DEBUG2("top 1:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - if ((curr != 0) && (curr != XML_ML_UNKNOWN_ID)) - { - if (p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = curr; - p_cp->p_data = p_ed->attr.value.p; - p_cp->len = p_ed->attr.value.len; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - p_ed->stack.top--; - XML_TRACE_DEBUG2("top 2:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - } - break; - - case XML_CHARDATA : -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(&p_ed->ch_data.value, dbg_value); - XML_TRACE_DEBUG2("XML_CHARDATA: v:%s, last:%d", dbg_value, p_ed->ch_data.last); -#endif - break; - - case XML_ETAG : /* </tag-name> */ - if (p_ed->stack.top > 0) - { - p_ed->stack.stack[p_ed->stack.top] = 0; - p_ed->stack.top--; - p_st->ended = (BOOLEAN) (p_ed->stack.top == 0); - } -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(&p_ed->etag.name, dbg_name); - xml_ml_debug_str(&p_ed->etag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("[xml ml] XML_ETAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("[xml ml] top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - break; - - case XML_TAG_END: /* /> */ - curr = p_ed->stack.stack[p_ed->stack.top]; - - if (p_st->prop_index <p_st->max_num_prop) - { - if (p_ed->empty_elem.end) - p_cp->name = XML_ML_TAG_END_ID; - else - p_cp->name = XML_ML_PAUSE_ID; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - if (p_ed->empty_elem.end && p_ed->stack.top > 0) - { - p_ed->stack.top--; - } - } - else - ret = FALSE; - -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4("[xml ml] XML_TAG_END: %d, top:x%x, stk:x%x, curr:x%x", - p_ed->empty_elem.end, p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top], curr); -#endif - break; - - case XML_PARTIAL: - if (p_st->p_prop[p_st->prop_index-1].name != XML_ML_TAG_END_ID) - { - p_ed->stack.top--; -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("[xml ml] adjust due to XML_PARTIAL"); -#endif - } - break; - - case XML_COPY: - xml_ml_find_ch_n_copy( &p_ed->copy ); - XML_TRACE_DEBUG1("[xml ml] XML_COPY: %s", p_ed->copy.last.p); - break; - - default : -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("[xml ml] default: XML event: %d", event); -#endif - break; - } - - return ret; -} - - - - -/********************************************************************************** -** Function xml_ml_int_fill_msg_list -** Description fill in file/folder structure. -** -** Parameters -** Returns xx: > 0 : number of properties scanned, folder entry is added -** = 0 : no end tag found, carry over to next parse -** = -1: no dst_resource avaibale, all prop left to next parse -** = -2: exceed max entry, no folder entry added -**********************************************************************************/ -static INT16 xml_ml_int_fill_msg_list( tXML_ML_STATE * p_xud, - tXML_PROP *p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - INT16 xx; - UINT16 len; - BOOLEAN end = FALSE; - tXML_PROP *cur_prop = p_prop; - UINT8 *p_cur_offset = *p_dst_data; - BOOLEAN copy_attr_info; - BOOLEAN no_buf_left; - UINT8 **p_attr_data = NULL; - UINT16 *p_attr_len = NULL; - - if ( p_xud->current_entry >= p_xud->max_entry ) - return -2; - - for (xx=0; (xx < *num_prop) && !end; xx++, cur_prop++) - { -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - /* XML_TRACE_DEBUG5( "[xml ml] fill: num_prop:%d, name id: x%x, p_prop: x%x, len: %d p_data:%s", - (*num_prop-xx) , cur_prop->name, cur_prop, cur_prop->len, cur_prop->p_data, ); */ -#endif - copy_attr_info = TRUE; - no_buf_left = FALSE; - len = cur_prop->len; - - switch (cur_prop->name) - { - case XML_ML_HANDLE_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].msg_handle) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].msg_handle_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - - case XML_ML_SUBJECT_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].subject) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].subject_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_DATETIME_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].datetime) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].datetime_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_SENDER_NAME_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].sender_name) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].sender_name_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_SENDER_ADDRESSING_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].sender_addressing) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].sender_addressing_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_REPLYTO_ADDRESSING_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].replyto_addressing) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].replyto_addressing_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_RECIPIENT_NAME_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].recipient_name) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].recipient_name_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_RECIPIENT_ADDRESSING_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].recipient_addressing) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].recipient_addressing_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_TYPE_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].type) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].type_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - - case XML_ML_SIZE_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].org_msg_size) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].org_msg_size_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_TEXT_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].text) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].text_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_RECEPTION_STATUS_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].reception_status) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].reception_status_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_ATTACHMENT_SIZE_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].attachment_size) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].attachment_size_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_PRIORITY_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].priority_status) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].priority_status_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_READ_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].read) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].read_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_SENT_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].sent) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].sent_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_PROTECTED_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].is_protected) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].is_protected_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - - case XML_ML_TAG_END_ID: - /* -------------------- CUSTOMER SPECIFIC ---------------------- */ - p_xud->current_entry++; /* increment only when end tag (/>) found */ - copy_attr_info = FALSE; - XML_TRACE_DEBUG1("[xml ml]: current_entry cnt=%d",p_xud->current_entry); - break; - /* case XML_VERSION_ATTR_ID: */ - default: - copy_attr_info = FALSE; - XML_TRACE_DEBUG1("[xml ml] unknown attrib: %d", cur_prop->name ); - break; - } - - if (copy_attr_info && p_attr_data && p_attr_len) - { - *p_attr_data = p_cur_offset; - *p_attr_len = len; - - memcpy( (void *)*p_attr_data, - (const void *)cur_prop->p_data, - len ); - (*p_attr_data)[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - - #if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - - XML_TRACE_DEBUG5("[xml ml]: Attr ID=%d val=[%s] len=%d level=%d dst_len_left=%d", - cur_prop->name, - *p_attr_data, - *p_attr_len, - cur_prop->level, - *dst_len); - #endif - } - - if (no_buf_left) - { - #if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("Error!! No more buffer left to store the parser outputs"); - #endif - return -1; - } - - } -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("[xml ml] fill_ml: end:%d, xx:%d", end, xx); -#endif -#if 0 - /* if end tag not found -> split over two buffers. but parser will still show rest of - found properties. so return still found properties. */ - if (end == FALSE) - xx = 0; -#endif - - /* keep track of current data buffer offset */ - *p_dst_data = p_cur_offset; - return xx; -} /* xml_ml_int_fill_msg_list() */ - - -/********************************************************************************** -** Function xml_ml_int_fill_evt_data -** -** Description fill in MAP event report structure. -** -** Parameters -** Returns -**********************************************************************************/ -static tXML_ML_RES xml_ml_int_fill_evt_data( UINT8 op, - void *p_evt_data, - tXML_PROP **p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - tXML_ML_STATE *p_xud = (tXML_ML_STATE *)p_evt_data; - INT16 inc_prop; - UINT8 prop_name; /* Property name. */ - tXML_PROP *cur_prop = *p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - tXML_ML_RES x_res = XML_ML_OK; - BOOLEAN x_no_res = FALSE; /* guard dest buffer resource */ - - if ( op == 0 || op > XML_ML_MAX_OBJ_TAG_ID || *num_prop == 0) - return XML_ML_ERROR; - -#if ML_DEBUG_XML - XML_TRACE_DEBUG2( "[xml ml] xml_ml_int_fill_evt_data op:%d, num_prop:%d", - op, *num_prop); -#endif - - - - while ( *num_prop > 0 && !x_no_res ) - { -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("end_prop:%d, name id: x%x", *num_prop, cur_prop->name); -#endif - prop_name = cur_prop->name; - cur_prop++; - *num_prop -= 1; - - - switch ( prop_name ) - { - case XML_ML_ELEM_ID: - XML_TRACE_DEBUG0("[xml ml] xml_etag_elem"); - /* skip over version attribute which should always be 1.0. this is the top level */ - break; - - case XML_ML_MSG_ELEM_ID: - XML_TRACE_DEBUG0("[xml ml] xml_etag_elem"); - inc_prop = xml_ml_int_fill_msg_list( p_xud, - cur_prop, - num_prop, - &p_cur_offset, - dst_len); - if (inc_prop == -1) /* no dst_buf available */ - { - /* backup one more prop to obtain the skipped ml/file entry header */ - cur_prop --; - *num_prop += 1; - - x_res = XML_ML_DST_NO_RES; - x_no_res = TRUE; - } - else if (inc_prop == -2) /* exceed max entry */ - { - x_no_res = TRUE; - x_res = XML_ML_OUT_FULL; - } - else /* found ml entry */ - { - cur_prop += inc_prop; - *num_prop -= inc_prop; - } - break; - - case XML_ML_PAUSE_ID: -#if (ML_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml ml] xml_ml_int_fill_evt_data(): XML_ML_PAUSE_ID" ); -#endif - break; - - case XML_ML_TAG_END_ID: -#if (ML_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml ml] xml_ml_int_fill_evt_data(): XML_ML_TAG_END_ID" ); -#endif - break; - - default: - XML_TRACE_DEBUG1( "[xml ml] xml_ml_int_fill_evt_data():unknown element: %d", prop_name ); - break; - } - } - - /* keep track of current filling position, and current available dst buffer */ - *p_prop = cur_prop; - *p_dst_data = p_cur_offset; - - return x_res; -} /* xml_ml_int_fill_evt_data() */ - - -/************************************************************************************** -** Function XML_MlInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of an xml parser state machine to be initialized, -** allocate an additional space of size XML_ML_CARRY_OVER_LEN -** right after *p_xml_state to hold carry over data. -** p_entry : points start of output directory entry. caller needs do -** free this memory -** max_entry : max is 16 bit integer value which is the maximum number -** of ml entries. - -** -** Returns void -**************************************************************************************/ - -void XML_MlInit( tXML_ML_PARSER *p_xml_state, - tXML_ML_ENTRY *p_entry, - const UINT16 max_entry ) -{ - XML_TRACE_DEBUG0("[xml ml] XML_MlInit"); - /* Initialize the generic xml parser state machine.*/ - XML_InitPars( &p_xml_state->xml, xml_ml_cback, &p_xml_state->xml_user_data ); - - /* User need to allocate an additional space of size XML_ML_CARRY_OVER_LEN */ - /* right after *p_xml_state to hold carry over data. */ - /* point to the end of the allocated buffer for p_xml_state, which is the */ - /* beginning of buffer(XML_ML_CARRY_OVER_LEN) */ - p_xml_state->xml.last_bfr.p = (UINT8 *)(p_xml_state + 1); - p_xml_state->xml.last_bfr.len = XML_ML_CARRY_OVER_LEN; - - /* Initialize user data */ - p_xml_state->xml_user_data.p_entry = p_entry; - p_xml_state->xml_user_data.current_entry = 0; - p_xml_state->xml_user_data.max_name_len = XML_UI_ENTRY_MAX_NAME_LEN + 1; - p_xml_state->xml_user_data.max_entry = (UINT16)max_entry; - p_xml_state->xml_user_data.prop_num = 0; -} - - -/************************************************************************************** -** Function XML_MlParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_MlInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. - When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: pointer to the length of dst_data buffer, its carry out value -** is the number of bytes remaining buffer.When dst_len is NULL, -** it will cause to flush the internal data in the parser. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_ML_RES (see xml_erp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_ML_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_ML_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -tXML_ML_RES XML_MlParse( tXML_ML_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ) -{ - tXML_OS xos; - BOOLEAN is_remain = TRUE; - tXML_MUL_STATE *p_xml = &p_xml_state->xml; - tXML_ML_STATE *p_st = &p_xml_state->xml_user_data; - tXML_ML_RES x_res = XML_ML_OK; - tXML_RESULT res = XML_NO_PROP; - UINT16 max_num_prop = GKI_BUF3_SIZE/sizeof(tXML_PROP); /* i hope this is sufficient for 1 */ - - -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - int xx; - UINT8 dbg_buf[ML_DEBUG_LEN]; - tXML_STR str; -#endif - - XML_TRACE_DEBUG0("[xml ml] XML_MlParse"); - /* if dst_data is NULL, clean up remaining data */ - if (!dst_data || !dst_len) - { - /* clean out remained xml data left over from last parse */ - if (p_xml_state->xml_user_data.p_prop ) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = p_st->offset_prop = NULL; - p_st->prop_num = 0; - } -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml ml] XML_MlParse() Clean up left over!"); -#endif - return x_res; - } - - /* if illegal OBEX data or dst buffer pointer received, return ERROR */ - if (xml_len == 0 || !xml_data) - { - return XML_ML_ERROR; - } - - /* XML_MlParse receive new xml data, allocate buffer to hold parsed prop */ - if (p_st->offset_prop == NULL) - { - -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml ml] XML_MlParse() Receive New Data!"); - XML_TRACE_DEBUG2( "[xml ml] XML_data start[%x] end [%x]",xml_data, xml_data+xml_len); -#endif - is_remain = FALSE; - if ( NULL!= (p_st->p_prop = (tXML_PROP *)GKI_getbuf( GKI_BUF3_SIZE ) ) ) - { - /* pointing next prop to be converted into file entry */ - p_st->prop_num = 0; - } - else - { - GKI_freebuf( p_xml_state ); - x_res = XML_ML_NO_RES; - return x_res; - } - } -#if (ML_DEBUG_XML == TRUE) - else - { - XML_TRACE_DEBUG0( "[xml ml] XML_MlParse(): Keep cleaning up old xml data !"); - } -#endif - /* update the data address */ - xos.p_begin = xml_data; - xos.p_end = xml_data + xml_len; - - while ( res == XML_NO_PROP ) - { - /* if no remaining data in p_st->p_prop, parse new xml data */ - if (!is_remain) - { - p_st->max_num_prop = max_num_prop; - p_st->prop_index = 0; - res = XML_MulParse( p_xml, &xos ); - - -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4( "xml_ml_parse obj: %x, max: %d, num: %d, res: %d", - p_st->obj, max_num_prop, p_st->prop_index, res); - if (res != 0) - { - XML_TRACE_DEBUG1( "XML_MulParse Parsing: %d !!!", res); - } - - for (xx=0; xx<p_st->prop_index; xx++) - { - if ( p_st->p_prop[xx].name < XML_ML_MAX_ID ) - { - str.p = p_st->p_prop[xx].p_data; - str.len = p_st->p_prop[xx].len; - xml_ml_debug_str(&str, dbg_buf); - XML_TRACE_DEBUG5( "[xml ml] parsed: index[%d]:%d:%s: %s(%d)", p_st->prop_index-xx, p_st->p_prop[xx].level, - xml_ml_ttbl[p_st->p_prop[xx].name].p_name, dbg_buf, p_st->p_prop[xx].len); - } - else - { - XML_TRACE_DEBUG3( "[xml ml] internal prop: %d:%d:%d", xx, p_st->p_prop[xx].level, - p_st->p_prop[xx].name ); - } - } -#endif - p_st->prop_num = p_st->prop_index ; - p_st->offset_prop = p_st->p_prop; - } - else - { - /* This is left over data, pick up the result from the previous parse */ - res = p_xml->pars_res; - } - - if ( res != XML_OBJ_ST_EMPTY ) - { - x_res = xml_ml_int_fill_evt_data( p_st->obj, p_st, &p_st->offset_prop, &p_st->prop_num, &dst_data, dst_len ); - - if ( (XML_ML_OK == x_res) && (XML_NO_END == res) ) - { - /* XML_NO_END means that the xml is not completly finished and fill returns - ok when when partial filling has been ok */ - x_res = XML_ML_PENDING; - } - - /* all parsed xml data has been converted into file entry */ - /* or exceed max entry number , break the parsing loop */ - if (XML_ML_OUT_FULL != x_res && XML_ML_DST_NO_RES != x_res) - { - is_remain = FALSE; - } - else - break; - } - } /* while */ - - /* free property table. at next call a new one is allocated */ - if ((x_res != XML_ML_DST_NO_RES && p_st->p_prop) || - XML_ML_OUT_FULL == x_res) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = NULL; - p_st->offset_prop = NULL; - } - - if ( x_res != XML_ML_DST_NO_RES && p_st->ended) - { - /* this should happen on the same time as final flag in fact */ - x_res = XML_ML_END_LIST; /* found closing /ml-listing */ - } - - *num_entries = p_st->current_entry; /* report number of entries found. only when ended is true - application really should be interested! */ - return x_res; -} - diff --git a/stack/xml/xml_parse.c b/stack/xml/xml_parse.c deleted file mode 100644 index 3f9e2e1..0000000 --- a/stack/xml/xml_parse.c +++ /dev/null @@ -1,1502 +0,0 @@ -/***************************************************************************** -** -** Name: xml_parse.c -** -** File: XML Parser -** -** Copyright (c) 2000-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "xml_pars_api.h" -#include "data_types.h" -#include "bt_types.h" -/* The XML Parser is dependent on the Object Store. At present -** the object store resides in GOEP and hence the parser is -** dependent on GOEP. The parser only uses the Object Store -** in GOEP, so if the Object Store is separated from GOEP in the -** future, the parser will not be dependent on GOEP. -*/ - -#include <stdlib.h> -#include <string.h> - -#ifndef BIP_TRACE_XML -#define BIP_TRACE_XML FALSE -#endif - -#if (defined(BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - -/***************************************************************************** -** Constants -*****************************************************************************/ - -#define XML_ST '<' -#define XML_GT '>' -#define XML_QM '?' -#define XML_EX '!' -#define XML_EM '/' /* End Mark */ -#define XML_CO ':' -#define XML_EQ '=' -#define XML_SQ '\'' -#define XML_DQ '"' -#define XML_AM '&' -#define XML_SC ';' -#define XML_PD '#' -#define XML_HX 'x' -#define XML_HY '-' -#define XML_LB '[' - -#define XML_LT_STR "lt" -#define XML_GT_STR "gt" -#define XML_AMP_STR "amp" -#define XML_APOS_STR "apos" -#define XML_QUOT_STR "quot" - -#define XML_QTAG_END_STR "?>" -#define XML_COMM_STR "--" -#define XML_COMM_END_STR "-->" -#define XML_CDS_STR "[CDATA[" -#define XML_CDS_END_STR "]]>" -#define XML_DOCT_STR "<'\"" - -static const UINT8 xml_name_srch[] = ":=/> \t\n\r"; - - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -enum -{ - XML_PASS_WS, - XML_SKIP_WS, - XML_NORM_WS -}; -typedef UINT16 tXML_WS_OP; - - - -/***************************************************************************** -** Globals -** -** The global below is used as the buffer set (tXML_BFR_SET) in a local -** variable (of type tXML_MUL_STATE) in XML_Parse. The buffer set memory, is -** separated from the rest of tXML_MUL_STATE to make it easy to change the -** allocation of its memory if found necessary. See xml_alloc_bfr_set. -*****************************************************************************/ - -/***************************************************************************** -** Macro Functions -*****************************************************************************/ - -#define XML_EOS(p_st) ((p_st)->curr_res <= 0) /* End Of Store */ -/* white space: " ", \t, \r, \n */ -#define XML_IS_WS(c) (((c) == 0x20) || ((c) == 0x9) || \ - ((c) == 0xD) || ((c) == 0xA) || \ - ((c) == 0x00) ) - - -/***************************************************************************** -** Function Prototypes -*****************************************************************************/ - -static BOOLEAN xml_get_next(tXML_MUL_STATE *, tXML_WS_OP); - -static BOOLEAN xml_find_ch(tXML_MUL_STATE *, UINT8, tXML_WS_OP); - -static void xml_incr_pars_res(tXML_MUL_STATE *, tXML_RESULT); - -static void xml_set_bfr(tXML_MUL_STATE *, UINT8); - -/* parsing static functions */ - -static BOOLEAN xml_elems(tXML_MUL_STATE *, BOOLEAN); - -static BOOLEAN xml_qm_elem(tXML_MUL_STATE *); - -static BOOLEAN xml_ex_elem(tXML_MUL_STATE *, BOOLEAN); - -static BOOLEAN xml_tag_elem(tXML_MUL_STATE *); - -static BOOLEAN xml_etag_elem(tXML_MUL_STATE *); - -#define XML_SET_CLEAR 0 -#define XML_SET_NAME 1 -#define XML_SET_VALUE 2 - - - - -/***************************************************************************** -** API Functions -*****************************************************************************/ - -void XML_InitPars(tXML_MUL_STATE *p_st, tXML_CBACK xml_cback, void *p_usr_data) -{ - memset(p_st, 0, sizeof(tXML_MUL_STATE)); - p_st->cback = xml_cback; - p_st->p_usr_data = p_usr_data; - - /* by memset() - p_st->p_data_bfr = NULL; - p_st->next_token = 0; - p_st->curr_res = 0; - p_st->pars_res = XML_SUCCESS; - p_st->skip_next_nl = FALSE; - - p_st->prefix.p = NULL; - p_st->name.p = NULL; - p_st->value.p = NULL; - p_st->prefix.len= 0; - p_st->name.len = 0; - p_st->value.len = 0; - - p_st->status = XML_STS_INIT; - */ -} - - - -/***************************************************************************** -** -** Function XML_MulParse -** -** Description -** The current implementation of the xml_pars_api supports only those -** XML-contructs needed in BPP SOAP-messages. The parser must have a -** small footprint and is therefore small and simple. -** -** According to SOAP a message must not contain the doctypedecl construct -** (production) and it must not contain Processing Instructions (PI -** production), i.e. these constructs are not supported. In addition, -** CDATA sections, any external or internal entities and the XML -** Declaration are not supported (not used in BPP). Should any of these -** be included in a message being parsed, they will be reported returning -** a warning code. The parser will then try to find the next tag. -** When the parser reports an XML-event using the callback it will always -** continue, even if the callback returns false. All strings in event -** data passed with the callback are limited to 64 bytes in size, except -** the prefix string which has 32 as max size. Consequtive XML_CHARDATA -** events are not supported. Leading and trailing white space is removed -** from the value string before sending the XML_CHARDATA event. -** -** This function and also all other helping static parsing functions use -** more than one return statement in a function. The reason is that -** a parse error has been found and to exit as soon as possible. -** If one had used only one return in each function, the path -** representing a correct xml syntax had been expressed with very deeply -** nested if-statements. -** -** Parameters -** see h-file -** Returns -** see h-file -*****************************************************************************/ - -tXML_RESULT XML_MulParse(tXML_MUL_STATE *p_st, tXML_OS *p_os) -{ - BOOLEAN found; - BOOLEAN query, partial = FALSE; - BOOLEAN parse_ok = TRUE; - int keep_size; - tXML_RESULT res = XML_SUCCESS; - tXML_RESULT old_pars_res; - - p_st->curr_res = 1; /* not EOS */ - memcpy(&p_st->xml_os, p_os, sizeof(tXML_OS)); - old_pars_res = p_st->pars_res; - p_st->pars_res = XML_SUCCESS; - p_st->prefix.len = 0; - p_st->name.len = 0; - p_st->value.len = 0; - p_st->p_last_stm = 0; - p_st->p_copy = 0; - -#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE)) - XML_TRACE_DEBUG4("XML_MulParse status:%d, pars_res: %d, begin:%x, end:x%x", - p_st->status, old_pars_res, p_os->p_begin, p_os->p_end); -#endif - - /* this do-while(0) loop is to avoid too many return statements in this routine. - * it's easier to "cleanup" with only one return statement */ - if(p_st->status == XML_STS_INIT) - { - - p_st->p_cur = p_os->p_begin; -#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE)) - XML_TRACE_DEBUG1("p_cur:x%x", p_st->p_cur); -#endif - do - { - if (!xml_get_next(p_st, XML_PASS_WS)) /* obj store empty or err */ - { - res = XML_OBJ_ST_EMPTY; - break; - } - - found = FALSE; - while (!XML_EOS(p_st) && !found) - { /* skip all but top element */ - if (!xml_find_ch(p_st, XML_ST, XML_PASS_WS) || - !xml_get_next(p_st, XML_PASS_WS)) - { - res = XML_ERR; - break; - } - - if (p_st->next_token == XML_QM) - { - parse_ok = xml_qm_elem(p_st); - } - else if (p_st->next_token == XML_EX) - { - parse_ok = xml_ex_elem(p_st, TRUE); - } - else if (p_st->next_token == XML_EM) - { - parse_ok = FALSE; - if (!xml_get_next(p_st, XML_PASS_WS)) - { - res = XML_ERR; - break; - } - } - else - { - found = TRUE; - parse_ok = TRUE; - } - - if (!parse_ok) - xml_incr_pars_res(p_st, XML_ERR); - } - } while (0); - p_st->status = XML_STS_1STM; - } - else if(old_pars_res == XML_NO_PROP) - { - } - else - { -#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE)) - XML_TRACE_DEBUG2("p_st->last_bfr.p:x%x, p_st->used_last_bfr:%d", - p_st->last_bfr.p, p_st->used_last_bfr); -#endif - -/* if there was some data left, read it here. */ - if(p_st->partial_st.last_bfr.p && p_st->partial_st.used_last_bfr ) - { - memcpy(p_st->last_bfr.p, p_st->partial_st.last_bfr.p, p_st->partial_st.used_last_bfr); - p_st->used_last_bfr = p_st->partial_st.used_last_bfr; - p_st->last_bfr.p[p_st->partial_st.used_last_bfr] = 0; - p_st->event_data.part.parse = p_st->partial_st.event_data.part.parse; - - /* set length to 0 */ - p_st->partial_st.used_last_bfr = 0; - XML_TRACE_DEBUG1("retrieved PARTIAL data = [%s]\n", p_st->last_bfr.p); - - p_st->p_cur = p_st->last_bfr.p; - /* continuation packet */ - /* read a ch, setup xml_set_bfr */ - xml_get_next(p_st, XML_PASS_WS); - p_st->event_data.copy.p_begin = p_st->xml_os.p_begin; - p_st->event_data.copy.last.p = p_st->last_bfr.p; - p_st->event_data.copy.last.len = p_st->used_last_bfr; - p_st->cback(XML_COPY, &(p_st->event_data), p_st->p_usr_data); - } - else - { - if(p_st->used_last_bfr == 0) - { - p_st->p_cur = p_os->p_begin; - xml_get_next(p_st, XML_PASS_WS); - } - else - return XML_NO_MEM; - } -#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE)) - XML_TRACE_DEBUG1("p_st->p_cur:x%x", p_st->p_cur); -#endif - } - - XML_TRACE_DEBUG0("XML_MulParse end while"); - - if(res == XML_SUCCESS) - { - /* here we found "<(a-z)" */ - if (!XML_EOS(p_st)) - { - if(p_st->status == XML_STS_1STM) - { - /* remeber the beginning position right after '<' in the first line */ - /* if the first line can't be parsed at first round, save it to the second parse */ - p_st->p_copy = p_st->p_cur - 1; - parse_ok = xml_tag_elem(p_st); - } - - /* parsed the first line */ - XML_TRACE_DEBUG0("XML_MulParse exit xml_tag_elem"); - - if (!parse_ok) - { - query = p_st->cback(XML_QUERY, &(p_st->event_data), p_st->p_usr_data); - - /* if first line parsing is not completed while reach the end of stack, ERROR occurs */ - if (query == TRUE) - xml_incr_pars_res(p_st, XML_ERR); - else /* first line parsing to be continued, copy partial data at later point*/ - partial = TRUE; - } - else /* first line is parsed ok, change parsing status */ - p_st->status = XML_STS_1TAG; - - - - if (!XML_EOS(p_st) && parse_ok) - { - parse_ok = xml_elems(p_st, parse_ok); - query = p_st->cback(XML_QUERY, &(p_st->event_data), p_st->p_usr_data); - if (parse_ok == FALSE || query == FALSE) - { - partial = TRUE; - - } - else - p_st->status = XML_STS_DONE; - } - - /* copy partial data if any */ - if (partial) - { - if(p_st->pars_res == XML_NO_PROP) - { - p_st->p_cur = p_st->p_copy; - p_st->event_data.part.parse = p_st->pars_res; - p_st->event_data.part.p_keep = p_st->p_cur; - XML_TRACE_DEBUG1("p_st->p_cur:x%x (last_stm)", p_st->p_cur); - p_st->cback(XML_PARTIAL, &(p_st->event_data), p_st->p_usr_data); - xml_incr_pars_res(p_st, XML_NO_END); - } - else - { - if( p_st->last_bfr.p && - (p_st->p_copy > p_st->xml_os.p_begin) && - (p_st->p_copy < p_st->xml_os.p_end) ) - { - keep_size = p_st->xml_os.p_end - p_st->p_copy; - if(keep_size < p_st->last_bfr.len) - { - /* store the partial data to a temporary buffer, - NOT to the queue of buffers as it would overwrite current ones! */ - if(p_st->partial_st.last_bfr.p ) - { - XML_TRACE_DEBUG0("Store partial data\n"); - BCM_STRNCPY_S((char *)p_st->partial_st.last_bfr.p, 512, (char *)p_st->p_copy, keep_size); - p_st->partial_st.used_last_bfr= keep_size; - p_st->partial_st.last_bfr.p[keep_size] = 0; - p_st->partial_st.event_data.part.parse = p_st->pars_res; - p_st->partial_st.event_data.part.p_keep= p_st->last_bfr.p; - } - else - XML_TRACE_DEBUG0("ERROR to store partial data"); - - p_st->cback(XML_PARTIAL, &(p_st->event_data), p_st->p_usr_data); - xml_incr_pars_res(p_st, XML_NO_END); - } - } - }/* else NO_PROP */ - } /* end of partial */ - } /* end of !XML_EOS(p_st) */ - } /* end of res == XML_SUCCESS */ - - - return p_st->pars_res; -} - - -/***************************************************************************** -** Static Functions -*****************************************************************************/ - - - -/***************************************************************************** -** -** Function xml_set_bfr -** -** Description -** Sets the buffer that is going to be used when tokens are pushed from -** p_st->next_token into some buffer in the buffer set. -** -** Parameters -** p_st (in/out) : the parser state -** p_bfr (in) : the buffer that will get all tokens (characters) -** NULL is allowed in which case no buffer is used. -** bfr_max_ind (in) : the max index into the buffer in which a non-null -** char may be stored -** -** Returns -** - -*****************************************************************************/ -static void xml_set_bfr(tXML_MUL_STATE *p_st, UINT8 set) -{ - switch(set) - { - case XML_SET_NAME: - p_st->name.p = p_st->p_cur - 1; - p_st->p_data_bfr = p_st->name.p; - p_st->name.len = 0; - break; - case XML_SET_VALUE: - p_st->value.p = p_st->p_cur - 1; - p_st->p_data_bfr = p_st->value.p; - p_st->value.len = 0; - break; - default: - p_st->p_data_bfr = NULL; - } -} - - -/***************************************************************************** -** -** Function xml_write_bfr -** -** Description -** Pushes (copies) the character from p_st->next_token to the buffer, if -** any, that has been set calling xml_set_bfr. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** - -*****************************************************************************/ - -static void xml_write_bfr(tXML_MUL_STATE *p_st) -{ - if (p_st->p_data_bfr) - { - if(p_st->p_data_bfr == p_st->name.p) - p_st->name.len++; - else - p_st->value.len++; - } -} - - -/***************************************************************************** -** -** Function xml_incr_pars_res -** -** Description -** Sets the final parsing result if the new_res provided has -** higher rank than the current parsing result. -** -** Parameters -** p_st (in/out) : the parser state -** new_res (in) : the new parsing result -** -** Returns -** - -*****************************************************************************/ - -static void xml_incr_pars_res(tXML_MUL_STATE *p_st, tXML_RESULT new_res) -{ - if (new_res > p_st->pars_res) - { - switch(p_st->pars_res) - { - /* preserve these error messages */ - case XML_OBJ_ST_EMPTY: - case XML_NO_MEM: /* no last_bfr.p, and the tXML_MUL_STATE is not in init */ - case XML_NO_PROP: /* run out of tXML_PROP */ - break; - - default: - /* - case XML_SUCCESS: - case XML_WARNING: - case XML_ERR: - */ - p_st->pars_res = new_res; - break; - } - } -} - - -/***************************************************************************** -** -** Function xml_read_char -** -** Description -*****************************************************************************/ -static void xml_read_char(tXML_MUL_STATE *p_st) -{ - BOOLEAN get_new = FALSE; - - if (p_st->p_cur && p_st->p_cur >= p_st->last_bfr.p && p_st->p_cur < (p_st->last_bfr.p + p_st->used_last_bfr)) - { - /* left over from previous parse */ - p_st->next_token = *p_st->p_cur; - if(p_st->next_token == 0) - { - /* leftover is done, use the new one */ - p_st->p_cur = p_st->xml_os.p_begin; - p_st->last_bfr.p[0] = 0; - p_st->used_last_bfr = 0; - get_new = TRUE; - } - else - { - p_st->p_cur++; - p_st->curr_res = 1; - } - } - else - { - if(p_st->p_cur == (p_st->last_bfr.p + p_st->used_last_bfr)) - { - p_st->used_last_bfr = 0; - p_st->p_cur = p_st->xml_os.p_begin; - } - get_new = TRUE; - } - - if(get_new) - { - if(p_st->p_cur && p_st->p_cur < p_st->xml_os.p_end) - { - /* use buffer given to XML_Parse */ - p_st->next_token = *p_st->p_cur; - p_st->p_cur++; - p_st->curr_res = 1; - } - else - p_st->curr_res = 0; - } - - -/* - XML_TRACE_DEBUG4("xml_read_char p_cur: x%x, curr_res:%d, get_new:%d, token:%c", - p_st->p_cur, p_st->curr_res, get_new, p_st->next_token); -*/ -} - -/***************************************************************************** -** -** Function xml_get_next -** -** Description -** Writes the character in p_st->next_token to the current buffer if set. -** Then the next character is read from the Object Store into -** p_st->next_token. The first time get_next is called, the current -** buffer must be NULL, i.e p_st->data_bfr must be NULL. -** -** xml_get_next handles end-of-line as specified in the xml spec. It -** passes, skips or normalises (p.29 in XML spec) white spaces (ws) -** as specified in the ws_op param. Note, the ws_op applies when -** getting one (or many characters) from Object Store into the -** p_st->next_token. It does not apply when pushing the (initial) -** p_st->next_token to the current buffer. -** -** The characters are read one by one from the Object Store. -** Presently this is not anticipated to cause any problems -** regarding reading speed. Should it become a problem in the -** future, a new buffer could be introduced into which a chunk -** of characters could be put, using one Object Store read call. -** The get_next function would then get the next character from -** the new buffer. -** -** Parameters -** p_st (in/out) : the parser state -** ws_op (in) : the requested white space handling. -** -** Returns -** True if a character was successfully read into p_st->next_token. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_get_next(tXML_MUL_STATE *p_st, tXML_WS_OP ws_op) -{ - xml_write_bfr(p_st); - do - { - xml_read_char(p_st); - } while ((ws_op == XML_SKIP_WS) && XML_IS_WS(p_st->next_token) && - !XML_EOS(p_st)); - - - /* handle end-of-line if any after the do-while above */ - - if (!XML_EOS(p_st) && (p_st->next_token == 0xA) && p_st->skip_next_nl) - { /* we have previously found 0xD (cr) and have set the state var - ** p_st->skip_next_nl,see below - */ - xml_read_char(p_st); - } - p_st->skip_next_nl = FALSE; - - if (XML_EOS(p_st)) - { - p_st->next_token = 0; - return FALSE; - } - - if (p_st->next_token == 0xD) - { - p_st->next_token = 0xA; - p_st->skip_next_nl = TRUE; - } - - if ((ws_op == XML_NORM_WS) && - ((p_st->next_token == 0xA) || (p_st->next_token == 0x9))) - { - p_st->next_token = 0x20; - } - - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_find_ch -** -** Description -** Searches for the character given in ch. It starts searching in -** p_st->next_token and if not found it gets characters from the Object -** Store until ch is in p_st->next_token. -** -** Parameters -** p_st (in/out) : the parser state -** ch (in) : the character to search for -** ws_op (in) : the requested white space handling when getting chars -** -** Returns -** True if the character was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_find_ch(tXML_MUL_STATE *p_st, UINT8 ch, tXML_WS_OP ws_op) -{ - while (!XML_EOS(p_st) && (p_st->next_token != ch)) - xml_get_next(p_st, ws_op); - return (BOOLEAN) !XML_EOS(p_st); -} - - -/***************************************************************************** -** -** Function xml_find_ch_n -** -** Description -** Same function as xml_find_ch, except that any character in p_str -** that is found will stop the search. -** -** Parameters -** p_st (in/out) : the parser state -** p_str (in) : the string containing the characters searched for. -** Must not be NULL or an empty string. -** -** Returns -** True if any of the characters in p_str was found. -** Fase otherwise. -*****************************************************************************/ - -static BOOLEAN xml_find_ch_n(tXML_MUL_STATE *p_st, const UINT8 *p_str) -{ - const UINT8 *p_tmp; - - while (!XML_EOS(p_st)) - { - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (p_st->next_token == *p_tmp) - return TRUE; - } - xml_get_next(p_st, XML_PASS_WS); - } - return FALSE; -} - - -/***************************************************************************** -** -** Function xml_find_str -** -** Description -** Searches for p_str (i.e the exact sequence of characters in p_str) in -** the input from Object Store. The function ends with the character -** succeeding p_str in the input, (i.e that char is in p_st->next_token -** upon return) or with XML_EOS. -** -** Parameters -** p_st (in/out) : the parser state -** p_str (in) : the string to search for and pass by. -** Must not be NULL or an empty string. -** -** Returns -** True if the string was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_find_str(tXML_MUL_STATE *p_st, const UINT8 *p_str) -{ - const UINT8 *p_tmp; - - p_tmp = p_str; - while (*p_tmp && !XML_EOS(p_st)) - { - for (p_tmp = p_str; *p_tmp && !XML_EOS(p_st); p_tmp++) - { - if (p_st->next_token != *p_tmp) - break; - xml_get_next(p_st, XML_PASS_WS); - } - - if ((p_tmp == p_str) && !XML_EOS(p_st)) - { - xml_get_next(p_st, XML_PASS_WS); - } - } - - return (BOOLEAN) (*p_tmp == 0); -} - - -/***************************************************************************** -** -** Function xml_consume_str -** -** Description -** Checks for p_str i.e that the first character from p_str is in -** p_st->next_token and that the successors immediately follows in the -** Object Store. The p_str must not be last in the Object Store. -** -** Parameters -** p_st (in/out) : the parser state -** p_str (in) : the string to check if present next and to pass by -** Must not be NULL. -** -** Returns -** True if the string was found and was not last in the Object Store. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_consume_str(tXML_MUL_STATE *p_st, const UINT8 *p_str) -{ - do - { - if (p_st->next_token != *p_str) - return FALSE; - p_str++; - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - } while (*p_str); - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_resolve_refs -** -** Description -** Resolves predefined entity references (sect. 4.6 in the XML spec) -** and character references (sect 4.1) that may be found in -** AttValue and content. (According to the XML spec it may also -** be in an EntityValue. However EntityValues are in the -** doctypedecl part which is not supported). -** -** The AttValue and content not beginning with a tag, must be -** stored in the p_st->p_bfr_set->value buffer. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** - -*****************************************************************************/ - -static void xml_resolve_refs(tXML_MUL_STATE *p_st) -{ - UINT8 *p_srch; /* where next search for & starts */ - UINT8 *p_am; /* points to found & */ - UINT8 *p_sc; /* points to found ; and succeeding chars */ - UINT8 *p_start; - UINT8 *p_tmp; - UINT32 ch_code; - UINT32 tmp_code; - INT8 i; - BOOLEAN resolved; - UINT16 len_left; - - p_srch = p_st->value.p; - len_left = p_st->value.len; - do - { - p_start = p_srch; - p_am = (UINT8*) strchr((char*) p_srch, XML_AM); - p_sc = p_am ? (UINT8*) strchr((char*) p_am, XML_SC) : NULL; - /* make sure the ptr does not exceed the end of the value str */ - if(p_sc > (len_left + p_start)) - p_sc = NULL; - - if (p_am && p_sc) - { - resolved = FALSE; - p_tmp = p_am + 1; - *p_sc = 0; /* terminate the ref by replacing ; with 0 */ - if (*p_tmp == XML_PD) /* character ref */ - { - if (p_tmp[1] == XML_HX) - *p_tmp = '0'; - else - { - for(p_tmp++; *p_tmp == '0'; p_tmp++) - { - ; - } - } - - ch_code = strtoul((char*) p_tmp, NULL, 0); - /* skip leading zero bytes */ - for (i = 3; (i >= 0) && !(ch_code >> i * 8); i--) - { - ; - } - p_tmp = p_am; - while (i >= 0) - { - /* mask out one byte and shift it rightmost */ - /* preceding bytes must be zero so shift left first */ - tmp_code = ch_code << ((3-i) * 8); - *p_tmp = (UINT8) (tmp_code >> 24); - p_tmp++; - i--; - } - resolved = TRUE; - } - else if (p_tmp < p_sc) /* check if predefined ref */ - { - resolved = TRUE; - if (strcmp((char*) p_tmp, XML_LT_STR) == 0) - { - *p_am = XML_ST; - p_st->value.len = p_st->value.len - 3; /* remove the length for lt; */ - p_st->p_cur = p_st->p_cur - 3; - } - else if (strcmp((char*) p_tmp, XML_GT_STR) == 0) - { - *p_am = XML_GT; - p_st->value.len = p_st->value.len - 3; /* remove the length for gt; */ - p_st->p_cur = p_st->p_cur - 3; - } - else if (strcmp((char*) p_tmp, XML_AMP_STR) == 0) - { - *p_am = XML_AM; - p_st->value.len = p_st->value.len - 4; /* remove the length for amp; */ - p_st->p_cur = p_st->p_cur - 4; - } - else if (strcmp((char*) p_tmp, XML_APOS_STR) == 0) - { - *p_am = XML_SQ; - p_st->value.len = p_st->value.len - 5; /* remove the length for apos; */ - p_st->p_cur = p_st->p_cur - 5; - } - else if (strcmp((char*) p_tmp, XML_QUOT_STR) == 0) - { - *p_am = XML_DQ; - p_st->value.len = p_st->value.len - 5; /* remove the length for quot; */ - p_st->p_cur = p_st->p_cur - 5; - } - else - resolved = FALSE; - } - - if (resolved) - { - p_srch = p_tmp; /* will contain char after ; */ - p_sc++; - while(*p_sc) - { - *p_tmp++ = *p_sc++; - } - } - else - { - *p_sc = XML_SC; /* restore the ref end */ - p_srch = p_sc + 1; - } - - } /* end if */ - } while (*p_srch && p_am && p_sc); -} - - -/***************************************************************************** -** -** Function xml_remove_trail_ws -** -** Description -** Removes trailing white space from the p_st->p_data_bfr buffer. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** - -*****************************************************************************/ - -static void xml_remove_trail_ws(tXML_MUL_STATE *p_st) -{ - UINT16 xx; - - if(p_st->value.p) - { - xx = p_st->value.len; - while(xx && XML_IS_WS(p_st->value.p[xx-1])) - xx--; - p_st->value.len = xx; - } - -} - - -/***************************************************************************** -** Parsing Static Functions -*****************************************************************************/ - - -/***************************************************************************** -** -** Function xml_name -** -** Description -** Parses a name and its prefix if any. The prefix and name buffers -** are set. -** The functions ends with either white space, -** XML_EQ, XML_EM or XML_GT in p_st->next_token or with XML_EOS. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_name(tXML_MUL_STATE *p_st) -{ - BOOLEAN found = FALSE; - - p_st->prefix.p = NULL; - p_st->prefix.len = 0; - xml_set_bfr(p_st, XML_SET_NAME); - xml_find_ch_n(p_st, xml_name_srch); - if (!XML_EOS(p_st) && (p_st->next_token == XML_CO)) - { - if (p_st->name.len) - { - found = TRUE; - /* p_st->name.len is string size in name buffer, \0 excl. - */ - p_st->prefix.p = p_st->name.p; - p_st->prefix.len = p_st->name.len; - } - xml_get_next(p_st, XML_PASS_WS); - xml_set_bfr(p_st, XML_SET_NAME); - if (!XML_EOS(p_st)) - { - xml_find_ch_n(p_st, xml_name_srch + 1); - } - } - - found = (BOOLEAN) (found || p_st->name.len); - if(found) - xml_set_bfr(p_st, XML_SET_CLEAR); - return found; -} - - -/***************************************************************************** -** -** Function xml_attributes -** -** Description -** Parses an attribute list. -** The functions ends with the XML_GT or XML_EM char or XML_EOS. -** Error is reported if the attribute list is last in the Object -** Store. -** Sends a XML_ATTRIBUTE event in the user callback for each -** attribute found. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_attributes(tXML_MUL_STATE *p_st) -{ - BOOLEAN cb_ret = TRUE; - UINT8 q_ch; - - XML_TRACE_DEBUG1("[xml_parse] xml_attributes: res= %d", p_st->pars_res); - - while ( cb_ret) - { - /* if this is a white space, then the next character is read from the - Object Store into p_st->next_token */ - if( XML_IS_WS(p_st->next_token) ) - { - if (!xml_get_next(p_st, XML_SKIP_WS)) - return FALSE; - } - - if (p_st->next_token == XML_EQ) - return FALSE; - - if ((p_st->next_token == XML_GT) || (p_st->next_token == XML_EM)) - return TRUE; - if (!xml_name(p_st) || XML_EOS(p_st)) - { - return FALSE; - } - if(XML_IS_WS(p_st->next_token)) - { - if (!xml_get_next(p_st, XML_SKIP_WS)) - return FALSE; - } - - if (p_st->next_token != XML_EQ) - return FALSE; - - if (!xml_get_next(p_st, XML_SKIP_WS)) - return FALSE; - - if ((p_st->next_token != XML_SQ) && (p_st->next_token != XML_DQ)) - return FALSE; - - q_ch = p_st->next_token; - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - - xml_set_bfr(p_st, XML_SET_VALUE); - if (!xml_find_ch(p_st, q_ch, XML_NORM_WS)) - { - return FALSE; - } - - xml_set_bfr(p_st, XML_SET_CLEAR); - xml_resolve_refs(p_st); - - p_st->event_data.attr.prefix.p = p_st->prefix.p; - p_st->event_data.attr.prefix.len = p_st->prefix.len; - p_st->event_data.attr.name.p = p_st->name.p; - p_st->event_data.attr.name.len = p_st->name.len; - p_st->event_data.attr.value.p = p_st->value.p; - p_st->event_data.attr.value.len = p_st->value.len; - p_st->value.len = 0; - cb_ret = p_st->cback(XML_ATTRIBUTE, &(p_st->event_data), p_st->p_usr_data); - /* chk cback return */ - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - } - - return (BOOLEAN) - ((p_st->next_token == XML_GT) || (p_st->next_token == XML_EM)); -} - - -/***************************************************************************** -** -** Function xml_elems -** -** Description -** Parses all elements with all their content.This function is not a -** one-to-one mapped implementation of one production from the XML spec. -** Instead it uses a simplified iterative (as opposed to recursive) -** approach when parsing both the element and content productions. -** -** When a parsing error is found, this function tries to recover by -** searching for the next element (tag). -** -** When char data is found, the function sends the XML_CHARDATA event in -** the user callback. -** -** Other static functions with production names, start their parsing -** from the first character in their production. They might check -** that the first character (token) in the production matches -** p_st->next_token, alternatively they can just get rid of the first -** char in the production by calling get_next_ch. The exceptions to this -** are the xml_qm_elem, xml_ex_elem, xml_etag_elem and the xml_tag_elem -** functions which starts with the XML_QM, XML_EX, XML_EM and the first -** char in the tag name, respectively. -** -** Parameters -** p_st (in/out) : the parser state -** prev_ok (in) : if parsing done before calling this function was -** ok. If not, the functions starts with recovering. -** -** Returns -** True if parsing was successful possibly with successful recoveries. -** False if an error was found from which recovery failed (XML_EOS). -*****************************************************************************/ - -static BOOLEAN xml_elems(tXML_MUL_STATE *p_st, BOOLEAN prev_ok) -{ - BOOLEAN tag_found; - BOOLEAN cb_ret = TRUE; - - while (!XML_EOS(p_st) && prev_ok) - { - /* remove leading ws even if char data */ - if (XML_IS_WS(p_st->next_token)) - { - if (!xml_get_next(p_st, XML_SKIP_WS)) - return TRUE; - } - - tag_found = (BOOLEAN) (p_st->next_token == XML_ST); - if (!tag_found) - { - xml_set_bfr(p_st, XML_SET_VALUE); - tag_found = xml_find_ch(p_st, XML_ST, XML_PASS_WS); - - xml_remove_trail_ws(p_st); - if (p_st->value.len > 0) - { - xml_resolve_refs(p_st); - p_st->event_data.ch_data.value.p = p_st->value.p; - p_st->event_data.ch_data.value.len = p_st->value.len; - p_st->event_data.ch_data.last = TRUE; - p_st->value.len = 0; - cb_ret = p_st->cback(XML_CHARDATA, &(p_st->event_data), p_st->p_usr_data); - /* chk cback return */ - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - } - xml_set_bfr(p_st, XML_SET_CLEAR); - - if (!tag_found) - return prev_ok; - } - else - { - p_st->p_last_stm = p_st->p_cur - 1; - - if (p_st->p_cur) - p_st->p_copy = p_st->p_last_stm; - - p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data); - } - - /* tag was found */ - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - - if (p_st->next_token == XML_QM) - prev_ok = xml_qm_elem(p_st); - else if (p_st->next_token == XML_EX) - { - prev_ok = xml_ex_elem(p_st, FALSE); - } - else if (p_st->next_token == XML_EM) - { - prev_ok = xml_etag_elem(p_st); - } - else - prev_ok = xml_tag_elem(p_st); - - - - if (!prev_ok) - xml_incr_pars_res(p_st, XML_ERR); - } - - XML_TRACE_DEBUG1("xml_elems prev_ok:%d", prev_ok); - return prev_ok; -} - - -/***************************************************************************** -** -** Function xml_qm_elem -** -** Description -** Recognises all productions starting with "<?". That is PI and XML decl. -** These productions are skipped and XML_WARNING is set. -** The function starts with the XML_QM as the first char (is in -** p_st->next_token).It ends with the XML_GT successor (is in -** p_st->next_token) or XML_EOS. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found trying to recognise the start and end of -** the productions. False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_qm_elem(tXML_MUL_STATE *p_st) -{ - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - if (!xml_find_str(p_st, (UINT8*) XML_QTAG_END_STR)) - return FALSE; - xml_incr_pars_res(p_st, XML_WARNING); - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_ex_elem -** -** Description -** Handles all productions starting with "<!". They are Comments, CDSect -** doctypedecl and markupdecl. All are skipped. However, the inpar -** prolog must be set for the function to try to detect the doctypedecl -** and markupdecl beginning. -** -** The function starts with the XML_EX as the first char. -** The function ends with XML_EOS or the char succeeding XML_GT, -** except for doctypedecl and marcupdecl which ends with the next XM_TAG. -** -** Parameters -** p_st (in/out) : the parser state -** prolog (in) : should be set if in prolog in which case the function -** tries to detect (allows) the beginning of doctypedecl -** and markupdecl. -** Returns -** True if no error was found trying to recognise the start and end of -** the productions. False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_ex_elem(tXML_MUL_STATE *p_st, BOOLEAN prolog) -{ - UINT8 q_ch; - - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - if (p_st->next_token == XML_HY) /* comment */ - { - if (!xml_consume_str(p_st, (UINT8*) XML_COMM_STR)) - return FALSE; - - if (!xml_find_str(p_st, (UINT8*) XML_COMM_END_STR)) - return FALSE; - } - else if (p_st->next_token == XML_LB) /* CDSect */ - { - if (!xml_consume_str(p_st, (UINT8*) XML_CDS_STR)) - return FALSE; - - if (!xml_find_str(p_st, (UINT8*) XML_CDS_END_STR)) - return FALSE; - - xml_incr_pars_res(p_st, XML_WARNING); - } - else if (prolog) /* doctypedecl or markupdecl */ - { - do - { - if (!xml_find_ch_n(p_st, (UINT8*) XML_DOCT_STR)) - return FALSE; - - if ((p_st->next_token == XML_SQ) || (p_st->next_token == XML_DQ)) - { - q_ch = p_st->next_token; - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - if (!xml_find_ch(p_st, q_ch, XML_PASS_WS)) - return FALSE; - - xml_get_next(p_st, XML_PASS_WS); - } - } while (!XML_EOS(p_st) && (p_st->next_token != XML_ST)); - - xml_incr_pars_res(p_st, XML_WARNING); - } - else /* error */ - { - return FALSE; - } - - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_tag_elem -** -** Description -** Parses a tag element. The function starts with the char succeeding the -** XML_ST char. -** The functions ends with the char succeeding the XML_GT char or -** with XML_EOS. -** Sends the XML_TAG and the XML_TAG_END events in a callback each. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_tag_elem(tXML_MUL_STATE *p_st) -{ - BOOLEAN cb_ret = TRUE; - - if (!xml_name(p_st)) - return FALSE; - - p_st->event_data.tag.prefix.p = p_st->prefix.p; - p_st->event_data.tag.name.p = p_st->name.p; - p_st->event_data.tag.prefix.len = p_st->prefix.len; - p_st->event_data.tag.name.len = p_st->name.len; - p_st->event_data.tag.p_last_stm = p_st->p_last_stm; - cb_ret = p_st->cback(XML_TAG, &(p_st->event_data), p_st->p_usr_data); - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - /* chk cback return */ - - if (XML_EOS(p_st)) - return FALSE; - - if (XML_IS_WS(p_st->next_token)) - { - if (!xml_attributes(p_st)) - return FALSE; - } - - p_st->event_data.empty_elem.end = (BOOLEAN) (p_st->next_token == XML_EM); - if (p_st->event_data.empty_elem.end) - { - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - } - - if (p_st->next_token != XML_GT) - return FALSE; - - xml_get_next(p_st, XML_PASS_WS); - - cb_ret = p_st->cback(XML_TAG_END, &(p_st->event_data), p_st->p_usr_data); - - - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - p_st->p_copy = p_st->p_cur - 1; - p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data); - /* chk cback return */ - - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_etag_elem -** -** Description -** Parses an end tag element. The function starts with the XML_EM char. -** The functions ends with the char succeeding the XML_GT char or -** with XML_EOS. Sends the XML_ETAG event in the user callback. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_etag_elem(tXML_MUL_STATE *p_st) -{ - BOOLEAN cb_ret = TRUE; - - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - if (!xml_name(p_st)) - return FALSE; - - p_st->event_data.etag.prefix.p = p_st->prefix.p; - p_st->event_data.etag.name.p = p_st->name.p; - p_st->event_data.etag.name.len = p_st->name.len; - p_st->event_data.etag.prefix.len = p_st->prefix.len; - cb_ret = p_st->cback(XML_ETAG, &(p_st->event_data), p_st->p_usr_data); - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - p_st->p_copy = (p_st->prefix.p) ? p_st->prefix.p - 2: p_st->name.p - 2; - p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data); - - /* chk cback return */ - - if (XML_EOS(p_st)) - return FALSE; - - if (XML_IS_WS(p_st->next_token)) - if (!xml_get_next(p_st, XML_SKIP_WS)) - return FALSE; - - if (p_st->next_token != XML_GT) - return FALSE; - - xml_get_next(p_st, XML_PASS_WS); - - return TRUE; -} - diff --git a/stack/xml/xml_vlist.c b/stack/xml/xml_vlist.c deleted file mode 100644 index 2800c12..0000000 --- a/stack/xml/xml_vlist.c +++ /dev/null @@ -1,873 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_vlist.c - ** - ** Description: This module contains xml parser of VCard listing - ** - ** Copyright (c) 2004-2011, Broadcom Corporation, All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#include "bt_target.h" -#include "gki.h" -#include "xml_vlist_api.h" - -#include <string.h> -#include <stdlib.h> - -#ifndef VLIST_DEBUG_XML -#define VLIST_DEBUG_XML FALSE -#endif -#define VLIST_DEBUG_LEN 50 -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - - -/***************************************************************************** -** Constants -*****************************************************************************/ -const UINT8 xml_vlist_elem[] = "vCard-listing";/* "vCard-listing" */ -const UINT8 xml_card_elem[] = "card"; /* "card" */ -const UINT8 xml_handle_attr[] = "handle"; /* "handle" */ -const UINT8 xml_vlist_name_attr[] = "name"; /* "name" */ -const UINT8 xml_vlist_version_attr[] = "version"; /* "version" */ -const UINT8 xml_vlist_unknown[] = "unknown"; /* "unknown" */ - - -#define XML_VLIST_ELEM_ID 0x01 -#define XML_CARD_ELEM_ID 0x02 -#define XML_MAX_OBJ_TAG_ID XML_VLIST_ELEM_ID -#define XML_HANDLE_ATTR_ID 0x03 -#define XML_NAME_ATTR_ID 0x04 -#define XML_VERSION_ATTR_ID 0x05 -#define XML_XP_UNKNOWN_ID 0x06 -#define XML_VLIST_MAX_ID 0x07 /* keep in sync with above */ -#define XML_VLIST_TAG_END_ID 0x07 /* closing tag found end=true */ -#define XML_VLIST_PAUSE_ID 0x08 /* closing tag found end=false */ - - -#define XML_VLIST_TTBL_SIZE (XML_VLIST_MAX_ID+1) - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -typedef struct -{ - const UINT8 *p_name; - UINT8 len; -} tXML_VLIST_TTBL_ELEM; - -typedef tXML_VLIST_TTBL_ELEM tXML_VLIST_TTBL[]; /* Tag Table */ - - -static const tXML_VLIST_TTBL_ELEM xml_vlist_ttbl[XML_VLIST_TTBL_SIZE] = -{ /* index (VLIST_XP_*_ID) & name */ - {(UINT8*) "", XML_VLIST_MAX_ID-1}, /* \x00 Number of elements in array */ - {xml_vlist_elem, 13}, /* \x01 vcard listing */ - {xml_card_elem, 4}, /* \x02 card */ - {xml_handle_attr, 6}, /* \x03 handle */ - {xml_vlist_name_attr, 4}, /* \x04 name */ - {xml_vlist_version_attr, 7}, /* \x05 version */ - {xml_vlist_unknown, 7}, /* \x06 unknown */ -}; - -#define XML_VLIST_PTBL_SIZE 0x03 -typedef UINT8 * tXML_VLIST_PTBL_ELEM; - -static const tXML_VLIST_PTBL_ELEM xml_vlist_ptbl[XML_VLIST_PTBL_SIZE] = -{ - (UINT8*) "\x01", /* \x00 */ - (UINT8*) "\x05\x02", /* \x01 Vcard Listing */ - (UINT8*) "\x03\x04" /* \x02 Card */ -}; - - -#if (VLIST_DEBUG_XML == TRUE) -void xml_vlist_debug_str(tXML_STR *p_str, UINT8 *p_buf) -{ - int dbg_len; - if ( (p_str == NULL) || (NULL==p_str->p)) - BCM_STRCPY_S( (char *)p_buf, VLIST_DEBUG_LEN, "(NULL)" ); - else - { - dbg_len = p_str->len; - if ( dbg_len >= VLIST_DEBUG_LEN) - dbg_len = VLIST_DEBUG_LEN - 1; - BCM_STRNCPY_S( (char *)p_buf, VLIST_DEBUG_LEN, (char *)p_str->p, dbg_len); - p_buf[dbg_len] = 0; - } -} - -#else -#define xml_vlist_debug_str(p_str, p_buf) -#endif - -/***************************************************************************** - ** Function xml_vlist_proc_tag - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_vlist_proc_tag( tXML_VLIST_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - UINT8 dbg_name[VLIST_DEBUG_LEN]; -#endif - - if (curr < XML_VLIST_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_vlist_ptbl[curr]; p_stag && *p_stag ; p_stag++) - { - if (*p_stag >= XML_VLIST_TTBL_SIZE) - continue; - if(p_name->len == xml_vlist_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_vlist_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_vlist_proc_tag: bad name:%s", dbg_name ); -#endif - - return XML_XP_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_vlist_proc_attr - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_vlist_proc_attr(tXML_VLIST_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (VLIST_DEBUG_XML == TRUE) - UINT8 dbg_name[VLIST_DEBUG_LEN]; -#endif - - if (curr < XML_VLIST_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_vlist_ptbl[curr]; p_stag && *p_stag; p_stag++) - { - if (*p_stag >= XML_VLIST_TTBL_SIZE) - continue; - if(p_name->len == xml_vlist_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_vlist_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_vlist_proc_attr: bad name:%s", dbg_name); -#endif - return XML_XP_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_vlist_find_ch_n_copy - ** Description copy any chacter till one char in p_str. Any char in p_str - ** will stop copy pointed by p_begin - ** Parameters - ** Returns - *****************************************************************************/ -static void xml_vlist_find_ch_n_copy( tXML_MCOPY *p_copy ) -{ - const UINT8 *p_tmp; - const UINT8 *p_str = (UINT8 *)">"; /* was: ":=/> \t\n\r". i think we should copy till - closing flag */ - unsigned int last = XML_VLIST_CARRY_OVER_LEN; /* maximum carry over len we can support */ - UINT8 *p_last = p_copy->last.p + p_copy->last.len - 1; /* point to the last char of carry - over buffer */ - BOOLEAN found = FALSE; - - /* check if the last char in p_last is in p_str */ - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_last == *p_tmp) - { - found = TRUE; - break; - } - } /* for */ - - if (found == FALSE) - { - /* if not in p_str, move chars from p_begin to p_last - * until reached last_len or any char in p_str */ - p_last++; - last -= p_copy->last.len; /* calculate the maximum number of chars we can copy */ - while (*(p_copy->p_begin) && last) /* rl: not sure that this buffer is termninated by a 0 */ - { - /* copy from source (new buffer) to carry over. adjust only carry over ptr. */ - *p_last++ = *p_copy->p_begin; - last--; - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_copy->p_begin == *p_tmp) - { - p_copy->p_begin++; /* adjust pointer to point to next char to read */ - /* calculate new length of carry over buffer contents */ - p_copy->last.len = XML_VLIST_CARRY_OVER_LEN-last; - *p_last = 0; /* NULL terminate p_last. rl: not really neccessary. */ - return; - } - } /* for */ - p_copy->p_begin++; /* update now to next char. this way abort char is also copied */ - } /* while */ - } /* !found */ -} - -/***************************************************************************** -** Function xml_vlist_cback -** Description -** -** Parameters -** Returns -*****************************************************************************/ -static BOOLEAN xml_vlist_cback( tXML_EVENT event, void *p_event_data, void *p_usr_data) -{ - tXML_MEVT_DATA *p_ed = (tXML_MEVT_DATA*) p_event_data; - tXML_VLIST_STATE *p_st = (tXML_VLIST_STATE *) p_usr_data; - tXML_PROP *p_cp = &p_st->p_prop[p_st->prop_index]; - BOOLEAN ret = TRUE; - UINT8 next; /* next element */ - UINT8 curr = p_ed->stack.stack[p_ed->stack.top]; /* current element */ -#if (VLIST_DEBUG_XML == TRUE) - UINT8 dbg_name[VLIST_DEBUG_LEN]; - UINT8 dbg_prefix[VLIST_DEBUG_LEN]; - UINT8 dbg_value[VLIST_DEBUG_LEN]; -#endif - -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("xml_vlist_cback:%d", event); -#endif - - switch (event) - { - case XML_TAG : /* <tag-name */ - next = xml_vlist_proc_tag(p_st, &p_ed->tag.name, &p_ed->stack); -#if (VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(&p_ed->tag.name, dbg_name); - xml_vlist_debug_str(&p_ed->tag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("XML_TAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - -#endif - if (next != 0) - { - if (next <= XML_MAX_OBJ_TAG_ID) - p_st->obj = next; - - if(p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = next; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - } - break; - - case XML_ATTRIBUTE : /* attr-name="attr-value" */ - curr = xml_vlist_proc_attr(p_st, &p_ed->attr.name, &p_ed->stack); -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(&p_ed->attr.name, dbg_name); - xml_vlist_debug_str(&p_ed->attr.prefix, dbg_prefix); - xml_vlist_debug_str(&p_ed->attr.value, dbg_value); - XML_TRACE_DEBUG4("[xml vlist] XML_ATTRIBUTE: p:%s, name:%s, v:%s, curr:%x", - dbg_prefix, dbg_name, dbg_value, curr); -#endif - if (curr != 0) - { - if(p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = curr; - p_cp->p_data = p_ed->attr.value.p; - p_cp->len = p_ed->attr.value.len; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - p_ed->stack.top--; - } - break; - - case XML_CHARDATA : -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(&p_ed->ch_data.value, dbg_value); - XML_TRACE_DEBUG2("XML_CHARDATA: v:%s, last:%d", dbg_value, p_ed->ch_data.last); -#endif - break; - - case XML_ETAG : /* </tag-name> */ - if(p_ed->stack.top > 0) - { - p_ed->stack.stack[p_ed->stack.top] = 0; - p_ed->stack.top--; - p_st->ended = (BOOLEAN) (p_ed->stack.top == 0); - } -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(&p_ed->etag.name, dbg_name); - xml_vlist_debug_str(&p_ed->etag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("[xml vlist] XML_ETAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("[xml vlist] top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - break; - - case XML_TAG_END: /* /> */ - curr = p_ed->stack.stack[p_ed->stack.top]; - - if(p_st->prop_index <p_st->max_num_prop) - { - if(p_ed->empty_elem.end) - p_cp->name = XML_VLIST_TAG_END_ID; - else - p_cp->name = XML_VLIST_PAUSE_ID; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - if(p_ed->empty_elem.end && p_ed->stack.top > 0) - { - p_ed->stack.top--; - } - } - else - ret = FALSE; - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4("[xml vlist] XML_TAG_END: %d, top:x%x, stk:x%x, curr:x%x", - p_ed->empty_elem.end, p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top], curr); -#endif - break; - - case XML_PARTIAL: - if(p_st->p_prop[p_st->prop_index-1].name != XML_VLIST_TAG_END_ID) - { - p_ed->stack.top--; -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("[xml vlist] adjust due to XML_PARTIAL"); -#endif - } - break; - - case XML_COPY: - xml_vlist_find_ch_n_copy( &p_ed->copy ); - XML_TRACE_DEBUG1("[xml vlist] XML_COPY: %s", p_ed->copy.last.p); - break; - - default : -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("[xml vlist] XML event: %d", event); -#endif - break; - } - - return ret; -} - -/********************************************************************************** -** Function xml_vlist_int_fill_attribute -** Description fill in file/folder structure. -** -** Parameters -** Returns xx: > 0 : number of properties scanned, folder entry is added -** = 0 : no end tag found, carry over to next parse -** = -1: no dst_resource avaibale, all prop left to next parse -** = -2: exceed max entry, no folder entry added -**********************************************************************************/ -static INT16 xml_vlist_int_fill_attribute(tXML_VLIST_STATE * p_xud, - tXML_PROP *p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - INT16 xx; - UINT16 len; - BOOLEAN end = FALSE; - tXML_PROP *cur_prop = p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - for(xx=0; (xx < *num_prop) && !end; xx++, cur_prop++) - { -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG5( "[xml vlist] fill: num_prop:%d, name id: x%x, p_prop: x%x, p_data:%s, len: %d", - (*num_prop-xx) , cur_prop->name, cur_prop, cur_prop->p_data, cur_prop->len); -#endif - switch (cur_prop->name) - { - case XML_NAME_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - /* calculate the max length to copy */ - len = (cur_prop->len<=p_xud->max_name_len) ? cur_prop->len:p_xud->max_name_len; - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_xud->p_entry[p_xud->current_entry].name = p_cur_offset; - p_xud->p_entry[p_xud->current_entry].name_len = len; - - memcpy( (void *)p_xud->p_entry[p_xud->current_entry].name, - (const void *)cur_prop->p_data, - len ); - p_xud->p_entry[p_xud->current_entry].name[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG3("[xml vlist]: catch filename [%s] len [%d] dst_len left:[%d]", - p_xud->p_entry[p_xud->current_entry].name, - len, - *dst_len); -#endif - } - else /* run out of dst buffer resource */ - { - xx = -1; - return xx; - } - } - else /* exceed max entry */ - return -2; - - break; - - case XML_HANDLE_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - /* as long as we do not exceed the number of entries in the ouput array copy name */ - /* calculate the max length to copy */ - len = (cur_prop->len<=p_xud->max_name_len) ? cur_prop->len:p_xud->max_name_len; - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_xud->p_entry[p_xud->current_entry].handle = p_cur_offset; - p_xud->p_entry[p_xud->current_entry].handle_len = len; - - memcpy( (void *)p_xud->p_entry[p_xud->current_entry].handle, - (const void *)cur_prop->p_data, - len ); - p_xud->p_entry[p_xud->current_entry].handle[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG3("[xml vlist]: catch filename [%s] len [%d] dst_len left:[%d]", - p_xud->p_entry[p_xud->current_entry].handle, - len, - *dst_len); -#endif - } - else /* run out of dst buffer resource */ - { - xx = -1; - return xx; - } - } - else /* exceed max entry */ - return -2; - - break; - - case XML_VLIST_TAG_END_ID: - /* -------------------- CUSTOMER SPECIFIC ---------------------- */ - p_xud->current_entry++; /* increment only when end tag (/>) found */ - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1( "[xml vlist] FOUND END TAG: 0x%x", cur_prop->name ); -#endif - - end = TRUE; - break; - - default: - XML_TRACE_DEBUG1("[xml vlist] unknown attrib: %d", cur_prop->name ); - break; - } - } -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("[xml vlist] fill_attribute: end:%d, xx:%d", end, xx); -#endif -#if 0 - /* if end tag not found -> split over two buffers. but parser will still show rest of - found properties. so return still found properties. */ - if(end == FALSE) - xx = 0; -#endif - - /* keep track of current data buffer offset */ - *p_dst_data = p_cur_offset; - return xx; -} - - -/********************************************************************************** -** Function xml_vlist_int_fill_evt_data -** -** Description fill in file/folder structure. -** -** Parameters -** Returns -**********************************************************************************/ -static tXML_VLIST_RES xml_vlist_int_fill_evt_data( UINT8 op, - void *p_evt_data, - tXML_PROP **p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - tXML_VLIST_STATE *p_xud = (tXML_VLIST_STATE *)p_evt_data; - INT16 inc_prop; - UINT8 prop_name; /* Property name. */ - tXML_PROP *cur_prop = *p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - tXML_VLIST_RES x_res = XML_VLIST_OK; - BOOLEAN x_no_res = FALSE; /* guard dest buffer resource */ - - - if ( op == 0 || op > XML_MAX_OBJ_TAG_ID || *num_prop == 0) - return XML_VLIST_ERROR; - -#if VLIST_DEBUG_XML - XML_TRACE_DEBUG2( "[xml vlist] xml_vlist_int_fill_evt_data op:%d, num_prop:%d", - op, *num_prop); -#endif - - - - while ( *num_prop > 0 && !x_no_res ) - { -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("end_prop:%d, name id: x%x", *num_prop, cur_prop->name); -#endif - prop_name = cur_prop->name; - cur_prop++; - *num_prop -= 1; - - - switch( prop_name ) - { - case XML_VLIST_ELEM_ID: - /* skip over version attribute which should always be 1.0. this is the top level */ - break; - - case XML_CARD_ELEM_ID: - inc_prop = xml_vlist_int_fill_attribute(p_xud, - cur_prop, - num_prop, - &p_cur_offset, - dst_len); - if (inc_prop == -1) /* no dst_buf available */ - { - /* backup one more prop to obtain the skipped folder/file entry header */ - cur_prop --; - *num_prop += 1; - - x_res = XML_VLIST_DST_NO_RES; - x_no_res = TRUE; - } - else if (inc_prop == -2) /* exceed max entry */ - { - x_no_res = TRUE; - x_res = XML_VLIST_OUT_FULL; - } - else /* found folder entry */ - { - cur_prop += inc_prop; - *num_prop -= inc_prop; - } - break; - - - case XML_VLIST_PAUSE_ID: - -#if (VLIST_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml vlist] xml_vlist_int_fill_evt_data(): XML_VLIST_PAUSE_ID" ); -#endif - break; - - case XML_VLIST_TAG_END_ID: -#if (VLIST_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml vlist] xml_vlist_int_fill_evt_data(): XML_VLIST_TAG_END_ID" ); -#endif - break; - - default: - XML_TRACE_DEBUG1( "[xml vlist] xml_vlist_int_fill_evt_data():unknown element: %d", prop_name ); - break; - } - } - - /* keep track of current filling position, and current available dst buffer */ - *p_prop = cur_prop; - *p_dst_data = p_cur_offset; - - return x_res; -} - - -/************************************************************************************** -** Function XML_VlistInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of an xml parser state machine to be initialized, -** allocate an additional space of size XML_VLIST_CARRY_OVER_LEN -** right after *p_xml_state to hold carry over data. -** p_entry : points start of output vlist entry. caller needs do -** free this memory -** max_entry : max is 16 bit integer value which is the maximum number -** of folder entries. - -** -** Returns void -**************************************************************************************/ - -void XML_VlistInit( tXML_VLIST_PARSER *p_xml_state, - tXML_VLIST_ENTRY *p_entry, - const UINT16 max_entry ) -{ - /* Initialize the generic xml parser state machine.*/ - XML_InitPars( &p_xml_state->xml, xml_vlist_cback, &p_xml_state->xml_user_data ); - - /* User need to allocate an additional space of size XML_VLIST_CARRY_OVER_LEN */ - /* right after *p_xml_state to hold carry over data. */ - /* point to the end of the allocated buffer for p_xml_state, which is the */ - /* beginning of buffer(XML_VLIST_CARRY_OVER_LEN) */ - p_xml_state->xml.last_bfr.p = (UINT8 *)(p_xml_state + 1); - p_xml_state->xml.last_bfr.len = XML_VLIST_CARRY_OVER_LEN; - - /* Initialize user data */ - p_xml_state->xml_user_data.p_entry = p_entry; - p_xml_state->xml_user_data.current_entry = 0; - p_xml_state->xml_user_data.max_name_len = XML_UI_ENTRY_MAX_NAME_LEN + 1; - p_xml_state->xml_user_data.max_entry = (UINT16)max_entry; - p_xml_state->xml_user_data.prop_num = 0; -} - - -/************************************************************************************** -** Function XML_VlistParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_VlistInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. - When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: pointer to the length of dst_data buffer, its carry out value -** is the number of bytes remaining buffer.When dst_len is NULL, -** it will cause to flush the internal data in the parser. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_VLIST_RES (see xml_vlist_api.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /VCard-listing but no final flag detected -** XML_VLIST_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_VLIST_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -tXML_VLIST_RES XML_VlistParse( tXML_VLIST_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ) -{ - tXML_OS xos; - BOOLEAN is_remain = TRUE; - tXML_MUL_STATE *p_xml = &p_xml_state->xml; - tXML_VLIST_STATE *p_st = &p_xml_state->xml_user_data; - tXML_VLIST_RES x_res = XML_VLIST_OK; - tXML_RESULT res = XML_NO_PROP; - UINT16 max_num_prop = GKI_BUF3_SIZE/sizeof(tXML_PROP); /* i hope this is sufficient for 1 */ - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - int xx; - UINT8 dbg_buf[VLIST_DEBUG_LEN]; - tXML_STR str; -#endif - - /* if dst_data is NULL, clean up remaining data */ - if (!dst_data || !dst_len) - { - /* clean out remained xml data left over from last parse */ - if (p_xml_state->xml_user_data.p_prop ) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = p_st->offset_prop = NULL; - p_st->prop_num = 0; - } -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml vlist] XML_VlistParse() Clean up left over!"); -#endif - return x_res; - } - - /* if illegal OBEX data or dst buffer pointer received, return ERROR */ - if (xml_len == 0 || !xml_data) - { - return XML_VLIST_ERROR; - } - - /* XML_VlistParse receive new xml data, allocate buffer to hold parsed prop */ - if (p_st->offset_prop == NULL) - { - -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml vlist] XML_VlistParse() Receive New Data!"); - XML_TRACE_DEBUG2( "[xml vlist] XML_data start[%x] end [%x]",xml_data, xml_data+xml_len); -#endif - is_remain = FALSE; - if ( NULL!= (p_st->p_prop = (tXML_PROP *)GKI_getbuf( GKI_BUF3_SIZE ) ) ) - { - xos.p_begin = xml_data; - xos.p_end = xml_data + xml_len; - /* pointing next prop to be converted into file entry */ - p_st->prop_num = 0; - } - else - { - GKI_freebuf( p_xml_state ); - x_res = XML_VLIST_NO_RES; - return x_res; - } - } -#if (VLIST_DEBUG_XML == TRUE) - else - { - XML_TRACE_DEBUG0( "[xml vlist] XML_VlistParse(): Keep cleaning up old xml data !"); - } -#endif - - while( res == XML_NO_PROP ) - { - /* if no remaining data in p_st->p_prop, parse new xml data */ - if (!is_remain) - { - p_st->max_num_prop = max_num_prop; - p_st->prop_index = 0; - res = XML_MulParse( p_xml, &xos ); - - -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4( "xml_vlist_parse obj: %x, max: %d, num: %d, res: %d", - p_st->obj, max_num_prop, p_st->prop_index, res); - - if (res != 0) - { - XML_TRACE_DEBUG1( "XML_MulParse Parsing: %d !!!", res); - } - - for(xx=0; xx<p_st->prop_index; xx++) - { - if ( p_st->p_prop[xx].name < XML_VLIST_MAX_ID ) - { - str.p = p_st->p_prop[xx].p_data; - str.len = p_st->p_prop[xx].len; - xml_vlist_debug_str(&str, dbg_buf); - XML_TRACE_DEBUG5( "[xml vlist] parsed: index[%d]:%d:%s: %s(%d)", p_st->prop_index-xx, p_st->p_prop[xx].level, - xml_vlist_ttbl[p_st->p_prop[xx].name].p_name, dbg_buf, p_st->p_prop[xx].len); - } - else - { - XML_TRACE_DEBUG3( "[xml vlist] internal prop: %d:%d:%d", xx, p_st->p_prop[xx].level, - p_st->p_prop[xx].name ); - } - } -#endif - p_st->prop_num = p_st->prop_index ; - p_st->offset_prop = p_st->p_prop; - } - else - { - /* This is left over data, pick up the result from the previous parse */ - res = p_xml->pars_res; - } - - if ( res != XML_OBJ_ST_EMPTY ) - { - x_res = xml_vlist_int_fill_evt_data( p_st->obj, p_st, &p_st->offset_prop, &p_st->prop_num, &dst_data, dst_len ); - - if ( (XML_VLIST_OK == x_res) && (XML_NO_END == res) ) - { - /* XML_NO_END means that the xml is not completly finished and fill returns - ok when when partial filling has been ok */ - x_res = XML_VLIST_PENDING; - } - - /* all parsed xml data has been converted into file entry */ - /* or exceed max entry number , break the parsing loop */ - if (XML_VLIST_OUT_FULL != x_res && XML_VLIST_DST_NO_RES != x_res) - { - is_remain = FALSE; - } - else - break; - } - } /* while */ - - /* free property table. at next call a new one is allocated */ - if ((x_res != XML_VLIST_DST_NO_RES && p_st->p_prop) || - XML_VLIST_OUT_FULL == x_res) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = NULL; - p_st->offset_prop = NULL; - } - - if ( x_res != XML_VLIST_DST_NO_RES && p_st->ended) - { - /* this should happen on the same time as final flag in fact */ - x_res = XML_VLIST_END_LIST; /* found closing /folder-listing */ - } - - - *num_entries = p_st->current_entry; /* report number of entries found. only when ended is true - application really should be interested! */ - return x_res; -} - |