Beispiel #1
0
static void set_mode_compression(struct scsi_cmd *cmd, uint8_t *p)
{
	struct lu_phy_attr *lu = cmd->lu;
	struct priv_lu_ssc *lu_priv = lu->lu_private;
	struct ssc_personality_template *pm;
	int dce;

	pm = lu_priv->pm;
	dce = p[2] & 0x80;

	MHVTL_DBG(2, " Data Compression Enable   : %s (0x%02x)",
				(p[1] & 0x80) ? "Yes" : "No", p[1]);
	MHVTL_DBG(2, " Data Compression Capable  : %s",
				(p[1] & 0x40) ? "Yes" : "No");
	MHVTL_DBG(2, " Data DeCompression Enable : %s (0x%02x)",
				(p[2] & 0x80) ? "Yes" : "No", p[2]);
	MHVTL_DBG(2, " Compression Algorithm     : 0x%04x",
				get_unaligned_be32(&p[4]));
	MHVTL_DBG(2, " DeCompression Algorithm   : 0x%04x",
				get_unaligned_be32(&p[8]));
	MHVTL_DBG(2, " Report Exception on Decompression: 0x%02x",
				(p[3] & 0x6) >> 5);

	if (dce) { /* Data Compression Enable bit set */
		MHVTL_DBG(1, " Setting compression");
		if (pm->set_compression)
			pm->set_compression(&lu->mode_pg,
					lu_priv->configCompressionFactor);
	} else {
		MHVTL_DBG(1, " Clearing compression");
		if (pm->clear_compression)
			pm->clear_compression(&lu->mode_pg);
	}
}
Beispiel #2
0
int extract_subprogram(u8 **progdata, u32 expected_magic,
		       struct key_program **result)
{
	struct key_program *prog = *result;
	u32 magic, code_crc, code_size;

	magic = get_unaligned_be32(*progdata);
	code_crc = get_unaligned_be32(*progdata + 4);
	code_size = get_unaligned_be32(*progdata + 8);

	*progdata += 12;

	if (magic != expected_magic)
		return -1;

	*result = malloc(sizeof(struct key_program) + code_size);

	if (!*result)
		return -1;

	prog->magic = magic;
	prog->code_crc = code_crc;
	prog->code_size = code_size;
	memcpy(prog->code, *progdata, code_size);

	*progdata += code_size;

	if (hre_verify_program(prog)) {
		free(prog);
		return -1;
	}

	return 0;
}
/**
 * ldm_parse_vmdb - Read the LDM Database VMDB structure
 * @data:  Raw database VMDB structure loaded from the device
 * @vm:    In-memory vmdb structure in which to return parsed information
 *
 * This parses the LDM Database VMDB structure supplied in @data and sets up
 * the in-memory vmdb structure @vm with the obtained information.
 *
 * N.B.  The *_start, *_size and *_seq values will be range-checked later.
 *
 * Return:  'true'   @vm contains VMDB info
 *          'false'  @vm contents are undefined
 */
static bool ldm_parse_vmdb (const u8 *data, struct vmdb *vm)
{
	BUG_ON (!data || !vm);

	if (MAGIC_VMDB != get_unaligned_be32(data)) {
		ldm_crit ("Cannot find the VMDB, database may be corrupt.");
		return false;
	}

	vm->ver_major = get_unaligned_be16(data + 0x12);
	vm->ver_minor = get_unaligned_be16(data + 0x14);
	if ((vm->ver_major != 4) || (vm->ver_minor != 10)) {
		ldm_error ("Expected VMDB version %d.%d, got %d.%d. "
			"Aborting.", 4, 10, vm->ver_major, vm->ver_minor);
		return false;
	}

	vm->vblk_size     = get_unaligned_be32(data + 0x08);
	if (vm->vblk_size == 0) {
		ldm_error ("Illegal VBLK size");
		return false;
	}

	vm->vblk_offset   = get_unaligned_be32(data + 0x0C);
	vm->last_vblk_seq = get_unaligned_be32(data + 0x04);

	ldm_debug ("Parsed VMDB successfully.");
	return true;
}
Beispiel #4
0
int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
	uint8_t *recvbuf, size_t *recv_size)
{
	struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
	struct tpm_ops *ops = tpm_get_ops(dev);
	ulong start, stop;
	uint count, ordinal;
	int ret, ret2;

	if (ops->xfer)
		return ops->xfer(dev, sendbuf, send_size, recvbuf, recv_size);

	if (!ops->send || !ops->recv)
		return -ENOSYS;

	/* switch endianess: big->little */
	count = get_unaligned_be32(sendbuf + TPM_CMD_COUNT_BYTE);
	ordinal = get_unaligned_be32(sendbuf + TPM_CMD_ORDINAL_BYTE);

	if (count == 0) {
		debug("no data\n");
		return -ENODATA;
	}
	if (count > send_size) {
		debug("invalid count value %x %zx\n", count, send_size);
		return -E2BIG;
	}

	debug("%s: Calling send\n", __func__);
	ret = ops->send(dev, sendbuf, send_size);
	if (ret < 0)
		return ret;

	start = get_timer(0);
	stop = tpm_tis_i2c_calc_ordinal_duration(priv, ordinal);
	do {
		ret = ops->recv(dev, priv->buf, sizeof(priv->buf));
		if (ret >= 0) {
			if (ret > *recv_size)
				return -ENOSPC;
			memcpy(recvbuf, priv->buf, ret);
			*recv_size = ret;
			ret = 0;
			break;
		} else if (ret != -EAGAIN) {
			return ret;
		}

		mdelay(priv->retry_time_ms);
		if (get_timer(start) > stop) {
			ret = -ETIMEDOUT;
			break;
		}
	} while (ret);

	ret2 = ops->cleanup ? ops->cleanup(dev) : 0;

	return ret2 ? ret2 : ret;
}
Beispiel #5
0
/*
 * @pi must be allocated previously
 * @skb is the buffer passed to the filter
 */
