/*******************************************************************************
* This file contains main functions related to iSCSI Parameter negotiation.
*
* (c) Copyright 2007-2013 Datera, Inc.
*
* Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
******************************************************************************/
#include <linux/ctype.h>
#include <linux/kthread.h>
#include <linux/slab.h>
#include <net/sock.h>
#include <scsi/iscsi_proto.h>
#include <target/target_core_base.h>
#include <target/target_core_fabric.h>
#include <target/iscsi/iscsi_transport.h>
#include <target/iscsi/iscsi_target_core.h>
#include "iscsi_target_parameters.h"
#include "iscsi_target_login.h"
#include "iscsi_target_nego.h"
#include "iscsi_target_tpg.h"
#include "iscsi_target_util.h"
#include "iscsi_target.h"
#include "iscsi_target_auth.h"
#define MAX_LOGIN_PDUS 7
#define TEXT_LEN 4096
void convert_null_to_semi(char *buf, int len)
{
int i;
for (i = 0; i < len; i++)
if (buf[i] == '\0')
buf[i] = ';';
}
static int strlen_semi(char *buf)
{
int i = 0;
while (buf[i] != '\0') {
if (buf[i] == ';')
return i;
i++;
}
return -1;
}
int extract_param(
const char *in_buf,
const char *pattern,
unsigned int max_length,
char *out_buf,
unsigned char *type)
{
char *ptr;
int len;
if (!in_buf || !pattern || !out_buf || !type)
return -1;
ptr = strstr(in_buf, pattern);
if (!ptr)
return -1;
ptr = strstr(ptr, "=");
if (!ptr)
return -1;
ptr += 1;
if (*ptr == '0' && (*(ptr+1) == 'x' || *(ptr+1) == 'X')) {
ptr += 2; /* skip 0x */
*type = HEX;
} else
*type = DECIMAL;
len = strlen_semi(ptr);
if (len < 0)
return