ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin)
{
	struct ipmi_sdr_iterator *itr;
	struct ipmi_rs *rsp;
	struct ipmi_rq req;

	struct ipm_devid_rsp *devid;

	itr = malloc(sizeof (struct ipmi_sdr_iterator));
	if (!itr) {
		lprintf(LOG_ERR, "ipmitool: malloc failure");
		return NULL;
	}

	/* check SDRR capability */
	memset(&req, 0, sizeof (req));
	req.msg.netfn = IPMI_NETFN_APP;
	req.msg.cmd = BMC_GET_DEVICE_ID;
	req.msg.data_len = 0;

	rsp = intf->sendrecv(intf, &req);

	if (!rsp) {
		lprintf(LOG_ERR, "Get Device ID command failed");
		free(itr);
		itr = NULL;
		return NULL;
	}
	if (rsp->ccode) {
		lprintf(LOG_ERR, "Get Device ID command failed: %#x %s",
			rsp->ccode, val2str(rsp->ccode, completion_code_vals));
		free(itr);
		itr = NULL;
		return NULL;
	}
	devid = (struct ipm_devid_rsp *) rsp->data;

   sdriana =  (long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id);

	if (!use_builtin && (devid->device_revision & IPM_DEV_DEVICE_ID_SDR_MASK)) {
		if ((devid->adtl_device_support & 0x02) == 0) {
			if ((devid->adtl_device_support & 0x01)) {
				lprintf(LOG_DEBUG, "Using Device SDRs\n");
				use_built_in = 1;
			} else {
				lprintf(LOG_ERR, "Error obtaining SDR info");
				free(itr);
				itr = NULL;
				return NULL;
			}
		} else {
			lprintf(LOG_DEBUG, "Using SDR from Repository \n");
		}
	}
	itr->use_built_in = use_builtin ? 1 : use_built_in;
   /***********************/
	if (itr->use_built_in == 0) {
		struct sdr_repo_info_rs sdr_info;
		/* get sdr repository info */
		memset(&req, 0, sizeof (req));
		req.msg.netfn = IPMI_NETFN_STORAGE;
		req.msg.cmd = GET_SDR_REPO_INFO;

		rsp = intf->sendrecv(intf, &req);
		if (!rsp) {
			lprintf(LOG_ERR, "Error obtaining SDR info");
			free(itr);
			itr = NULL;
			return NULL;
		}
		if (rsp->ccode) {
			lprintf(LOG_ERR, "Error obtaining SDR info: %s",
				val2str(rsp->ccode, completion_code_vals));
			free(itr);
			itr = NULL;
			return NULL;
		}

		memcpy(&sdr_info, rsp->data, sizeof (sdr_info));
		/* IPMIv1.0 == 0x01
		   * IPMIv1.5 == 0x51
		   * IPMIv2.0 == 0x02
		 */
		if ((sdr_info.version != 0x51) &&
		    (sdr_info.version != 0x01) &&
		    (sdr_info.version != 0x02)) {
			lprintf(LOG_WARN, "WARNING: Unknown SDR repository "
				"version 0x%02x", sdr_info.version);
		}

		itr->total = sdr_info.count;
		itr->next = 0;

		lprintf(LOG_DEBUG, "SDR free space: %d", sdr_info.free);
		lprintf(LOG_DEBUG, "SDR records   : %d", sdr_info.count);

		/* Build SDRR if there is no record in repository */
		if( sdr_info.count == 0 ) {
		   lprintf(LOG_DEBUG, "Rebuilding SDRR...");

		   if( ipmi_sdr_add_from_sensors( intf, 0 ) != 0 ) {
		      lprintf(LOG_ERR, "Could not build SDRR!");
		      free(itr);
					itr = NULL;
		      return NULL;
		   }
		}
	} else {
		struct sdr_device_info_rs sdr_info;
		/* get device sdr info */
		memset(&req, 0, sizeof (req));
		req.msg.netfn = IPMI_NETFN_SE;
		req.msg.cmd = GET_DEVICE_SDR_INFO;

		rsp = intf->sendrecv(intf, &req);
		if (!rsp || !rsp->data_len || rsp->ccode) {
			printf("Err in cmd get sensor sdr info\n");
			free(itr);
			itr = NULL;
			return NULL;
		}
		memcpy(&sdr_info, rsp->data, sizeof (sdr_info));

		itr->total = sdr_info.count;
		itr->next = 0;
		lprintf(LOG_DEBUG, "SDR records   : %d", sdr_info.count);
	}

	if (ipmi_sdr_get_reservation(intf, itr->use_built_in,
                                &(itr->reservation)) < 0) {
		lprintf(LOG_ERR, "Unable to obtain SDR reservation");
		free(itr);
		itr = NULL;
		return NULL;
	}

	return itr;
}