static inline int getPacketInfo(const struct sk_buff *skb, struct packetInfo *src_pi, struct packetInfo *dst_pi)
{
	u32 tmp;
	void *ptr;
	u32 X;

	ptr = load_pointer(skb,23,1,&tmp);
	if(ptr != NULL)
	{
		src_pi->protocol = *(u8 *)ptr;
		dst_pi->protocol = *(u8 *)ptr;
	}else goto out;

	ptr = load_pointer(skb,26,4,&tmp);
	if(ptr !=NULL)
	{
		src_pi->address = get_unaligned_be32(ptr);
	}else goto out;

	ptr = load_pointer(skb,30,4,&tmp);
	if(ptr != NULL)
	{
		dst_pi->address = get_unaligned_be32(ptr);
	}else goto out;

	ptr = load_pointer(skb,14,1,&tmp);
	if(ptr != NULL)
	{
		X = (*(u8 *)ptr & 0xf) << 2;
		X+=14;
		ptr = load_pointer(skb,X,2,&tmp);
		if(ptr != NULL)
		{
			src_pi->port = get_unaligned_be16(ptr);
		}else goto out;

		X+=2;
		ptr = load_pointer(skb,X,2,&tmp);
		if(ptr != NULL)
		{
			dst_pi->port = get_unaligned_be16(ptr);
		}else goto out;
	}else goto out;

	return 0;

out:
	return -1;
}
static void
rk3399_vpu_jpeg_enc_set_qtable(struct rockchip_vpu_dev *vpu,
			       unsigned char *luma_qtable,
			       unsigned char *chroma_qtable)
{
	u32 reg, i;

	for (i = 0; i < VEPU_JPEG_QUANT_TABLE_COUNT; i++) {
		reg = get_unaligned_be32(&luma_qtable[i]);
		vepu_write_relaxed(vpu, reg, VEPU_REG_JPEG_LUMA_QUAT(i));

		reg = get_unaligned_be32(&chroma_qtable[i]);
		vepu_write_relaxed(vpu, reg, VEPU_REG_JPEG_CHROMA_QUAT(i));
	}
}
Beispiel #7
0
static int ratpfs_open(struct device_d __always_unused *dev,
		      FILE *file, const char *filename)
{
	int len_name = strlen(filename);
	int len_tx = 1 /* type */
		+ 4 /* flags */
		+ len_name /* path */;
	struct ratp_bb_pkt *pkt_tx = xzalloc(sizeof(*pkt_tx) + len_tx);
	struct ratp_bb_pkt *pkt_rx = NULL;
	struct ratpfs_file *rfile = xzalloc(sizeof(*rfile));
	int ret;

	pr_debug("%s: len_tx=%i filename='%s'\n", __func__, len_tx, filename);

	pkt_tx->len = len_tx;
	pkt_tx->data[0] = RATPFS_TYPE_OPEN_CALL;
	put_unaligned_be32(file->flags, &pkt_tx->data[1]);
	memcpy(&pkt_tx->data[5], filename, len_name);

	ret = barebox_ratp_fs_call(pkt_tx, &pkt_rx);
	if (ret) {
		ret = -EIO;
		goto err;
	}

	pr_debug("%s: len_rx=%i\n", __func__, pkt_rx->len);
	if (pkt_rx->len < 1 || pkt_rx->data[0] != RATPFS_TYPE_OPEN_RETURN) {
		pr_err("invalid open response\n");
		ret = -EIO;
		goto err;
	}
	rfile->handle = get_unaligned_be32(&pkt_rx->data[1]);
	if (rfile->handle == 0) {
		ret = -get_unaligned_be32(&pkt_rx->data[5]); /* errno */
		goto err;
	}
	file->priv = rfile;
	file->size = get_unaligned_be32(&pkt_rx->data[5]);

	goto out;

err:
	file->priv = NULL;
	free(rfile);
out:
	free(pkt_rx);
	return ret;
}
Beispiel #8
0
static void nps_enet_send_frame(struct net_device *ndev,
				struct sk_buff *skb)
{
	struct nps_enet_priv *priv = netdev_priv(ndev);
	u32 tx_ctrl_value = 0;
	short length = skb->len;
	u32 i, len = DIV_ROUND_UP(length, sizeof(u32));
	u32 *src = (void *)skb->data;
	bool src_is_aligned = IS_ALIGNED((unsigned long)src, sizeof(u32));

