static ssize_t sdp_attr_get(struct bt_l2cap_sdp_state_s *sdp,

                uint8_t *rsp, const uint8_t *req, ssize_t len)

{

    ssize_t seqlen;

    int i, start, end, max;

    int32_t handle;

    struct sdp_service_record_s *record;

    uint8_t *lst;



    /* Perform the search */

    if (len < 7)

        return -SDP_INVALID_SYNTAX;

    memcpy(&handle, req, 4);

    req += 4;

    len -= 4;



    if (handle < 0 || handle > sdp->services)

        return -SDP_INVALID_RECORD_HANDLE;

    record = &sdp->service_list[handle];



    for (i = 0; i < record->attributes; i ++)

        record->attribute_list[i].match = 0;



    max = (req[0] << 8) | req[1];

    req += 2;

    len -= 2;

    if (max < 0x0007)

        return -SDP_INVALID_SYNTAX;



    if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {

        seqlen = sdp_datalen(&req, &len);

        if (seqlen < 3 || len < seqlen)

            return -SDP_INVALID_SYNTAX;

        len -= seqlen;



        while (seqlen)

            if (sdp_attr_match(record, &req, &seqlen))

                return -SDP_INVALID_SYNTAX;

    } else if (sdp_attr_match(record, &req, &seqlen))

        return -SDP_INVALID_SYNTAX;



    if (len < 1)

        return -SDP_INVALID_SYNTAX;



    if (*req) {

        if (len <= sizeof(int))

            return -SDP_INVALID_SYNTAX;

        len -= sizeof(int);

        memcpy(&start, req + 1, sizeof(int));

    } else

        start = 0;



    if (len > 1)

        return -SDP_INVALID_SYNTAX;



    /* Output the results */

    lst = rsp + 2;

    max = MIN(max, MAX_RSP_PARAM_SIZE);

    len = 3 - start;

    end = 0;

    for (i = 0; i < record->attributes; i ++)

        if (record->attribute_list[i].match) {

            if (len >= 0 && len + record->attribute_list[i].len < max) {

                memcpy(lst + len, record->attribute_list[i].pair,

                                record->attribute_list[i].len);

                end = len + record->attribute_list[i].len;

            }

            len += record->attribute_list[i].len;

        }

    if (0 >= start) {

       lst[0] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;

       lst[1] = (len + start - 3) >> 8;

       lst[2] = (len + start - 3) & 0xff;

    }



    rsp[0] = end >> 8;

    rsp[1] = end & 0xff;



    if (end < len) {

        len = end + start;

        lst[end ++] = sizeof(int);

        memcpy(lst + end, &len, sizeof(int));

        end += sizeof(int);

    } else

        lst[end ++] = 0;



    return end + 2;

}

static ssize_t sdp_attr_get(struct bt_l2cap_sdp_state_s *sdp,

                uint8_t *rsp, const uint8_t *req, ssize_t len)

