/* Note: check_ucp is called only with a buffer of at least LEN+2 bytes. IOW: The buffer should contain a complete UCP PDU  */
static int check_ucp(tvbuff_t *tvb, int *endpkt)
/* Note: check_ucp is called only with a buffer of at least LEN+2 bytes. IOW: The buffer should contain a complete UCP PDU  */
static int check_ucp(tvbuff_t *tvb, int *endpkt)
{
    guint        offset = 1;
    guint        checksum = 0;
    int          pkt_check, tmp;
    int          length;
    length = tvb_find_guint8(tvb, offset, -1, UCP_ETX);
    if (length == -1) {
        *endpkt = tvb_reported_length_remaining(tvb, offset);
        return UCP_MALFORMED;
    }
    for (; offset < (guint) (length - 2); offset++)
        checksum += tvb_get_guint8(tvb, offset);
    checksum &= 0xFF;
    tmp = tvb_get_guint8(tvb, offset++);
    pkt_check = AHex2Bin(tmp);
    tmp = tvb_get_guint8(tvb, offset++);
    pkt_check = 16 * pkt_check + AHex2Bin(tmp);
    *endpkt = offset + 1;
    if (checksum == (guint) pkt_check)
        return 0;
    else
        return UCP_INV_CHK;
}