static GstVaapiDecoderStatus decode_ebdu(GstVaapiDecoderVC1 *decoder, GstVC1BDU *ebdu) { GstVaapiDecoderStatus status; GstVC1BDU rbdu; if (!decode_rbdu(decoder, &rbdu, ebdu)) return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED; switch (ebdu->type) { case GST_VC1_SEQUENCE: status = decode_sequence(decoder, &rbdu, ebdu); break; case GST_VC1_ENTRYPOINT: status = decode_entry_point(decoder, &rbdu, ebdu); break; case GST_VC1_FRAME: status = decode_frame(decoder, &rbdu, ebdu); break; case GST_VC1_SLICE: GST_DEBUG("decode slice"); status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER; break; case GST_VC1_END_OF_SEQ: status = decode_sequence_end(decoder); break; default: GST_DEBUG("unsupported BDU type %d", ebdu->type); status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER; break; } return status; }
char *unbase32(cad_memory_t memory, const char *b32, size_t *len) { size_t sz = strlen(b32) * 5 / 8 + 8; size_t l = 0; char *raw = memory.malloc(sz + 1); memset(raw, 0, sz + 1); for (size_t i = 0, j = 0; ; i += 8, j += 5) { int n = decode_sequence(&b32[i], &raw[j]); l += n; if (n < 5) { break; } } assert(l <= sz); if (len != NULL) { *len = l; } return raw; }
/* * Decode SEEK request */ static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_seek_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_seek(xdr, res); out: return status; }
int main(int argc, char **argv) { int r, g, b; // parse arguments if (!parse_arguments(argc, argv, &r, &g, &b)) return -1; // Set up gpi pointer for direct register access setup_io(); // calibrate our timers calibrate(1000000); // Set GPIO pin 4 to output INP_GPIO(4); // must use INP_GPIO before we can use OUT_GPIO OUT_GPIO(4); decode_sequence(r, g, b); send_sequence(); return 0; } // main
/* Given the enclosing tag t, decode from asn1/len the contents of the ASN.1 * type specified by a, placing the result into val (caller-allocated). */ static asn1_error_code decode_atype(const taginfo *t, const unsigned char *asn1, size_t len, const struct atype_info *a, void *val) { asn1_error_code ret; switch (a->type) { case atype_fn: { const struct fn_info *fn = a->tinfo; assert(fn->dec != NULL); return fn->dec(t, asn1, len, val); } case atype_sequence: return decode_sequence(asn1, len, a->tinfo, val); case atype_ptr: { const struct ptr_info *ptrinfo = a->tinfo; void *ptr = LOADPTR(val, ptrinfo); assert(ptrinfo->basetype != NULL); if (ptr != NULL) { /* Container was already allocated by a previous sequence field. */ return decode_atype(t, asn1, len, ptrinfo->basetype, ptr); } else { ret = decode_atype_to_ptr(t, asn1, len, ptrinfo->basetype, &ptr); if (ret) return ret; STOREPTR(ptr, ptrinfo, val); break; } } case atype_offset: { const struct offset_info *off = a->tinfo; assert(off->basetype != NULL); return decode_atype(t, asn1, len, off->basetype, (char *)val + off->dataoff); } case atype_optional: { const struct optional_info *opt = a->tinfo; return decode_atype(t, asn1, len, opt->basetype, val); } case atype_counted: { const struct counted_info *counted = a->tinfo; void *dataptr = (char *)val + counted->dataoff; size_t count; assert(counted->basetype != NULL); ret = decode_cntype(t, asn1, len, counted->basetype, dataptr, &count); if (ret) return ret; return store_count(count, counted, val); } case atype_tagged_thing: { const struct tagged_info *tag = a->tinfo; taginfo inner_tag; const taginfo *tp = t; const unsigned char *rem; size_t rlen; if (!tag->implicit) { ret = get_tag(asn1, len, &inner_tag, &asn1, &len, &rem, &rlen); if (ret) return ret; /* Note: we don't check rlen (it should be 0). */ tp = &inner_tag; if (!check_atype_tag(tag->basetype, tp)) return ASN1_BAD_ID; } return decode_atype(tp, asn1, len, tag->basetype, val); } case atype_bool: { intmax_t intval; ret = k5_asn1_decode_bool(asn1, len, &intval); if (ret) return ret; return store_int(intval, a->size, val); } case atype_int: { intmax_t intval; ret = k5_asn1_decode_int(asn1, len, &intval); if (ret) return ret; return store_int(intval, a->size, val); } case atype_uint: { uintmax_t intval; ret = k5_asn1_decode_uint(asn1, len, &intval); if (ret) return ret; return store_uint(intval, a->size, val); } case atype_int_immediate: { const struct immediate_info *imm = a->tinfo; intmax_t intval; ret = k5_asn1_decode_int(asn1, len, &intval); if (ret) return ret; if (intval != imm->val && imm->err != 0) return imm->err; break; } default: /* Null-terminated sequence types are handled in decode_atype_to_ptr, * since they create variable-sized objects. */ assert(a->type != atype_nullterm_sequence_of); assert(a->type != atype_nonempty_nullterm_sequence_of); assert(a->type > atype_min); assert(a->type < atype_max); abort(); } return 0; }
/* * Encode ALLOCATE request */ static void nfs4_xdr_enc_allocate(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_falloc_args *args) { struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->falloc_fh, &hdr); encode_allocate(xdr, args, &hdr); encode_getfattr(xdr, args->falloc_bitmask, &hdr); encode_nops(&hdr); } /* * Encode DEALLOCATE request */ static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_falloc_args *args) { struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->falloc_fh, &hdr); encode_deallocate(xdr, args, &hdr); encode_getfattr(xdr, args->falloc_bitmask, &hdr); encode_nops(&hdr); } /* * Encode SEEK request */ static void nfs4_xdr_enc_seek(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_seek_args *args) { struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->sa_fh, &hdr); encode_seek(xdr, args, &hdr); encode_nops(&hdr); } /* * Encode LAYOUTSTATS request */ static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_layoutstat_args *args) { int i; struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->fh, &hdr); WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV); for (i = 0; i < args->num_dev; i++) encode_layoutstats(xdr, args, &args->devinfo[i], &hdr); encode_nops(&hdr); } static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res) { return decode_op_hdr(xdr, OP_ALLOCATE); } static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res) { return decode_op_hdr(xdr, OP_DEALLOCATE); } static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res) { int status; __be32 *p; status = decode_op_hdr(xdr, OP_SEEK); if (status) return status; p = xdr_inline_decode(xdr, 4 + 8); if (unlikely(!p)) goto out_overflow; res->sr_eof = be32_to_cpup(p++); p = xdr_decode_hyper(p, &res->sr_offset); return 0; out_overflow: print_overflow_msg(__func__, xdr); return -EIO; } static int decode_layoutstats(struct xdr_stream *xdr) { return decode_op_hdr(xdr, OP_LAYOUTSTATS); } /* * Decode ALLOCATE request */ static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_falloc_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_allocate(xdr, res); if (status) goto out; decode_getfattr(xdr, res->falloc_fattr, res->falloc_server); out: return status; } /* * Decode DEALLOCATE request */ static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_falloc_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_deallocate(xdr, res); if (status) goto out; decode_getfattr(xdr, res->falloc_fattr, res->falloc_server); out: return status; } /* * Decode SEEK request */ static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_seek_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_seek(xdr, res); out: return status; } /* * Decode LAYOUTSTATS request */ static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_layoutstat_res *res) { struct compound_hdr hdr; int status, i; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV); for (i = 0; i < res->num_dev; i++) { status = decode_layoutstats(xdr); if (status) goto out; } out: res->rpc_status = status; return status; }
/* * Encode ALLOCATE request */ static void nfs4_xdr_enc_allocate(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_falloc_args *args) { struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->falloc_fh, &hdr); encode_allocate(xdr, args, &hdr); encode_getfattr(xdr, args->falloc_bitmask, &hdr); encode_nops(&hdr); } /* * Encode COPY request */ static void nfs4_xdr_enc_copy(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_copy_args *args) { struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->src_fh, &hdr); encode_savefh(xdr, &hdr); encode_putfh(xdr, args->dst_fh, &hdr); encode_copy(xdr, args, &hdr); encode_nops(&hdr); } /* * Encode DEALLOCATE request */ static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_falloc_args *args) { struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->falloc_fh, &hdr); encode_deallocate(xdr, args, &hdr); encode_getfattr(xdr, args->falloc_bitmask, &hdr); encode_nops(&hdr); } /* * Encode SEEK request */ static void nfs4_xdr_enc_seek(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_seek_args *args) { struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->sa_fh, &hdr); encode_seek(xdr, args, &hdr); encode_nops(&hdr); } /* * Encode LAYOUTSTATS request */ static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_layoutstat_args *args) { int i; struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->fh, &hdr); WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV); for (i = 0; i < args->num_dev; i++) encode_layoutstats(xdr, args, &args->devinfo[i], &hdr); encode_nops(&hdr); } /* * Encode CLONE request */ static void nfs4_xdr_enc_clone(struct rpc_rqst *req, struct xdr_stream *xdr, struct nfs42_clone_args *args) { struct compound_hdr hdr = { .minorversion = nfs4_xdr_minorversion(&args->seq_args), }; encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->src_fh, &hdr); encode_savefh(xdr, &hdr); encode_putfh(xdr, args->dst_fh, &hdr); encode_clone(xdr, args, &hdr); encode_getfattr(xdr, args->dst_bitmask, &hdr); encode_nops(&hdr); } static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res) { return decode_op_hdr(xdr, OP_ALLOCATE); } static int decode_write_response(struct xdr_stream *xdr, struct nfs42_write_res *res) { __be32 *p; p = xdr_inline_decode(xdr, 4 + 8 + 4); if (unlikely(!p)) goto out_overflow; /* * We never use asynchronous mode, so warn if a server returns * a stateid. */ if (unlikely(*p != 0)) { pr_err_once("%s: server has set unrequested " "asynchronous mode\n", __func__); return -EREMOTEIO; } p++; p = xdr_decode_hyper(p, &res->count); res->verifier.committed = be32_to_cpup(p); return decode_verifier(xdr, &res->verifier.verifier); out_overflow: print_overflow_msg(__func__, xdr); return -EIO; } static int decode_copy_requirements(struct xdr_stream *xdr, struct nfs42_copy_res *res) { __be32 *p; p = xdr_inline_decode(xdr, 4 + 4); if (unlikely(!p)) goto out_overflow; res->consecutive = be32_to_cpup(p++); res->synchronous = be32_to_cpup(p++); return 0; out_overflow: print_overflow_msg(__func__, xdr); return -EIO; } static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res) { int status; status = decode_op_hdr(xdr, OP_COPY); if (status == NFS4ERR_OFFLOAD_NO_REQS) { status = decode_copy_requirements(xdr, res); if (status) return status; return NFS4ERR_OFFLOAD_NO_REQS; } else if (status) return status; status = decode_write_response(xdr, &res->write_res); if (status) return status; return decode_copy_requirements(xdr, res); } static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res) { return decode_op_hdr(xdr, OP_DEALLOCATE); } static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res) { int status; __be32 *p; status = decode_op_hdr(xdr, OP_SEEK); if (status) return status; p = xdr_inline_decode(xdr, 4 + 8); if (unlikely(!p)) goto out_overflow; res->sr_eof = be32_to_cpup(p++); p = xdr_decode_hyper(p, &res->sr_offset); return 0; out_overflow: print_overflow_msg(__func__, xdr); return -EIO; } static int decode_layoutstats(struct xdr_stream *xdr) { return decode_op_hdr(xdr, OP_LAYOUTSTATS); } static int decode_clone(struct xdr_stream *xdr) { return decode_op_hdr(xdr, OP_CLONE); } /* * Decode ALLOCATE request */ static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_falloc_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_allocate(xdr, res); if (status) goto out; decode_getfattr(xdr, res->falloc_fattr, res->falloc_server); out: return status; } /* * Decode COPY response */ static int nfs4_xdr_dec_copy(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_copy_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_savefh(xdr); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_copy(xdr, res); out: return status; } /* * Decode DEALLOCATE request */ static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_falloc_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_deallocate(xdr, res); if (status) goto out; decode_getfattr(xdr, res->falloc_fattr, res->falloc_server); out: return status; } /* * Decode SEEK request */ static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_seek_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_seek(xdr, res); out: return status; } /* * Decode LAYOUTSTATS request */ static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_layoutstat_res *res) { struct compound_hdr hdr; int status, i; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV); for (i = 0; i < res->num_dev; i++) { status = decode_layoutstats(xdr); if (status) goto out; } out: res->rpc_status = status; return status; } /* * Decode CLONE request */ static int nfs4_xdr_dec_clone(struct rpc_rqst *rqstp, struct xdr_stream *xdr, struct nfs42_clone_res *res) { struct compound_hdr hdr; int status; status = decode_compound_hdr(xdr, &hdr); if (status) goto out; status = decode_sequence(xdr, &res->seq_res, rqstp); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_savefh(xdr); if (status) goto out; status = decode_putfh(xdr); if (status) goto out; status = decode_clone(xdr); if (status) goto out; status = decode_getfattr(xdr, res->dst_fattr, res->server); out: res->rpc_status = status; return status; }