Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_iscsi_api.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /**
34  * @file
35  * Defines the iSCSI interface functions to higher level iSCSI software
36  */
37 
38 #ifndef _OCS_ISCSI_API_H
39 #define _OCS_ISCSI_API_H
40 
41 #include "ocs_os.h"
42 
43 /**
44  * @brief enum identifying the types of IP addresses.
45  */
46 typedef enum {
47  /* Valid for requesting addresses */
53 
54 /**
55  * @brief enum identifying the types of IP addresses.
56  */
57 typedef enum {
58  /* Valid for requesting addresses */
62 
63 /**
64  * @brief enum identifying the link state.
65  */
66 typedef enum {
70 
71 /**
72  * @brief structure wrapping an IP address together with it's type.
73  */
74 typedef struct {
76  uint8_t ip_address[16];
78 
79 /**
80  * @brief structure wrapping an IP address and subnet together with their type.
81  */
82 typedef struct {
84  uint8_t ip_address[16];
85  uint8_t subnet[16];
87 
88 /**
89  * @brief structure for storing CHAP usernames and passwords.
90  */
91 typedef struct ocs_chap_user_s {
93  uint32_t type; /* CHAP type indicates Incoming (one-way) or Outgoing (mutual-chap) */
94  uint32_t mode; /* OCS initiator or target */
95  char username[32];
96  char secret[32];
98 
99 /**
100  * @brief structure for storing VLAN id and interface handle together
101  */
102 typedef struct ocs_vlan_portal_info_s {
105  uint32_t vlan_id;
107 
108 struct iscsi_api_s;
109 
110 /***************************************************************************
111  * iSCSI API objects
112  *
113  * Several objects used by the iSCSI API layer so that they can be used by the
114  * managment code. These structures should be modified as required to represent
115  * a customer implementation.
116  */
117 
118 
119 /**
120  * @brief Stores information needed to manage targets
121  */
122 typedef struct iscsi_api_tgt_s
123 {
125  char tgt_name[OCS_MAX_ISCSI_NAME];
126  char tgt_alias[OCS_ISCSI_MAX_ALIAS_SIZE];
128 
129 typedef struct iscsi_api_s
130 {
131  ocs_sem_t link_cfg_sem;
132  ocs_thread_t link_cfg_thread;
137 
138  char ini_name[OCS_MAX_ISCSI_NAME];
140 
141  ocs_ip_address_subnet_t ipsub; /* for initial cofiguration only */
147  char isns_eid[40];
148 
149  ocs_lock_t api_list_lock;
150  ocs_list_t tgt_list;
151  ocs_list_t chap_list;
152  ocs_list_t portal_list;
153 } iscsi_api_t;
154 
155 
156 /* *****************************************************************
157  * Calls from transport code to higher level driver.
158  * *****************************************************************
159  */
160 
161 /* call related to targets */
162 char* ocs_iscsi_tgt_get_names(ocs_t *ocs, uint32_t index);
163 char* ocs_iscsi_tgt_get_alias(ocs_t *ocs, uint32_t index);
164 ocs_ip_address_t *ocs_iscsi_tgt_get_ip_address(ocs_t *ocs, char *tgt_name, uint32_t index);
165 uint32_t ocs_iscsi_tgt_get_portal_group(ocs_t *ocs, char *tgt_name, ocs_ip_address_t *ip_address);
166 uint8_t ocs_iscsi_tgt_require_chap(ocs_t *ocs, char *tgt_name, ocs_session_type_e type);
167 
168 uint32_t ocs_iscsi_tgt_is_access_allowed(ocs_t *ocs, char *tgt_name, char *ini_name);
169 
170 /* call related to initiator */
171 char* ocs_iscsi_ini_get_name(ocs_t *ocs);
172 char* ocs_iscsi_ini_get_alias(ocs_t *ocs);
173 
174 /* call related to initiators and targets */
175 int32_t ocs_iscsi_api_initialize(ocs_t *ocs);
176 int32_t ocs_iscsi_api_shutdown(ocs_t *ocs);
177 void ocs_iscsi_api_link_state(ocs_t *ocs, ocs_link_state_e link_state);
178 char *ocs_iscsi_get_chap_name(ocs_t *ocs, uint8_t sess_type,
179  uint32_t mode, uint32_t type);
180 char *ocs_iscsi_get_chap_secret(ocs_t *ocs, char *name, uint32_t mode,
181  uint32_t type, uint32_t *secret_len);
182 uint32_t ocs_iscsi_get_max_cxns(ocs_t *ocs, char *tgt_name, char *ini_name);
183 
184 
185 /* *****************************************************************
186  * Calls from the higher level driver to the transport code
187  * *****************************************************************
188  */
189 void ocs_iscsi_tgt_del_sport(ocs_t *ocs, uint32_t sport_index);
190 int32_t ocs_iscsi_tgt_add_sport(ocs_t *ocs, ocs_sport_t *sport);
191 ocs_sport_t *ocs_iscsi_tgt_get_free_sport(ocs_t *ocs);
192 int32_t ocs_iscsi_tgt_add(ocs_t *ocs, char* name, char* alias);
193 int32_t ocs_iscsi_mac_set(ocs_t *ocs, uint8_t *mac_address);
194 uint8_t *ocs_iscsi_mac_get(ocs_t *ocs);
195 int32_t ocs_iscsi_ip_address_add(ocs_t *ocs,
196  ocs_hal_portal_t portal,
197  ocs_ip_address_subnet_t *ipsub);
198 int32_t ocs_iscsi_ip_address_remove(ocs_t *ocs,
199  ocs_hal_portal_t portal,
200  ocs_ip_address_subnet_t *ipsub);
201 int32_t ocs_iscsi_ip_address_query(ocs_t *ocs,
202  ocs_hal_portal_t portal,
203  ocs_ip_type_e ip_type,
204  uint32_t max_entries,
205  uint32_t *num_ips,
206  ocs_ip_address_subnet_t *ipsub);
207 
208 int32_t ocs_iscsi_find_portal_from_vlan(ocs_t *ocs, uint32_t vlan_id,
209  ocs_hal_portal_t *iface_handle);
210 int32_t ocs_iscsi_portal_remove_ip_addresses(ocs_t *ocs,
211  ocs_hal_portal_t iface_handle);
212 int32_t ocs_iscsi_find_portal_from_vlan(ocs_t *ocs, uint32_t vlan_id,
213  ocs_hal_portal_t *iface_handle);
215 int32_t ocs_iscsi_portal_create(ocs_t *ocs, unsigned int vlan_tag,
216  ocs_hal_portal_t *portal);
217 int32_t ocs_iscsi_portal_delete(ocs_t *ocs, ocs_hal_portal_t portal);
218 
219 int32_t ocs_iscsi_listen_start(ocs_t *ocs, ocs_ip_address_t *ip,
220  uint16_t tcp_port);
221 int32_t ocs_iscsi_listen_stop(ocs_t *ocs, ocs_ip_address_t *ip,
222  uint16_t tcp_port);
223 int32_t ocs_iscsi_gateway_set(ocs_t *ocs, ocs_ip_address_t *gateway);
224 int32_t ocs_iscsi_mtu_set(ocs_t *ocs, uint8_t is_jumbo);
225 int32_t ocs_iscsi_isns_discover(ocs_t *ocs, ocs_hal_portal_t portal,
226  uint32_t max_entries,
227  uint32_t *num_ips,
228  ocs_ip_address_t *ip);
229 int32_t ocs_iscsi_isns_esi_listen_start(ocs_t *ocs, ocs_ip_address_t *ip,
230  uint16_t tcp_port);
231 int32_t ocs_iscsi_isns_esi_listen_stop(ocs_t *ocs, ocs_ip_address_t *ip,
232  uint16_t tcp_port);
233 int32_t ocs_iscsi_isns_send(ocs_t *ocs, ocs_ip_address_t *isns_server,
234  uint32_t tcp_port,
235  void *pkt, uint32_t *pkt_len, uint32_t buff_len);
236 
237 int32_t ocs_iscsi_chap_user_add(ocs_t *ocs, char *username, char *secret,
238  uint32_t type, uint32_t mode);
239 int32_t ocs_iscsi_chap_user_del(ocs_t *ocs, char *username,
240  uint32_t type, uint32_t mode);
241 int32_t ocs_iscsi_chap_list_get(ocs_t *ocs, char *userbuf, int32_t buflen);
242 
243 typedef int32_t (*ocs_iscsi_pdu_cb_t)(ocs_io_t *io, uint32_t exp_cmdsn, uint32_t max_cmdsn, uint8_t response);
244 int32_t ocs_iscsi_unassisted_pdu_send(ocs_t *ocs, ocs_io_t *io, ocs_cxn_t *cxn, void *bhs, void *data,
245  uint32_t data_size, bool is_login, bool set_dm,
246  ocs_iscsi_pdu_cb_t cb);
247 int32_t ocs_iscsi_send_context_udpate(ocs_cxn_t *cxn);
248 
249 #endif /* !_OCS_ISCSI_API_H */
250 
251 /* vim: set noexpandtab textwidth=120: */
int32_t ocs_iscsi_unassisted_pdu_send(ocs_t *ocs, ocs_io_t *io, ocs_cxn_t *cxn, void *bhs, void *data, uint32_t data_size, bool is_login, bool set_dm, ocs_iscsi_pdu_cb_t cb)
structure for storing VLAN id and interface handle together
ocs_sport_t * ocs_iscsi_tgt_get_free_sport(ocs_t *ocs)
Get a next free sport object index.
Definition: ocs_iscsi_api.c:57
ocs_link_state_e
enum identifying the link state.
Definition: ocs_iscsi_api.h:66
int32_t ocs_iscsi_tgt_add(ocs_t *ocs, char *name, char *alias)
Adds a target.
ocs_list_t ocs_list_link_t
Definition: ocs_list.h:84
int32_t ocs_iscsi_isns_esi_listen_start(ocs_t *ocs, ocs_ip_address_t *ip, uint16_t tcp_port)
Starts an iSNS ESI TCP listen socket.
Definition: ocs_iscsi.c:1037
uint32_t ocs_iscsi_tgt_is_access_allowed(ocs_t *ocs, char *tgt_name, char *ini_name)
Checks if this initiator is allowed access to a target.
ocs_ip_address_t * ocs_iscsi_tgt_get_ip_address(ocs_t *ocs, char *tgt_name, uint32_t index)
Returns the IP address of the target name based on the index.
ocs_list_link_t link
Definition: ocs_iscsi_api.h:92
structure for storing CHAP usernames and passwords.
Definition: ocs_iscsi_api.h:91
uint32_t ocs_iscsi_tgt_get_portal_group(ocs_t *ocs, char *tgt_name, ocs_ip_address_t *ip_address)
Returns the portal group of an IP address of the target name.
ocs_list_t chap_list
int32_t ocs_iscsi_mtu_set(ocs_t *ocs, uint8_t is_jumbo)
Sets the TCP MTU size of the iSCSI device.
Definition: ocs_iscsi.c:2173
int32_t ocs_iscsi_find_portal_from_vlan(ocs_t *ocs, uint32_t vlan_id, ocs_hal_portal_t *iface_handle)
Helper function to find respective interface handle of VLAN id.
Definition: ocs_iscsi.c:2921
ocs_lock_t api_list_lock
ocs_session_type_e
enum identifying the types of IP addresses.
Definition: ocs_iscsi_api.h:57
int32_t ocs_iscsi_listen_start(ocs_t *ocs, ocs_ip_address_t *ip, uint16_t tcp_port)
Starts a TCP listen socket.
Definition: ocs_iscsi.c:3227
int32_t ocs_iscsi_chap_user_del(ocs_t *ocs, char *username, uint32_t type, uint32_t mode)
Delete CHAP user.
char * ocs_iscsi_ini_get_name(ocs_t *ocs)
Return this initiator's name.
uint8_t ocs_iscsi_tgt_require_chap(ocs_t *ocs, char *tgt_name, ocs_session_type_e type)
Returns TRUE if CHAP is required for the session type.
const char * name
Definition: ocs_ddump.h:54
int32_t ocs_iscsi_send_context_udpate(ocs_cxn_t *cxn)
Sends the login parameters to the FW.
uint32_t ocs_hal_portal_t
Definition: ocs_common.h:204
#define OCS_ISCSI_MAX_ALIAS_SIZE
char * ocs_iscsi_tgt_get_names(ocs_t *ocs, uint32_t index)
Returns the target name based on the index.
ocs_ip_type_e ip_type
Definition: ocs_iscsi_api.h:75
bool cfg_thread_started
uint8_t * ocs_iscsi_mac_get(ocs_t *ocs)
Gets the MAC address of the iSCSI device.
Definition: ocs_iscsi.c:1323
char * ocs_iscsi_get_chap_name(ocs_t *ocs, uint8_t sess_type, uint32_t mode, uint32_t type)
Returns the CHAP user name of corresponding type.
int32_t ocs_iscsi_chap_user_add(ocs_t *ocs, char *username, char *secret, uint32_t type, uint32_t mode)
Add CHAP user. If CHAP user of same type is already exists, return error.
int32_t ocs_iscsi_listen_stop(ocs_t *ocs, ocs_ip_address_t *ip, uint16_t tcp_port)
Stops a TCP listen socket.
Definition: ocs_iscsi.c:3275
ocs_ip_address_subnet_t ipsub
ocs_hal_portal_t ocs_iscsi_portal_get_default(ocs_t *ocs)
Retrieves the default portal.
Definition: ocs_iscsi.c:2816
int32_t ocs_iscsi_ip_address_remove(ocs_t *ocs, ocs_hal_portal_t portal, ocs_ip_address_subnet_t *ipsub)
Remove the IP address to the specified interface.
Definition: ocs_iscsi.c:2510
void ocs_iscsi_api_link_state(ocs_t *ocs, ocs_link_state_e link_state)
Notifies the higher level iSCSI software of the link state.
bool isns_registered
int32_t ocs_iscsi_ip_address_query(ocs_t *ocs, ocs_hal_portal_t portal, ocs_ip_type_e ip_type, uint32_t max_entries, uint32_t *num_ips, ocs_ip_address_subnet_t *ipsub)
Queries the IP addresses on the default interface.
Definition: ocs_iscsi.c:2567
ocs_hal_portal_t portal
ocs_hal_portal_t iface_handle
int32_t ocs_iscsi_api_initialize(ocs_t *ocs)
Initialize the higher level iSCSI software.
ocs_thread_t link_cfg_thread
ocs_ip_address_t gateway
int32_t ocs_iscsi_isns_esi_listen_stop(ocs_t *ocs, ocs_ip_address_t *ip, uint16_t tcp_port)
Stops an iSNS ESI TCP listen socket.
Definition: ocs_iscsi.c:1087
char * ocs_iscsi_get_chap_secret(ocs_t *ocs, char *name, uint32_t mode, uint32_t type, uint32_t *secret_len)
Returns the unenctypted CHAP secret for a specific user name. Note: Passwords should be at least 16 c...
bool link_configured
int32_t ocs_iscsi_portal_delete(ocs_t *ocs, ocs_hal_portal_t portal)
Removes a previously-created portal.
Definition: ocs_iscsi.c:3183
int32_t ocs_iscsi_gateway_set(ocs_t *ocs, ocs_ip_address_t *gateway)
Sets the IP gateway address.
Definition: ocs_iscsi.c:2771
int32_t ocs_iscsi_mac_set(ocs_t *ocs, uint8_t *mac_address)
Sets the MAC address of the iSCSI device.
Definition: ocs_iscsi.c:1281
int32_t ocs_iscsi_tgt_add_sport(ocs_t *ocs, ocs_sport_t *sport)
Add sport to iscsi target.
Definition: ocs_iscsi_api.c:85
structure wrapping an IP address and subnet together with their type.
Definition: ocs_iscsi_api.h:82
char * ocs_iscsi_ini_get_alias(ocs_t *ocs)
Returns the initiator alias.
int32_t ocs_iscsi_portal_remove_ip_addresses(ocs_t *ocs, ocs_hal_portal_t iface_handle)
Check and remove IP addresses of the corresponding interface.
Definition: ocs_iscsi.c:2862
ocs_ip_type_e
enum identifying the types of IP addresses.
Definition: ocs_iscsi_api.h:46
ocs_list_link_t link
int32_t ocs_iscsi_chap_list_get(ocs_t *ocs, char *userbuf, int32_t buflen)
Return CHAP list items.
bool enable_mgmt_flag
int32_t ocs_iscsi_isns_send(ocs_t *ocs, ocs_ip_address_t *isns_server, uint32_t tcp_port, void *buffer, uint32_t *pkt_len, uint32_t buff_len)
Sends an iSNS packet to a server to test the interface.
Definition: ocs_iscsi.c:1196
int32_t ocs_iscsi_ip_address_add(ocs_t *ocs, ocs_hal_portal_t portal, ocs_ip_address_subnet_t *ipsub)
Adds the IP address to the specified interface.
Definition: ocs_iscsi.c:2417
ocs_ip_address_t subnet
ocs_list_t portal_list
int32_t ocs_iscsi_isns_discover(ocs_t *ocs, ocs_hal_portal_t portal, uint32_t max_entries, uint32_t *num_ips, ocs_ip_address_t *ip)
Discovers the iSNS through the DHCP service.
Definition: ocs_iscsi.c:1138
Stores information needed to manage targets.
#define OCS_MAX_ISCSI_NAME
Definition: ocs_common.h:240
ocs_ip_address_t * isns_servers
int32_t ocs_iscsi_portal_create(ocs_t *ocs, unsigned int vlan_id, ocs_hal_portal_t *portal)
Creates a portal for a VLAN.
Definition: ocs_iscsi.c:3125
uint32_t ocs_iscsi_get_max_cxns(ocs_t *ocs, char *tgt_name, char *ini_name)
Returns the maximum number of connections allowed per session.
int32_t(* ocs_iscsi_pdu_cb_t)(ocs_io_t *io, uint32_t exp_cmdsn, uint32_t max_cmdsn, uint8_t response)
ocs_list_t tgt_list
ocs_list_link_t link
structure wrapping an IP address together with it's type.
Definition: ocs_iscsi_api.h:74
void ocs_iscsi_tgt_del_sport(ocs_t *ocs, uint32_t sport_index)
Delete sport from iscsi target.
char * ocs_iscsi_tgt_get_alias(ocs_t *ocs, uint32_t index)
Returns the target alias based on the index.
ocs_sem_t link_cfg_sem
int32_t ocs_iscsi_api_shutdown(ocs_t *ocs)
Initialize the higher level iSCSI software.