2007-08-10 02:44:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright Fen Systems Ltd. 2007. Portions of this code are derived
|
|
|
|
* from IBM Corporation Sample Programs. Copyright IBM Corporation
|
|
|
|
* 2004, 2007. All rights reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-05-01 16:41:06 +02:00
|
|
|
FILE_LICENCE ( BSD2 );
|
|
|
|
|
2007-08-10 02:44:20 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <byteswap.h>
|
|
|
|
#include <realmode.h>
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/pci.h>
|
|
|
|
#include <ipxe/acpi.h>
|
|
|
|
#include <ipxe/in.h>
|
|
|
|
#include <ipxe/netdevice.h>
|
|
|
|
#include <ipxe/ethernet.h>
|
|
|
|
#include <ipxe/dhcp.h>
|
|
|
|
#include <ipxe/iscsi.h>
|
|
|
|
#include <ipxe/ibft.h>
|
2007-08-10 02:44:20 +02:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* iSCSI boot firmware table
|
|
|
|
*
|
|
|
|
* The information in this file is derived from the document "iSCSI
|
|
|
|
* Boot Firmware Table (iBFT)" as published by IBM at
|
|
|
|
*
|
|
|
|
* ftp://ftp.software.ibm.com/systems/support/system_x_pdf/ibm_iscsi_boot_firmware_table_v1.02.pdf
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ibftab __use_data16 ( ibftab )
|
2010-04-19 21:16:01 +02:00
|
|
|
/** The iBFT used by iPXE */
|
|
|
|
struct ipxe_ibft __data16 ( ibftab ) = {
|
2007-08-10 02:44:20 +02:00
|
|
|
/* Table header */
|
|
|
|
.table = {
|
|
|
|
/* ACPI header */
|
|
|
|
.acpi = {
|
|
|
|
.signature = IBFT_SIG,
|
|
|
|
.length = sizeof ( ibftab ),
|
|
|
|
.revision = 1,
|
|
|
|
.oem_id = "FENSYS",
|
2010-04-19 21:16:01 +02:00
|
|
|
.oem_table_id = "iPXE",
|
2007-08-10 02:44:20 +02:00
|
|
|
},
|
|
|
|
/* Control block */
|
|
|
|
.control = {
|
|
|
|
.header = {
|
|
|
|
.structure_id = IBFT_STRUCTURE_ID_CONTROL,
|
|
|
|
.version = 1,
|
|
|
|
.length = sizeof ( ibftab.table.control ),
|
|
|
|
.flags = 0,
|
|
|
|
},
|
|
|
|
.initiator = offsetof ( typeof ( ibftab ), initiator ),
|
|
|
|
.nic_0 = offsetof ( typeof ( ibftab ), nic ),
|
|
|
|
.target_0 = offsetof ( typeof ( ibftab ), target ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
/* iSCSI initiator information */
|
|
|
|
.initiator = {
|
|
|
|
.header = {
|
|
|
|
.structure_id = IBFT_STRUCTURE_ID_INITIATOR,
|
|
|
|
.version = 1,
|
|
|
|
.length = sizeof ( ibftab.initiator ),
|
|
|
|
.flags = ( IBFT_FL_INITIATOR_BLOCK_VALID |
|
|
|
|
IBFT_FL_INITIATOR_FIRMWARE_BOOT_SELECTED ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
/* NIC information */
|
|
|
|
.nic = {
|
|
|
|
.header = {
|
|
|
|
.structure_id = IBFT_STRUCTURE_ID_NIC,
|
|
|
|
.version = 1,
|
|
|
|
.length = sizeof ( ibftab.nic ),
|
|
|
|
.flags = ( IBFT_FL_NIC_BLOCK_VALID |
|
|
|
|
IBFT_FL_NIC_FIRMWARE_BOOT_SELECTED ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
/* iSCSI target information */
|
|
|
|
.target = {
|
|
|
|
.header = {
|
|
|
|
.structure_id = IBFT_STRUCTURE_ID_TARGET,
|
|
|
|
.version = 1,
|
|
|
|
.length = sizeof ( ibftab.target ),
|
|
|
|
.flags = ( IBFT_FL_TARGET_BLOCK_VALID |
|
|
|
|
IBFT_FL_TARGET_FIRMWARE_BOOT_SELECTED ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill in an IP address field within iBFT
|
|
|
|
*
|
|
|
|
* @v ipaddr IP address field
|
|
|
|
* @v in IPv4 address
|
|
|
|
*/
|
|
|
|
static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) {
|
|
|
|
memset ( ipaddr, 0, sizeof ( ipaddr ) );
|
|
|
|
if ( in.s_addr ) {
|
|
|
|
ipaddr->in = in;
|
|
|
|
ipaddr->ones = 0xffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-03-25 21:46:16 +01:00
|
|
|
* Fill in an IP address within iBFT from configuration setting
|
2007-08-10 02:44:20 +02:00
|
|
|
*
|
|
|
|
* @v ipaddr IP address field
|
2008-03-25 21:46:16 +01:00
|
|
|
* @v setting Configuration setting
|
2007-08-10 02:44:20 +02:00
|
|
|
* @v tag DHCP option tag
|
|
|
|
*/
|
|
|
|
static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr,
|
2008-03-25 21:46:16 +01:00
|
|
|
struct setting *setting ) {
|
2008-03-21 01:49:44 +01:00
|
|
|
struct in_addr in = { 0 };
|
2008-03-25 21:46:16 +01:00
|
|
|
fetch_ipv4_setting ( NULL, setting, &in );
|
2007-08-10 02:44:20 +02:00
|
|
|
ibft_set_ipaddr ( ipaddr, in );
|
|
|
|
}
|
|
|
|
|
2009-02-20 22:41:00 +01:00
|
|
|
/**
|
|
|
|
* Read IP address from iBFT (for debugging)
|
|
|
|
*
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @v string String field
|
|
|
|
* @ret ipaddr IP address string
|
|
|
|
*/
|
|
|
|
static const char * ibft_ipaddr ( struct ibft_ipaddr *ipaddr ) {
|
|
|
|
return inet_ntoa ( ipaddr->in );
|
|
|
|
}
|
|
|
|
|
2007-08-10 02:44:20 +02:00
|
|
|
/**
|
2008-03-21 01:49:44 +01:00
|
|
|
* Allocate a string within iBFT
|
2007-08-10 02:44:20 +02:00
|
|
|
*
|
|
|
|
* @v strings iBFT string block descriptor
|
2008-03-21 01:49:44 +01:00
|
|
|
* @v string String field to fill in
|
|
|
|
* @v len Length of string to allocate (excluding NUL)
|
2007-08-10 02:44:20 +02:00
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
2008-03-21 01:49:44 +01:00
|
|
|
static int ibft_alloc_string ( struct ibft_string_block *strings,
|
|
|
|
struct ibft_string *string, size_t len ) {
|
2007-08-10 02:44:20 +02:00
|
|
|
char *dest;
|
|
|
|
unsigned int remaining;
|
|
|
|
|
|
|
|
dest = ( ( ( char * ) strings->table ) + strings->offset );
|
2008-03-21 01:49:44 +01:00
|
|
|
remaining = ( strings->table->acpi.length - strings->offset );
|
2007-08-10 02:44:20 +02:00
|
|
|
if ( len >= remaining )
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
string->offset = strings->offset;
|
|
|
|
string->length = len;
|
|
|
|
strings->offset += ( len + 1 );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-21 01:49:44 +01:00
|
|
|
/**
|
|
|
|
* Fill in a string field within iBFT
|
|
|
|
*
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @v string String field
|
2008-08-11 04:12:38 +02:00
|
|
|
* @v data String to fill in, or NULL
|
2008-03-21 01:49:44 +01:00
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int ibft_set_string ( struct ibft_string_block *strings,
|
|
|
|
struct ibft_string *string, const char *data ) {
|
|
|
|
char *dest;
|
|
|
|
int rc;
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
if ( ! data )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( ( rc = ibft_alloc_string ( strings, string,
|
|
|
|
strlen ( data ) ) ) != 0 )
|
2008-03-21 01:49:44 +01:00
|
|
|
return rc;
|
|
|
|
dest = ( ( ( char * ) strings->table ) + string->offset );
|
|
|
|
strcpy ( dest, data );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-10 02:44:20 +02:00
|
|
|
/**
|
2008-03-25 21:46:16 +01:00
|
|
|
* Fill in a string field within iBFT from configuration setting
|
2007-08-10 02:44:20 +02:00
|
|
|
*
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @v string String field
|
2008-03-25 21:46:16 +01:00
|
|
|
* @v setting Configuration setting
|
2007-08-10 02:44:20 +02:00
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int ibft_set_string_option ( struct ibft_string_block *strings,
|
|
|
|
struct ibft_string *string,
|
2008-03-25 21:46:16 +01:00
|
|
|
struct setting *setting ) {
|
2008-03-21 01:49:44 +01:00
|
|
|
int len;
|
|
|
|
char *dest;
|
|
|
|
int rc;
|
2007-08-10 02:44:20 +02:00
|
|
|
|
2008-03-25 21:46:16 +01:00
|
|
|
len = fetch_setting_len ( NULL, setting );
|
2008-03-21 01:49:44 +01:00
|
|
|
if ( len < 0 ) {
|
2007-08-10 02:44:20 +02:00
|
|
|
string->offset = 0;
|
|
|
|
string->length = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-21 01:49:44 +01:00
|
|
|
if ( ( rc = ibft_alloc_string ( strings, string, len ) ) != 0 )
|
|
|
|
return rc;
|
|
|
|
dest = ( ( ( char * ) strings->table ) + string->offset );
|
2008-03-25 21:46:16 +01:00
|
|
|
fetch_string_setting ( NULL, setting, dest, ( len + 1 ) );
|
2008-03-21 01:49:44 +01:00
|
|
|
return 0;
|
2007-08-10 02:44:20 +02:00
|
|
|
}
|
|
|
|
|
2009-02-20 22:41:00 +01:00
|
|
|
/**
|
|
|
|
* Read string from iBFT (for debugging)
|
|
|
|
*
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @v string String field
|
|
|
|
* @ret data String content (or "<empty>")
|
|
|
|
*/
|
|
|
|
static const char * ibft_string ( struct ibft_string_block *strings,
|
|
|
|
struct ibft_string *string ) {
|
2009-10-23 22:33:48 +02:00
|
|
|
return ( string->offset ?
|
|
|
|
( ( ( char * ) strings->table ) + string->offset ) : NULL );
|
2009-02-20 22:41:00 +01:00
|
|
|
}
|
|
|
|
|
2007-08-10 02:44:20 +02:00
|
|
|
/**
|
|
|
|
* Fill in NIC portion of iBFT
|
|
|
|
*
|
|
|
|
* @v nic NIC portion of iBFT
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @v netdev Network device
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int ibft_fill_nic ( struct ibft_nic *nic,
|
|
|
|
struct ibft_string_block *strings,
|
|
|
|
struct net_device *netdev ) {
|
2009-10-23 23:18:04 +02:00
|
|
|
struct ll_protocol *ll_protocol = netdev->ll_protocol;
|
2008-03-21 01:49:44 +01:00
|
|
|
struct in_addr netmask_addr = { 0 };
|
2007-08-10 02:44:20 +02:00
|
|
|
unsigned int netmask_count = 0;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Extract values from DHCP configuration */
|
2008-03-25 21:46:16 +01:00
|
|
|
ibft_set_ipaddr_option ( &nic->ip_address, &ip_setting );
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT NIC IP = %s\n", ibft_ipaddr ( &nic->ip_address ) );
|
2008-03-25 21:46:16 +01:00
|
|
|
ibft_set_ipaddr_option ( &nic->gateway, &gateway_setting );
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT NIC gateway = %s\n", ibft_ipaddr ( &nic->gateway ) );
|
2008-03-25 21:46:16 +01:00
|
|
|
ibft_set_ipaddr_option ( &nic->dns[0], &dns_setting );
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT NIC DNS = %s\n", ibft_ipaddr ( &nic->dns[0] ) );
|
2007-08-10 02:44:20 +02:00
|
|
|
if ( ( rc = ibft_set_string_option ( strings, &nic->hostname,
|
2008-03-25 21:46:16 +01:00
|
|
|
&hostname_setting ) ) != 0 )
|
2007-08-10 02:44:20 +02:00
|
|
|
return rc;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT NIC hostname = %s\n",
|
|
|
|
ibft_string ( strings, &nic->hostname ) );
|
2007-08-10 02:44:20 +02:00
|
|
|
|
|
|
|
/* Derive subnet mask prefix from subnet mask */
|
2008-03-25 21:46:16 +01:00
|
|
|
fetch_ipv4_setting ( NULL, &netmask_setting, &netmask_addr );
|
2007-08-10 02:44:20 +02:00
|
|
|
while ( netmask_addr.s_addr ) {
|
|
|
|
if ( netmask_addr.s_addr & 0x1 )
|
|
|
|
netmask_count++;
|
|
|
|
netmask_addr.s_addr >>= 1;
|
|
|
|
}
|
|
|
|
nic->subnet_mask_prefix = netmask_count;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT NIC subnet = /%d\n", nic->subnet_mask_prefix );
|
2007-08-10 02:44:20 +02:00
|
|
|
|
|
|
|
/* Extract values from net-device configuration */
|
2009-10-23 23:18:04 +02:00
|
|
|
if ( ( rc = ll_protocol->eth_addr ( netdev->ll_addr,
|
|
|
|
nic->mac_address ) ) != 0 ) {
|
|
|
|
DBG ( "Could not determine iBFT MAC: %s\n", strerror ( rc ) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
DBG ( "iBFT NIC MAC = %s\n", eth_ntoa ( nic->mac_address ) );
|
2007-08-10 02:44:20 +02:00
|
|
|
nic->pci_bus_dev_func = netdev->dev->desc.location;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT NIC PCI = %04x\n", nic->pci_bus_dev_func );
|
2007-08-10 02:44:20 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill in Initiator portion of iBFT
|
|
|
|
*
|
|
|
|
* @v initiator Initiator portion of iBFT
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int ibft_fill_initiator ( struct ibft_initiator *initiator,
|
|
|
|
struct ibft_string_block *strings ) {
|
|
|
|
const char *initiator_iqn = iscsi_initiator_iqn();
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name,
|
2008-03-21 01:49:44 +01:00
|
|
|
initiator_iqn ) ) != 0 )
|
2007-08-10 02:44:20 +02:00
|
|
|
return rc;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT initiator hostname = %s\n",
|
|
|
|
ibft_string ( strings, &initiator->initiator_name ) );
|
2007-08-10 02:44:20 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/**
|
|
|
|
* Fill in Target CHAP portion of iBFT
|
|
|
|
*
|
|
|
|
* @v target Target portion of iBFT
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int ibft_fill_target_chap ( struct ibft_target *target,
|
|
|
|
struct ibft_string_block *strings,
|
|
|
|
struct iscsi_session *iscsi ) {
|
|
|
|
int rc;
|
|
|
|
|
2009-02-20 22:41:00 +01:00
|
|
|
if ( ! ( iscsi->status & ISCSI_STATUS_AUTH_FORWARD_REQUIRED ) )
|
2008-08-11 04:12:38 +02:00
|
|
|
return 0;
|
2009-02-20 22:41:00 +01:00
|
|
|
|
|
|
|
assert ( iscsi->initiator_username );
|
2008-08-11 04:12:38 +02:00
|
|
|
assert ( iscsi->initiator_password );
|
|
|
|
|
|
|
|
target->chap_type = IBFT_CHAP_ONE_WAY;
|
|
|
|
if ( ( rc = ibft_set_string ( strings, &target->chap_name,
|
|
|
|
iscsi->initiator_username ) ) != 0 )
|
|
|
|
return rc;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT target username = %s\n",
|
|
|
|
ibft_string ( strings, &target->chap_name ) );
|
2008-08-11 04:12:38 +02:00
|
|
|
if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
|
|
|
|
iscsi->initiator_password ) ) != 0 )
|
|
|
|
return rc;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT target password = <redacted>\n" );
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill in Target Reverse CHAP portion of iBFT
|
|
|
|
*
|
|
|
|
* @v target Target portion of iBFT
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int ibft_fill_target_reverse_chap ( struct ibft_target *target,
|
|
|
|
struct ibft_string_block *strings,
|
|
|
|
struct iscsi_session *iscsi ) {
|
|
|
|
int rc;
|
|
|
|
|
2009-02-20 22:41:00 +01:00
|
|
|
if ( ! ( iscsi->status & ISCSI_STATUS_AUTH_REVERSE_REQUIRED ) )
|
2008-08-11 04:12:38 +02:00
|
|
|
return 0;
|
2009-02-20 22:41:00 +01:00
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
assert ( iscsi->initiator_username );
|
|
|
|
assert ( iscsi->initiator_password );
|
2009-02-20 22:41:00 +01:00
|
|
|
assert ( iscsi->target_username );
|
|
|
|
assert ( iscsi->target_password );
|
2008-08-11 04:12:38 +02:00
|
|
|
|
|
|
|
target->chap_type = IBFT_CHAP_MUTUAL;
|
|
|
|
if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_name,
|
|
|
|
iscsi->target_username ) ) != 0 )
|
|
|
|
return rc;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT target reverse username = %s\n",
|
|
|
|
ibft_string ( strings, &target->chap_name ) );
|
2008-08-11 04:12:38 +02:00
|
|
|
if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_secret,
|
|
|
|
iscsi->target_password ) ) != 0 )
|
|
|
|
return rc;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT target reverse password = <redacted>\n" );
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-10 02:44:20 +02:00
|
|
|
/**
|
|
|
|
* Fill in Target portion of iBFT
|
|
|
|
*
|
|
|
|
* @v target Target portion of iBFT
|
|
|
|
* @v strings iBFT string block descriptor
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int ibft_fill_target ( struct ibft_target *target,
|
|
|
|
struct ibft_string_block *strings,
|
|
|
|
struct iscsi_session *iscsi ) {
|
|
|
|
struct sockaddr_in *sin_target =
|
|
|
|
( struct sockaddr_in * ) &iscsi->target_sockaddr;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Fill in Target values */
|
|
|
|
ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr );
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT target IP = %s\n", ibft_ipaddr ( &target->ip_address ) );
|
2007-08-10 02:44:20 +02:00
|
|
|
target->socket = ntohs ( sin_target->sin_port );
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT target port = %d\n", target->socket );
|
2007-08-10 02:44:20 +02:00
|
|
|
if ( ( rc = ibft_set_string ( strings, &target->target_name,
|
2008-03-21 01:49:44 +01:00
|
|
|
iscsi->target_iqn ) ) != 0 )
|
2007-08-10 02:44:20 +02:00
|
|
|
return rc;
|
2009-02-20 22:41:00 +01:00
|
|
|
DBG ( "iBFT target name = %s\n",
|
|
|
|
ibft_string ( strings, &target->target_name ) );
|
2008-08-11 04:12:38 +02:00
|
|
|
if ( ( rc = ibft_fill_target_chap ( target, strings, iscsi ) ) != 0 )
|
|
|
|
return rc;
|
|
|
|
if ( ( rc = ibft_fill_target_reverse_chap ( target, strings,
|
|
|
|
iscsi ) ) != 0 )
|
|
|
|
return rc;
|
2007-08-10 02:44:20 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill in all variable portions of iBFT
|
|
|
|
*
|
|
|
|
* @v netdev Network device
|
|
|
|
* @v initiator_iqn Initiator IQN
|
|
|
|
* @v st_target Target socket address
|
|
|
|
* @v target_iqn Target IQN
|
|
|
|
* @ret rc Return status code
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int ibft_fill_data ( struct net_device *netdev,
|
|
|
|
struct iscsi_session *iscsi ) {
|
|
|
|
struct ibft_string_block strings = {
|
|
|
|
.table = &ibftab.table,
|
|
|
|
.offset = offsetof ( typeof ( ibftab ), strings ),
|
|
|
|
};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Fill in NIC, Initiator and Target portions */
|
|
|
|
if ( ( rc = ibft_fill_nic ( &ibftab.nic, &strings, netdev ) ) != 0 )
|
|
|
|
return rc;
|
|
|
|
if ( ( rc = ibft_fill_initiator ( &ibftab.initiator,
|
|
|
|
&strings ) ) != 0 )
|
|
|
|
return rc;
|
|
|
|
if ( ( rc = ibft_fill_target ( &ibftab.target, &strings,
|
|
|
|
iscsi ) ) != 0 )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Update checksum */
|
|
|
|
acpi_fix_checksum ( &ibftab.table.acpi );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|