	/* In case src is not aligned we need an intermediate buffer */
	if (src_is_aligned)
		iowrite32_rep(priv->regs_base + NPS_ENET_REG_TX_BUF, src, len);
	else /* !src_is_aligned */
		for (i = 0; i < len; i++, src++)
			nps_enet_reg_set(priv, NPS_ENET_REG_TX_BUF,
					 get_unaligned_be32(src));

	/* Write the length of the Frame */
	tx_ctrl_value |= length << TX_CTL_NT_SHIFT;

	tx_ctrl_value |= NPS_ENET_ENABLE << TX_CTL_CT_SHIFT;
	/* Send Frame */
	nps_enet_reg_set(priv, NPS_ENET_REG_TX_CTL, tx_ctrl_value);
}
static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
                     const struct tcphdr *tcph, __u32 *sack)
{
	unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
	const unsigned char *ptr;
	int length = (tcph->doff*4) - sizeof(struct tcphdr);
	__u32 tmp;

	if (!length)
		return;

	ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
				 length, buff);
	BUG_ON(ptr == NULL);

	/* Fast path for timestamp-only option */
	if (length == TCPOLEN_TSTAMP_ALIGNED*4
	    && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
				       | (TCPOPT_NOP << 16)
				       | (TCPOPT_TIMESTAMP << 8)
				       | TCPOLEN_TIMESTAMP))
		return;

	while (length > 0) {
		int opcode = *ptr++;
		int opsize, i;

		switch (opcode) {
		case TCPOPT_EOL:
			return;
		case TCPOPT_NOP:	/* Ref: RFC 793 section 3.1 */
			length--;
			continue;
		default:
			opsize = *ptr++;
			if (opsize < 2) /* "silly options" */
				return;
			if (opsize > length)
				break;	/* don't parse partial options */

			if (opcode == TCPOPT_SACK
			    && opsize >= (TCPOLEN_SACK_BASE
					  + TCPOLEN_SACK_PERBLOCK)
			    && !((opsize - TCPOLEN_SACK_BASE)
				 % TCPOLEN_SACK_PERBLOCK)) {
				for (i = 0;
				     i < (opsize - TCPOLEN_SACK_BASE);
				     i += TCPOLEN_SACK_PERBLOCK) {
					tmp = get_unaligned_be32((__be32 *)(ptr+i)+1);

					if (after(tmp, *sack))
						*sack = tmp;
				}
				return;
			}
			ptr += opsize - 2;
			length -= opsize;
		}
	}
}
static int cyttsp5_check_firmware_version_builtin(struct device *dev,
		const struct firmware *fw)
{
	struct cyttsp5_loader_data *ld = cyttsp5_get_loader_data(dev);
	u32 fw_ver_new;
	u32 fw_revctrl_new;
	int upgrade;

	if (!ld->si) {
		dev_info(dev, "%s: No firmware infomation found, device FW may be corrupted\n",
			__func__);
		return CYTTSP5_AUTO_LOAD_FOR_CORRUPTED_FW;
	}

	fw_ver_new = get_unaligned_be16(fw->data + 3);
	/* 4 middle bytes are not used */
	fw_revctrl_new = get_unaligned_be32(fw->data + 9);

	upgrade = cyttsp5_check_firmware_version(dev, fw_ver_new,
			fw_revctrl_new);

	if (upgrade > 0)
		return 1;

	return 0;
}
Beispiel #11
0
/**
 * Read values defined by a type string from a buffer, and write these values
 * to environment variables.
 *
 * @param type_str	type string
 * @param data		input buffer of values
 * @param vars		names of environment variables
 * @return 0 on success, non-0 on error
 */
