PayloadReader.cc revision 34e5f34ea2684ba8edcac4d3985bf6ea664830f4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <string.h>
#include <stdlib.h>
#include "PayloadReader.h"
#define ITER_CONT_BYTE_LEN 4
#define IS_ITERATED(pathDef) \
// functions to place bit data properly.
static fru_errno_t
{
if ((bitLength > 64) &&
(bitOffset > 64) &&
(dataLength > 8) &&
return (FRU_FAILURE);
// move the bit data into place
// create a mask to clear the old data.
}
// get the data out of the byte array.
// clear the old data
// put in the new data.
// write the data back to the buffer.
return (FRU_SUCCESS);
}
static fru_errno_t
{
if ((bitLength > 64) ||
(bitLength < 0) ||
(bitOffset > 64) ||
(dataLength > 8) ||
return (FRU_FAILURE);
// get the data out of the byte array.
return (FRU_SUCCESS);
}
// ===========================================================================
// caller is to be sure elemDef is contained by recDef.
int
{
int rc = 0;
return (rc);
}
}
// ===========================================================================
// return -1 on error.
int
{
*err = FRU_SUCCESS;
switch (iterType) {
case FRU_FIFO:
case FRU_Linear:
{
break;
}
case FRU_Circular:
case FRU_LIFO:
{
}
// For reading they are oposite.
if (iterType == FRU_Circular) {
} else {
if (abs < 0)
// abs is negative here
}
break;
}
}
*err = FRU_FAILURE;
return (-1);
}
// ===========================================================================
// return -1 on error.
int
{
int rc = 0;
// read the iteration control bytes first because we may ONLY need
// them.
// the '+' symbol on anything is an error here
*err = FRU_INVALPATH;
return (-1);
}
// check assumptions for next calls.
*err = FRU_DATACORRUPT;
return (-1);
}
if (onlyFindingIterThereFlag == ITER_THERE_ONLY) {
if (rcIterThere != NULL) {
*rcIterThere = iterThere;
}
*err = FRU_SUCCESS;
return (ITER_CONT_BYTE_LEN);
}
*err = FRU_DATANOTFOUND;
return (-1);
}
// don't forget to skip the iteration control bytes!!!
if (rc == -1) {
// error set by calcOffset
return (-1);
}
*err = FRU_SUCCESS;
return (ITER_CONT_BYTE_LEN + rc);
}
// ===========================================================================
// Iff onlyFindingIterThereFlag is set data is ignored and dataLen will be set
// to the number of iterations which are actually in the seeprom.
{
size_t calc_data_len = 0;
// alway go ahead and do the iterated thing. If we are not a
// field then the onlyFindingIterThereFlag should be set.
// Check this afterward.
int offset = 0;
int iterThere = 0;
// zzz altering the length things again...
if (IS_ITERATED(path)) {
// we are iterated.
// zzz still have to figure out the bit offsets for bit iterations...
if (offset == -1)
return (rc);
// done
if (onlyFindingIterThereFlag) {
return (FRU_SUCCESS);
}
} else {
// done but this thing was not an iteration!!!
if (onlyFindingIterThereFlag) {
return (FRU_INVALPATH);
}
offset = 0;
}
// end zzz
// now make sure we have a field.
return (FRU_NOTFIELD);
}
// allocate and copy.
return (FRU_FAILURE);
}
// iterated bit field adjust acordingly.
if (IS_ITERATED(path)) {
}
calc_data_len, 0, eData);
if (rc != FRU_SUCCESS) {
return (rc);
}
unsigned char *eData
return (FRU_FAILURE);
}
/* copy the correct number of bytes to eData */
(calc_data_len));
} else {
return (FRU_FAILURE);
}
*dataLen = calc_data_len;
}
return (FRU_SUCCESS);
}
// At this point we know the entry is some sort of record.
if (IS_ITERATED(path)) {
// zzz still have to figure out the bit offsets for bit iterations...
if (newOffset == -1)
return (rc);
}
}
// ===========================================================================
// will send the data back in (data,dataLen)
int instWICur,
{
}
// ===========================================================================
int instWICur,
int *numThere)
{
if (err == FRU_SUCCESS) {
int tmp_num_there = (int)tmp_num;
if (tmp_num_there != tmp_num) {
return (FRU_FAILURE);
}
}
return (err);
}
static fru_errno_t
{
// update the iteration control information
// This never changes.
return (FRU_DATACORRUPT);
}
// Remember that when the iteration is added the head and the tail both
// equal 0 (ie point to 0). So if we are empty when we are updating
// then we don't have to alter the head or tail values. We simply add
// one to the numThere.
if (*numThere != 0) {
case FRU_Linear:
// this will flag an error when Linear can't
// hold anymore.
return (FRU_ITERFULL);
/* Fall through */
case FRU_FIFO:
// if we are not at the end move the tail.
break;
case FRU_Circular:
case FRU_LIFO:
// this is the same except LIFO is read
// BACKWARDS
// move the tail.
// if the tail hits the end wrap around.
*tail = 0;
// if tail catches head move the head.
// if head hits the end wrap around.
*head = 0;
}
break;
}
}
// add one IFF we are not full
}
return (FRU_SUCCESS);
}
// ===========================================================================
{
// Delay checking for Records until after this which will
// allow for [+] notation for Iterated Records.
// if this is updating an iteration AND we are adding one...
if (IS_ITERATED(path) &&
}
return (FRU_NOTFIELD);
}
int offset = 0;
int calcLen = 0;
int dummy = 0;
// zzz altering the length things again...
if (IS_ITERATED(path)) {
// we are iterated.
// zzz still have to figure out the bit offsets
if (offset == -1)
return (rc);
} else {
offset = 0;
}
// end zzz
// once again convert enums for the user again.
// iterated bit field adjust acordingly.
}
if (rc != FRU_SUCCESS)
return (rc);
calcLen);
} else {
// copy into and return.
}
return (FRU_SUCCESS);
}
int dummy = 0;
// zzz still have to figure out the bit offsets
if (newOffset == -1)
return (rc);
}
}
// ===========================================================================
// will update the data in payload which can then be written back.
int instWICur,
{
// verify the user data first before doing any major work.
int calcLen = 0;
}
// unless we are updateing with [+] symbol
// (which means we don't have any data length at all.)
if (IS_ITERATED(prev)) {
} else {
}
// the sizeof the data for Binary or Enumeration MUST
// be uint64_t
return (FRU_INVALDATASIZE);
// all others must be shorter than the space available.
} else {
return (FRU_INVALDATASIZE);
}
}
}