{

    ssize_t seqlen;

    int i, start, end, max;

    int32_t handle;

    struct sdp_service_record_s *record;

    uint8_t *lst;



    

    if (len < 7)

        return -SDP_INVALID_SYNTAX;

    memcpy(&handle, req, 4);

    req += 4;

    len -= 4;



    if (handle < 0 || handle > sdp->services)

        return -SDP_INVALID_RECORD_HANDLE;

    record = &sdp->service_list[handle];



    for (i = 0; i < record->attributes; i ++)

        record->attribute_list[i].match = 0;



    max = (req[0] << 8) | req[1];

    req += 2;

    len -= 2;

    if (max < 0x0007)

        return -SDP_INVALID_SYNTAX;



    if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {

        seqlen = sdp_datalen(&req, &len);

        if (seqlen < 3 || len < seqlen)

            return -SDP_INVALID_SYNTAX;

        len -= seqlen;



        while (seqlen)

            if (sdp_attr_match(record, &req, &seqlen))

                return -SDP_INVALID_SYNTAX;

    } else if (sdp_attr_match(record, &req, &seqlen))

        return -SDP_INVALID_SYNTAX;



    if (len < 1)

        return -SDP_INVALID_SYNTAX;



    if (*req) {

        if (len <= sizeof(int))

            return -SDP_INVALID_SYNTAX;

        len -= sizeof(int);

        memcpy(&start, req + 1, sizeof(int));

    } else

        start = 0;



    if (len > 1)

        return -SDP_INVALID_SYNTAX;



    

    lst = rsp + 2;

    max = MIN(max, MAX_RSP_PARAM_SIZE);

    len = 3 - start;

    end = 0;

    for (i = 0; i < record->attributes; i ++)

        if (record->attribute_list[i].match) {

            if (len >= 0 && len + record->attribute_list[i].len < max) {

                memcpy(lst + len, record->attribute_list[i].pair,

                                record->attribute_list[i].len);

                end = len + record->attribute_list[i].len;

            }

            len += record->attribute_list[i].len;

        }

    if (0 >= start) {

       lst[0] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;

       lst[1] = (len + start - 3) >> 8;

       lst[2] = (len + start - 3) & 0xff;

    }



    rsp[0] = end >> 8;

    rsp[1] = end & 0xff;



    if (end < len) {

        len = end + start;

        lst[end ++] = sizeof(int);

        memcpy(lst + end, &len, sizeof(int));

        end += sizeof(int);

    } else

        lst[end ++] = 0;



    return end + 2;

}

        return -SDP_INVALID_SYNTAX;     } else if (sdp_attr_match(record, &req, &seqlen))         return -SDP_INVALID_SYNTAX;         return -SDP_INVALID_SYNTAX;         return -SDP_INVALID_SYNTAX;
static ssize_t FUNC_0(struct bt_l2cap_sdp_state_s *sdp,

                uint8_t *rsp, const uint8_t *req, ssize_t len)

{

    ssize_t seqlen;

    int VAR_0, VAR_1, VAR_2, VAR_3;

    int32_t handle;

    struct sdp_service_record_s *VAR_4;

    uint8_t *lst;



    

    if (len < 7)

        return -SDP_INVALID_SYNTAX;

    memcpy(&handle, req, 4);

    req += 4;

    len -= 4;



    if (handle < 0 || handle > sdp->services)

        return -SDP_INVALID_RECORD_HANDLE;

    VAR_4 = &sdp->service_list[handle];



    for (VAR_0 = 0; VAR_0 < VAR_4->attributes; VAR_0 ++)

        VAR_4->attribute_list[VAR_0].match = 0;



    VAR_3 = (req[0] << 8) | req[1];

    req += 2;

    len -= 2;

    if (VAR_3 < 0x0007)

        return -SDP_INVALID_SYNTAX;



    if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {

        seqlen = sdp_datalen(&req, &len);

        if (seqlen < 3 || len < seqlen)

            return -SDP_INVALID_SYNTAX;

        len -= seqlen;



        while (seqlen)

            if (sdp_attr_match(VAR_4, &req, &seqlen))

                return -SDP_INVALID_SYNTAX;

    } else if (sdp_attr_match(VAR_4, &req, &seqlen))

        return -SDP_INVALID_SYNTAX;



    if (len < 1)

        return -SDP_INVALID_SYNTAX;



    if (*req) {

        if (len <= sizeof(int))

            return -SDP_INVALID_SYNTAX;

        len -= sizeof(int);

        memcpy(&VAR_1, req + 1, sizeof(int));

    } else

        VAR_1 = 0;



    if (len > 1)

        return -SDP_INVALID_SYNTAX;



    

    lst = rsp + 2;

    VAR_3 = MIN(VAR_3, MAX_RSP_PARAM_SIZE);

    len = 3 - VAR_1;

    VAR_2 = 0;

    for (VAR_0 = 0; VAR_0 < VAR_4->attributes; VAR_0 ++)

        if (VAR_4->attribute_list[VAR_0].match) {

            if (len >= 0 && len + VAR_4->attribute_list[VAR_0].len < VAR_3) {

                memcpy(lst + len, VAR_4->attribute_list[VAR_0].pair,

                                VAR_4->attribute_list[VAR_0].len);

                VAR_2 = len + VAR_4->attribute_list[VAR_0].len;

            }

            len += VAR_4->attribute_list[VAR_0].len;

        }

    if (0 >= VAR_1) {

       lst[0] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;

       lst[1] = (len + VAR_1 - 3) >> 8;

       lst[2] = (len + VAR_1 - 3) & 0xff;

    }



    rsp[0] = VAR_2 >> 8;

    rsp[1] = VAR_2 & 0xff;



    if (VAR_2 < len) {

        len = VAR_2 + VAR_1;

        lst[VAR_2 ++] = sizeof(int);

        memcpy(lst + VAR_2, &len, sizeof(int));

        VAR_2 += sizeof(int);

    } else

        lst[VAR_2 ++] = 0;



    return VAR_2 + 2;

}

