static ssize_t sdp_svc_search(struct bt_l2cap_sdp_state_s *sdp,

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

{

    ssize_t seqlen;

    int i, count, start, end, max;

    int32_t handle;



    /* Perform the search */

    for (i = 0; i < sdp->services; i ++)

        sdp->service_list[i].match = 0;



    if (len < 1)

        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_svc_match(sdp, &req, &seqlen))

                return -SDP_INVALID_SYNTAX;

    } else if (sdp_svc_match(sdp, &req, &seqlen))

        return -SDP_INVALID_SYNTAX;



    if (len < 3)

        return -SDP_INVALID_SYNTAX;

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

    req += 2;

    len -= 2;



    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 */

    len = 4;

    count = 0;

    end = start;

    for (i = 0; i < sdp->services; i ++)

        if (sdp->service_list[i].match) {

            if (count >= start && count < max && len + 4 < MAX_RSP_PARAM_SIZE) {

                handle = i;

                memcpy(rsp + len, &handle, 4);

                len += 4;

                end = count + 1;

            }



            count ++;

        }



    rsp[0] = count >> 8;

    rsp[1] = count & 0xff;

    rsp[2] = (end - start) >> 8;

    rsp[3] = (end - start) & 0xff;



    if (end < count) {

        rsp[len ++] = sizeof(int);

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

        len += 4;

    } else

        rsp[len ++] = 0;



    return len;

}

static ssize_t sdp_svc_search(struct bt_l2cap_sdp_state_s *sdp,

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

{

    ssize_t seqlen;

    int i, count, start, end, max;

    int32_t handle;



    

    for (i = 0; i < sdp->services; i ++)

        sdp->service_list[i].match = 0;



    if (len < 1)

        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_svc_match(sdp, &req, &seqlen))

                return -SDP_INVALID_SYNTAX;

    } else if (sdp_svc_match(sdp, &req, &seqlen))

        return -SDP_INVALID_SYNTAX;



    if (len < 3)

        return -SDP_INVALID_SYNTAX;

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

    req += 2;

    len -= 2;



    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;



    

    len = 4;

    count = 0;

    end = start;

    for (i = 0; i < sdp->services; i ++)

        if (sdp->service_list[i].match) {

            if (count >= start && count < max && len + 4 < MAX_RSP_PARAM_SIZE) {

                handle = i;

                memcpy(rsp + len, &handle, 4);

                len += 4;

                end = count + 1;

            }



            count ++;

        }



    rsp[0] = count >> 8;

    rsp[1] = count & 0xff;

    rsp[2] = (end - start) >> 8;

    rsp[3] = (end - start) & 0xff;



    if (end < count) {

        rsp[len ++] = sizeof(int);

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

        len += 4;

    } else

        rsp[len ++] = 0;



    return len;

}

    } else if (sdp_svc_match(sdp, &req, &seqlen))         return -SDP_INVALID_SYNTAX;         return -SDP_INVALID_SYNTAX;     } else if (sdp_svc_match(sdp, &req, &seqlen))         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, VAR_4;

    int32_t handle;



    

    for (VAR_0 = 0; VAR_0 < sdp->services; VAR_0 ++)

        sdp->service_list[VAR_0].match = 0;



    if (len < 1)

        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_svc_match(sdp, &req, &seqlen))

                return -SDP_INVALID_SYNTAX;

    } else if (sdp_svc_match(sdp, &req, &seqlen))

        return -SDP_INVALID_SYNTAX;



    if (len < 3)

        return -SDP_INVALID_SYNTAX;

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

    req += 2;

    len -= 2;



    if (*req) {

        if (len <= sizeof(int))

            return -SDP_INVALID_SYNTAX;

        len -= sizeof(int);

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

    } else

        VAR_2 = 0;



    if (len > 1)

        return -SDP_INVALID_SYNTAX;



    

    len = 4;

    VAR_1 = 0;

    VAR_3 = VAR_2;

    for (VAR_0 = 0; VAR_0 < sdp->services; VAR_0 ++)

        if (sdp->service_list[VAR_0].match) {

            if (VAR_1 >= VAR_2 && VAR_1 < VAR_4 && len + 4 < MAX_RSP_PARAM_SIZE) {

                handle = VAR_0;

                memcpy(rsp + len, &handle, 4);

                len += 4;

                VAR_3 = VAR_1 + 1;

            }



            VAR_1 ++;

        }



    rsp[0] = VAR_1 >> 8;

    rsp[1] = VAR_1 & 0xff;

    rsp[2] = (VAR_3 - VAR_2) >> 8;

    rsp[3] = (VAR_3 - VAR_2) & 0xff;



    if (VAR_3 < VAR_1) {

        rsp[len ++] = sizeof(int);

        memcpy(rsp + len, &VAR_3, sizeof(int));

        len += 4;

    } else

        rsp[len ++] = 0;



    return len;

}

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, VAR_4; int32_t handle; for (VAR_0 = 0; VAR_0 < sdp->services; VAR_0 ++) sdp->service_list[VAR_0].match = 0; if (len < 1)
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_svc_match(sdp, &req, &seqlen))
return -SDP_INVALID_SYNTAX; } else if (sdp_svc_match(sdp, &req, &seqlen)) return -SDP_INVALID_SYNTAX; if (len < 3)
return -SDP_INVALID_SYNTAX; VAR_4 = (req[0] << 8) | req[1]; req += 2; len -= 2; if (*req) { if (len <= sizeof(int))
return -SDP_INVALID_SYNTAX; len -= sizeof(int); memcpy(&VAR_2, req + 1, sizeof(int)); } else VAR_2 = 0; if (len > 1)
return -SDP_INVALID_SYNTAX; len = 4; VAR_1 = 0; VAR_3 = VAR_2; for (VAR_0 = 0; VAR_0 < sdp->services; VAR_0 ++) if (sdp->service_list[VAR_0].match) { if (VAR_1 >= VAR_2 && VAR_1 < VAR_4 && len + 4 < MAX_RSP_PARAM_SIZE) { handle = VAR_0; memcpy(rsp + len, &handle, 4); len += 4; VAR_3 = VAR_1 + 1; } VAR_1 ++; } rsp[0] = VAR_1 >> 8; rsp[1] = VAR_1 & 0xff; rsp[2] = (VAR_3 - VAR_2) >> 8; rsp[3] = (VAR_3 - VAR_2) & 0xff; if (VAR_3 < VAR_1) { rsp[len ++] = sizeof(int); memcpy(rsp + len, &VAR_3, sizeof(int)); len += 4; } else rsp[len ++] = 0; return len; }