static int type_string_write_vars(const char *type_str, uint8_t *data,
		char * const vars[])
{
	size_t offset;
	uint32_t value;

	for (offset = 0; *type_str; type_str++, vars++) {
		switch (*type_str) {
		case 'b':
			value = data[offset];
			offset += 1;
			break;
		case 'w':
			value = get_unaligned_be16(data + offset);
			offset += 2;
			break;
		case 'd':
			value = get_unaligned_be32(data + offset);
			offset += 4;
			break;
		default:
			return -1;
		}
		if (setenv_ulong(*vars, value))
			return -1;
	}

	return 0;
}
Beispiel #12
0
uint8_t ssc_write_attributes(struct scsi_cmd *cmd)
{
	int sz;
	struct priv_lu_ssc *lu_priv;
	uint8_t *sam_stat;

	lu_priv = cmd->lu->lu_private;
	sam_stat = &cmd->dbuf_p->sam_stat;

	MHVTL_DBG(1, "Write Attributes (%ld) **", (long)cmd->dbuf_p->serialNo);

	switch (lu_priv->tapeLoaded) {
	case TAPE_UNLOADED:
		mkSenseBuf(NOT_READY, E_MEDIUM_NOT_PRESENT, sam_stat);
		return SAM_STAT_CHECK_CONDITION;
		break;
	case TAPE_LOADED:
		cmd->dbuf_p->sz = get_unaligned_be32(&cmd->scb[10]);
		sz = retrieve_CDB_data(cmd->cdev, cmd->dbuf_p);
		MHVTL_DBG(1, "  --> Expected to read %d bytes"
				", read %d", cmd->dbuf_p->sz, sz);
		if (resp_write_attribute(cmd) > 0)
			rewriteMAM(sam_stat);
		break;
	default:
		mkSenseBuf(NOT_READY, E_MEDIUM_FMT_CORRUPT, sam_stat);
		return SAM_STAT_CHECK_CONDITION;
		break;
	}
	return SAM_STAT_GOOD;
}
Beispiel #13
0
/*
 * Validate that the next four input bytes match the value of s->crc32.
 * s->pos must be zero when starting to validate the first byte.
 */
static enum xz_ret crc32_validate(struct xz_dec *s, struct xz_buf *b)
{
	if(s->crc32_temp == 0)
	{
	  GRUB_MD_CRC32->final(s->crc32_context);
		s->crc32_temp = get_unaligned_be32(GRUB_MD_CRC32->read(s->crc32_context));
	}
Beispiel #14
0
static int hfsplus_read_mdb(void *bufptr, struct hfsplus_wd *wd)
{
    u32 extent;
    u16 attrib;
    __be16 sig;

    sig = *(__be16 *)(bufptr + HFSP_WRAPOFF_EMBEDSIG);
    if (sig != cpu_to_be16(HFSPLUS_VOLHEAD_SIG) &&
            sig != cpu_to_be16(HFSPLUS_VOLHEAD_SIGX))
        return 0;

    attrib = be16_to_cpu(*(__be16 *)(bufptr + HFSP_WRAPOFF_ATTRIB));
    if (!(attrib & HFSP_WRAP_ATTRIB_SLOCK) ||
            !(attrib & HFSP_WRAP_ATTRIB_SPARED))
        return 0;

    wd->ablk_size =
        be32_to_cpu(*(__be32 *)(bufptr + HFSP_WRAPOFF_ABLKSIZE));
    if (wd->ablk_size < HFSPLUS_SECTOR_SIZE)
        return 0;
    if (wd->ablk_size % HFSPLUS_SECTOR_SIZE)
        return 0;
    wd->ablk_start =
        be16_to_cpu(*(__be16 *)(bufptr + HFSP_WRAPOFF_ABLKSTART));

    extent = get_unaligned_be32(bufptr + HFSP_WRAPOFF_EMBEDEXT);
    wd->embed_start = (extent >> 16) & 0xFFFF;
    wd->embed_count = extent & 0xFFFF;

    return 1;
}
static int cyttsp5_check_ttconfig_version_platform(struct device *dev,
		struct cyttsp5_touch_config *ttconfig)
{
	struct cyttsp5_loader_data *ld = cyttsp5_get_loader_data(dev);
	u32 fw_ver_config;
	u32 fw_revctrl_config;

	if (!ld->si) {
		dev_info(dev, "%s: No firmware infomation found, device FW may be corrupted\n",
			__func__);
		return 0;
	}