static ssize_t FUNC_0(struct bt_l2cap_sdp_state_s *sdp,
uint8_t *rsp, const uint8_t *req, ssize_t len)
{ ssize_t seqlen; int VAR_0, VAR_1, VAR_2, VAR_3; int32_t handle; struct sdp_service_record_s *VAR_4; uint8_t *lst; if (len < 7)
return -SDP_INVALID_SYNTAX; memcpy(&handle, req, 4); req += 4; len -= 4; if (handle < 0 || handle > sdp->services)
return -SDP_INVALID_RECORD_HANDLE; VAR_4 = &sdp->service_list[handle]; for (VAR_0 = 0; VAR_0 < VAR_4->attributes; VAR_0 ++) VAR_4->attribute_list[VAR_0].match = 0; VAR_3 = (req[0] << 8) | req[1]; req += 2; len -= 2; if (VAR_3 < 0x0007)
return -SDP_INVALID_SYNTAX; if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) { seqlen = sdp_datalen(&req, &len); if (seqlen < 3 || len < seqlen)
return -SDP_INVALID_SYNTAX; len -= seqlen; while (seqlen)
if (sdp_attr_match(VAR_4, &req, &seqlen))
return -SDP_INVALID_SYNTAX; } else if (sdp_attr_match(VAR_4, &req, &seqlen)) return -SDP_INVALID_SYNTAX; if (len < 1)
return -SDP_INVALID_SYNTAX; if (*req) { if (len <= sizeof(int))
return -SDP_INVALID_SYNTAX; len -= sizeof(int); memcpy(&VAR_1, req + 1, sizeof(int)); } else VAR_1 = 0; if (len > 1)
return -SDP_INVALID_SYNTAX; lst = rsp + 2; VAR_3 = MIN(VAR_3, MAX_RSP_PARAM_SIZE); len = 3 - VAR_1; VAR_2 = 0; for (VAR_0 = 0; VAR_0 < VAR_4->attributes; VAR_0 ++) if (VAR_4->attribute_list[VAR_0].match) { if (len >= 0 && len + VAR_4->attribute_list[VAR_0].len < VAR_3) { memcpy(lst + len, VAR_4->attribute_list[VAR_0].pair,
VAR_4->attribute_list[VAR_0].len); VAR_2 = len + VAR_4->attribute_list[VAR_0].len; } len += VAR_4->attribute_list[VAR_0].len; } if (0 >= VAR_1) { lst[0] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2; lst[1] = (len + VAR_1 - 3) >> 8; lst[2] = (len + VAR_1 - 3) & 0xff; } rsp[0] = VAR_2 >> 8; rsp[1] = VAR_2 & 0xff; if (VAR_2 < len) { len = VAR_2 + VAR_1; lst[VAR_2 ++] = sizeof(int); memcpy(lst + VAR_2, &len, sizeof(int)); VAR_2 += sizeof(int); } else lst[VAR_2 ++] = 0; return VAR_2 + 2; }