	fw_ver_config = get_unaligned_be16(ttconfig->fw_ver + 2);
	/* 4 middle bytes are not used */
	fw_revctrl_config = get_unaligned_be32(ttconfig->fw_ver + 8);

	/* FW versions should match */
	if (cyttsp5_check_firmware_version(dev, fw_ver_config,
			fw_revctrl_config)) {
		dev_err(dev, "%s: FW versions mismatch\n", __func__);
		return 0;
	}

	/* Check PowerOn Self Test, TT_CFG CRC bit */
	if ((ld->si->cydata.post_code & CY_POST_TT_CFG_CRC_MASK) == 0) {
		dev_dbg(dev, "%s: POST, TT_CFG failed (%X), will upgrade\n",
			__func__, ld->si->cydata.post_code);
		return 1;
	}

	return cyttsp5_check_ttconfig_version(dev, ttconfig->param_regs->data,
			ttconfig->param_regs->size);
}
Beispiel #16
0
static ovs_be32
get_be32(const void **pp)
{
    const ovs_be32 *p = *pp;
    ovs_be32 value = get_unaligned_be32(p);
    *pp = p + 1;
    return value;
}
void smc_eng_clk_dump(struct smc_eng_clk *tbl)
{
	u32 tmp;

	L("SMC_ENG_CLK START");

	tmp = get_unaligned_be32(&tbl->cg_eng_pll_func_ctl_0);
	L("cg_eng_pll_func_ctl_0=0x%08x",tmp);

	tmp = get_unaligned_be32(&tbl->cg_eng_pll_func_ctl_1);
	L("cg_eng_pll_func_ctl_1=0x%08x",tmp);
	
	tmp = get_unaligned_be32(&tbl->cg_eng_pll_func_ctl_2);
	L("cg_eng_pll_func_ctl_2=0x%08x",tmp);

	tmp = get_unaligned_be32(&tbl->cg_eng_pll_func_ctl_3);
	L("cg_eng_pll_func_ctl_3=0x%08x",tmp);

	tmp = get_unaligned_be32(&tbl->cg_eng_pll_ss_0);
	L("cg_eng_pll_ss_0=0x%08x",tmp);

	tmp = get_unaligned_be32(&tbl->cg_eng_pll_ss_1);
	L("cg_eng_pll_ss_1=0x%08x",tmp);

	tmp = get_unaligned_be32(&tbl->clk);
	L("clk=0x%08x",tmp);

	L("SMC_ENG_CLK END");
}
STATIC inline int INIT parse_header(u8 *input, int *skip, int in_len)
{
	int l;
	u8 *parse = input;
	u8 *end = input + in_len;
	u8 level = 0;
	u16 version;

	/*
                                                                    
                                                                 
                            
  */
	if (in_len < HEADER_SIZE_MIN)
		return 0;

	/*                          */
	for (l = 0; l < 9; l++) {
		if (*parse++ != lzop_magic[l])
			return 0;
	}
	/*                                                
                                          
               */
	version = get_unaligned_be16(parse);
	parse += 7;
	if (version >= 0x0940)
		level = *parse++;
	if (get_unaligned_be32(parse) & HEADER_HAS_FILTER)
		parse += 8; /*                     */
	else
		parse += 4; /*       */

	/*
                                                                
                                                                
                                                            
                    
  */
	if (end - parse < 8 + 1 + 4)
		return 0;

	/*                         */
	parse += 8;
	if (version >= 0x0940)
		parse += 4;	/*                 */

	l = *parse++;
	/*                                                   */
	if (end - parse < l + 4)
		return 0;
	parse += l + 4;

	*skip = parse - input;
	return 1;
}
static STATIC inline int INIT parse_header(u8 *input, int *skip, int in_len)
{
	int l;
	u8 *parse = input;
	u8 *end = input + in_len;
	u8 level = 0;
	u16 version;

	/*
	 * Check that there's enough input to possibly have a valid header.
	 * Then it is possible to parse several fields until the minimum
	 * size may have been used.
	 */
	if (in_len < HEADER_SIZE_MIN)
		return 0;

	/* read magic: 9 first bits */
	for (l = 0; l < 9; l++) {
		if (*parse++ != lzop_magic[l])
			return 0;
	}
	/* get version (2bytes), skip library version (2),
	 * 'need to be extracted' version (2) and
	 * method (1) */
	version = get_unaligned_be16(parse);
	parse += 7;
	if (version >= 0x0940)
		level = *parse++;
	if (get_unaligned_be32(parse) & HEADER_HAS_FILTER)
		parse += 8; /* flags + filter info */
	else
		parse += 4; /* flags */

	/*
	 * At least mode, mtime_low, filename length, and checksum must
	 * be left to be parsed. If also mtime_high is present, it's OK
	 * because the next input buffer check is after reading the
	 * filename length.
	 */
	if (end - parse < 8 + 1 + 4)
		return 0;

	/* skip mode and mtime_low */
	parse += 8;
	if (version >= 0x0940)
		parse += 4;	/* skip mtime_high */

	l = *parse++;
	/* don't care about the file name, and skip checksum */
	if (end - parse < l + 4)
		return 0;
	parse += l + 4;

	*skip = parse - input;
	return 1;
}
Beispiel #20
0
/*
 * Inode numbers in short-form directories can come in two versions,
 * either 4 bytes or 8 bytes wide.  These helpers deal with the
 * two forms transparently by looking at the headers i8count field.
 *
 * For 64-bit inode number the most significant byte must be zero.
 */
static xfs_ino_t
xfs_dir2_sf_get_ino(
	struct xfs_dir2_sf_hdr	*hdr,
	xfs_dir2_inou_t		*from)
{
	if (hdr->i8count)
		return get_unaligned_be64(&from->i8.i) & 0x00ffffffffffffffULL;
	else
		return get_unaligned_be32(&from->i4.i);
}
Beispiel #21
0
/*
 * Inode numbers in short-form directories can come in two versions,
 * either 4 bytes or 8 bytes wide.  These helpers deal with the
 * two forms transparently by looking at the headers i8count field.
 *
 * For 64-bit inode number the most significant byte must be zero.
 */
static xfs_ino_t
xfs_dir2_sf_get_ino(
	struct xfs_dir2_sf_hdr	*hdr,
	__uint8_t		*from)
{
	if (hdr->i8count)
		return get_unaligned_be64(from) & 0x00ffffffffffffffULL;
	else
		return get_unaligned_be32(from);
}
Beispiel #22
0
uint8_t ssc_spout(struct scsi_cmd *cmd)
{
	MHVTL_DBG(1, "Security Protocol Out (%ld) **",
						(long)cmd->dbuf_p->serialNo);

	cmd->dbuf_p->sz = get_unaligned_be32(&cmd->scb[6]);
	/* Check for '512 increment' bit & multiply sz by 512 if set */
	cmd->dbuf_p->sz *= (cmd->scb[4] & 0x80) ? 512 : 1;

	retrieve_CDB_data(cmd->cdev, cmd->dbuf_p);

	return resp_spout(cmd);
}
/* 
 * (1) len doesn't include the header by default.  I want this. 
 */
static int
aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt, struct net_device *orig_dev)
{
	struct aoe_hdr *h;
	u32 n;

	if (dev_net(ifp) != &init_net)
		goto exit;

	skb = skb_share_check(skb, GFP_ATOMIC);
	if (skb == NULL)
		return 0;
	if (skb_linearize(skb))
		goto exit;
	if (!is_aoe_netif(ifp))
		goto exit;
	skb_push(skb, ETH_HLEN);	/* (1) */

	h = (struct aoe_hdr *) skb_mac_header(skb);
	n = get_unaligned_be32(&h->tag);
	if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
		goto exit;

	if (h->verfl & AOEFL_ERR) {
		n = h->err;
		if (n > NECODES)
			n = 0;
		if (net_ratelimit())
			printk(KERN_ERR
				"%s%d.%d@%s; ecode=%d '%s'\n",
				"aoe: error packet from ",
				get_unaligned_be16(&h->major),
				h->minor, skb->dev->name,
				h->err, aoe_errlist[n]);
		goto exit;
	}

	switch (h->cmd) {
	case AOECMD_ATA:
		aoecmd_ata_rsp(skb);
		break;
	case AOECMD_CFG:
		aoecmd_cfg_rsp(skb);
		break;
	default:
		printk(KERN_INFO "aoe: unknown cmd %d\n", h->cmd);
	}
exit:
	dev_kfree_skb(skb);
	return 0;
}
Beispiel #24
0
static int em_cmp_match(struct sk_buff *skb, struct tcf_ematch *em,
			struct tcf_pkt_info *info)
{
	struct tcf_em_cmp *cmp = (struct tcf_em_cmp *) em->data;
	unsigned char *ptr = tcf_get_base_ptr(skb, cmp->layer) + cmp->off;
	u32 val = 0;

	if (!tcf_valid_offset(skb, ptr, cmp->align))
		return 0;

	switch (cmp->align) {
	case TCF_EM_ALIGN_U8:
		val = *ptr;
		break;

	case TCF_EM_ALIGN_U16:
		val = get_unaligned_be16(ptr);

		if (cmp_needs_transformation(cmp))
			val = be16_to_cpu(val);
		break;

	case TCF_EM_ALIGN_U32:
		/* Worth checking boundries? The branching seems
		 * to get worse. Visit again.
		 */
		val = get_unaligned_be32(ptr);

		if (cmp_needs_transformation(cmp))
			val = be32_to_cpu(val);
		break;

	default:
		return 0;
	}

	if (cmp->mask)
		val &= cmp->mask;

	switch (cmp->opnd) {
	case TCF_EM_OPND_EQ:
		return val == cmp->val;
	case TCF_EM_OPND_LT:
		return val < cmp->val;
	case TCF_EM_OPND_GT:
		return val > cmp->val;
	}

	return 0;
}
Beispiel #25
0
static int tpm_tis_i2c_recv(struct udevice *dev, u8 *buf, size_t count)
{
	struct tpm_chip *chip = dev_get_priv(dev);
	int size = 0;
	int status;
	unsigned int expected;
	int rc;

	status = tpm_tis_i2c_status(dev);
	if (status == TPM_STS_COMMAND_READY)
		return -EINTR;
	if ((status & (TPM_STS_DATA_AVAIL | TPM_STS_VALID)) !=
	    (TPM_STS_DATA_AVAIL | TPM_STS_VALID))
		return -EAGAIN;

	debug("...got it;\n");

	/* Read first 10 bytes, including tag, paramsize, and result */
	size = tpm_tis_i2c_recv_data(dev, buf, TPM_HEADER_SIZE);
	if (size < TPM_HEADER_SIZE) {
		debug("Unable to read header\n");
		return size < 0 ? size : -EIO;
	}

	expected = get_unaligned_be32(buf + TPM_RSP_SIZE_BYTE);
	if ((size_t)expected > count || (size_t)expected < TPM_HEADER_SIZE) {
		debug("Error size=%x, expected=%x, count=%x\n", size, expected,
		      count);
		return -ENOSPC;
	}

	size += tpm_tis_i2c_recv_data(dev, &buf[TPM_HEADER_SIZE],
				      expected - TPM_HEADER_SIZE);
	if (size < expected) {
		debug("Unable to read remainder of result\n");
		return -ETIMEDOUT;
	}

	rc = tpm_tis_i2c_wait_for_stat(dev, TPM_STS_VALID, chip->timeout_c,
				       &status);
	if (rc)
		return rc;
	if (status & TPM_STS_DATA_AVAIL) {  /* Retry? */
		debug("Error left over data\n");
		return -EIO;
	}

	return size;
}
static int cyttsp5_verify_ttconfig_binary(struct device *dev,
		u8 *bin_config_data, int bin_config_size, u8 **start, int *len)
{
	struct cyttsp5_loader_data *ld = cyttsp5_get_loader_data(dev);
	int header_size;
	u16 config_size;
	u32 fw_ver_config;
	u32 fw_revctrl_config;

	if (!ld->si) {
		dev_err(dev, "%s: No firmware infomation found, device FW may be corrupted\n",
			__func__);
		return -ENODEV;
	}

	/*
	 * We need 11 bytes for FW version control info and at
	 * least 6 bytes in config (Length + Max Length + CRC)
	 */
	header_size = bin_config_data[0] + 1;
	if (header_size < 11 || header_size >= bin_config_size - 6) {
		dev_err(dev, "%s: Invalid header size %d\n", __func__,
			header_size);
		return -EINVAL;
	}

	fw_ver_config = get_unaligned_be16(&bin_config_data[1]);
	/* 4 middle bytes are not used */
	fw_revctrl_config = get_unaligned_be32(&bin_config_data[7]);

	/* FW versions should match */
	if (cyttsp5_check_firmware_version(dev, fw_ver_config,
			fw_revctrl_config)) {
		dev_err(dev, "%s: FW versions mismatch\n", __func__);
		return -EINVAL;
	}

	config_size = get_unaligned_le16(&bin_config_data[header_size]);
	/* Perform a simple size check (2 bytes for CRC) */
	if (config_size != bin_config_size - header_size - 2) {
		dev_err(dev, "%s: Config size invalid\n", __func__);
		return -EINVAL;
	}

	*start = &bin_config_data[header_size];
	*len = bin_config_size - header_size;

	return 0;
}
int parse_dek_packet(char *data,
		struct ecryptfs_crypt_stat *crypt_stat,
		size_t *packet_size) {
	int rc = 0;
	char temp_comm[PKG_NAME_SIZE]; //test
	int temp_euid;

	(*packet_size) = 0;

	if (data[(*packet_size)++] != ECRYPTFS_DEK_PACKET_TYPE) {
		DEK_LOGE("First byte != 0x%.2x; invalid packet\n",
				ECRYPTFS_DEK_PACKET_TYPE);
		rc = -EINVAL;
	}

	memcpy(temp_comm, &data[*packet_size], PKG_NAME_SIZE);
	(*packet_size) += PKG_NAME_SIZE;

	temp_euid = get_unaligned_be32(data + *packet_size);
	(*packet_size) += 4;

	if (crypt_stat->flags & ECRYPTFS_DEK_IS_SENSITIVE) {
		crypt_stat->sdp_dek.type = get_unaligned_be32(data + *packet_size);
		(*packet_size) += 4;
		crypt_stat->sdp_dek.len = get_unaligned_be32(data + *packet_size);
		(*packet_size) += 4;
		memcpy(crypt_stat->sdp_dek.buf, &data[*packet_size], crypt_stat->sdp_dek.len);
		(*packet_size) += crypt_stat->sdp_dek.len;
	}
	
#if ECRYPTFS_DEK_DEBUG
	DEK_LOGD("%s() : comm : %s [euid:%d]\n",
		__func__, temp_comm, temp_euid);
#endif
	return rc;
}
/*
 * tis_sendrecv()
 *
 * Send the requested data to the TPM and then try to get its response
 *
 * @sendbuf - buffer of the data to send
 * @send_size size of the data to send
 * @recvbuf - memory to save the response to
 * @recv_len - pointer to the size of the response buffer
 *
 * Returns 0 on success (and places the number of response bytes at recv_len)
 * or -1 on failure.
 */
int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
                 size_t *recv_len)
{
    int res;
    unsigned long start;

#ifdef DEBUG
    memset(recvbuf, 0xcc, *recv_len);
    printf("send to TPM (%d bytes, recv_len=%d):\n", send_size, *recv_len);
    print_buffer(0, (void *)sendbuf, 1, send_size, 0);
#endif

    res = i2c_write(0x29, 0, 0, (uchar *)sendbuf, send_size);
    if (res) {
        printf("i2c_write returned %d\n", res);
        return -1;
    }

    start = get_timer(0);
    while ((res = i2c_read(0x29, 0, 0, recvbuf, 10))) {
        if (get_timer(start) > ATMEL_TPM_TIMEOUT_MS) {
            puts("tpm timed out\n");
            return -1;
        }
        udelay(100);
    }
    if (!res) {
        *recv_len = get_unaligned_be32(recvbuf + 2);
        if (*recv_len > 10)
            res = i2c_read(0x29, 0, 0, recvbuf, *recv_len);
    }
    if (res) {
        printf("i2c_read returned %d (rlen=%d)\n", res, *recv_len);
#ifdef DEBUG
        print_buffer(0, recvbuf, 1, *recv_len, 0);
#endif
    }

#ifdef DEBUG
    if (!res) {
        printf("read from TPM (%d bytes):\n", *recv_len);
        print_buffer(0, recvbuf, 1, *recv_len, 0);
    }
#endif

    return res;
}
Beispiel #29
0
static void sm3_expand(u32 *t, u32 *w, u32 *wt)
{
	int i;
	unsigned int tmp;

	/* load the input */
	for (i = 0; i <= 15; i++)
		w[i] = get_unaligned_be32((__u32 *)t + i);

	for (i = 16; i <= 67; i++) {
		tmp = w[i - 16] ^ w[i - 9] ^ rol32(w[i - 3], 15);
		w[i] = p1(tmp) ^ (rol32(w[i - 13], 7)) ^ w[i - 6];
	}

	for (i = 0; i <= 63; i++)
		wt[i] = w[i] ^ w[i + 4];
}
Beispiel #30
0
uint8_t ssc_pr_out(struct scsi_cmd *cmd)
{
	struct priv_lu_ssc *lu_priv;
	uint8_t *sam_stat = &cmd->dbuf_p->sam_stat;

	lu_priv = cmd->lu->lu_private;

	MHVTL_DBG(1, "PERSISTENT RESERVE OUT (%ld) **",
						(long)cmd->dbuf_p->serialNo);
	if (lu_priv->I_am_SPC_2_Reserved) {
		MHVTL_DBG(1, "SPC 2 reserved");
		*sam_stat = SAM_STAT_RESERVATION_CONFLICT;
		return SAM_STAT_RESERVATION_CONFLICT;
	}
	cmd->dbuf_p->sz = get_unaligned_be32(&cmd->scb[5]);
	retrieve_CDB_data(cmd->cdev, cmd->dbuf_p);
	return resp_spc_pro(cmd->scb, cmd->dbuf_p);
}