Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * Filename: target_core_fabric_lib.c |
| 4 | * |
| 5 | * This file contains generic high level protocol identifier and PR |
| 6 | * handlers for TCM fabric modules |
| 7 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 8 | * (c) Copyright 2010-2013 Datera, Inc. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 9 | * |
| 10 | * Nicholas A. Bellinger <nab@linux-iscsi.org> |
| 11 | * |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 12 | ******************************************************************************/ |
| 13 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 14 | /* |
| 15 | * See SPC4, section 7.5 "Protocol specific parameters" for details |
| 16 | * on the formats implemented in this file. |
| 17 | */ |
| 18 | |
Andy Shevchenko | 11650b85 | 2011-07-18 22:26:40 -0700 | [diff] [blame] | 19 | #include <linux/kernel.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 20 | #include <linux/string.h> |
| 21 | #include <linux/ctype.h> |
| 22 | #include <linux/spinlock.h> |
Paul Gortmaker | c53181a | 2011-08-30 18:16:43 -0400 | [diff] [blame] | 23 | #include <linux/export.h> |
Bart Van Assche | a85d667 | 2017-05-23 16:48:27 -0700 | [diff] [blame] | 24 | #include <asm/unaligned.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 25 | |
Stephen Rothwell | 6546a02 | 2015-06-03 18:16:07 +1000 | [diff] [blame] | 26 | #include <scsi/scsi_proto.h> |
| 27 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 28 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 29 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 30 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 31 | #include "target_core_internal.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 32 | #include "target_core_pr.h" |
| 33 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 34 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 35 | static int sas_get_pr_transport_id( |
| 36 | struct se_node_acl *nacl, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 37 | int *format_code, |
| 38 | unsigned char *buf) |
| 39 | { |
Mimi Zohar | 8c35ad2 | 2011-09-16 08:50:30 -0400 | [diff] [blame] | 40 | int ret; |
Andy Shevchenko | 11650b85 | 2011-07-18 22:26:40 -0700 | [diff] [blame] | 41 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 42 | /* Skip over 'naa. prefix */ |
| 43 | ret = hex2bin(&buf[4], &nacl->initiatorname[4], 8); |
| 44 | if (ret) { |
| 45 | pr_debug("%s: invalid hex string\n", __func__); |
| 46 | return ret; |
| 47 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 48 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 49 | return 24; |
| 50 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 51 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 52 | static int fc_get_pr_transport_id( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 53 | struct se_node_acl *se_nacl, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 54 | int *format_code, |
| 55 | unsigned char *buf) |
| 56 | { |
Andy Shevchenko | 11650b85 | 2011-07-18 22:26:40 -0700 | [diff] [blame] | 57 | unsigned char *ptr; |
Mimi Zohar | 8c35ad2 | 2011-09-16 08:50:30 -0400 | [diff] [blame] | 58 | int i, ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 59 | u32 off = 8; |
Mimi Zohar | 8c35ad2 | 2011-09-16 08:50:30 -0400 | [diff] [blame] | 60 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 61 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 62 | * We convert the ASCII formatted N Port name into a binary |
| 63 | * encoded TransportID. |
| 64 | */ |
| 65 | ptr = &se_nacl->initiatorname[0]; |
Bodo Stroesser | 8fed04e | 2020-04-08 15:26:10 +0200 | [diff] [blame] | 66 | for (i = 0; i < 23; ) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 67 | if (!strncmp(&ptr[i], ":", 1)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 68 | i++; |
| 69 | continue; |
| 70 | } |
Mimi Zohar | 8c35ad2 | 2011-09-16 08:50:30 -0400 | [diff] [blame] | 71 | ret = hex2bin(&buf[off++], &ptr[i], 1); |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 72 | if (ret < 0) { |
| 73 | pr_debug("%s: invalid hex string\n", __func__); |
| 74 | return ret; |
| 75 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 76 | i += 2; |
| 77 | } |
| 78 | /* |
| 79 | * The FC Transport ID is a hardcoded 24-byte length |
| 80 | */ |
| 81 | return 24; |
| 82 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 83 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 84 | static int sbp_get_pr_transport_id( |
| 85 | struct se_node_acl *nacl, |
| 86 | int *format_code, |
| 87 | unsigned char *buf) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 88 | { |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 89 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 90 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 91 | ret = hex2bin(&buf[8], nacl->initiatorname, 8); |
| 92 | if (ret) { |
| 93 | pr_debug("%s: invalid hex string\n", __func__); |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | return 24; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 98 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 99 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 100 | static int srp_get_pr_transport_id( |
| 101 | struct se_node_acl *nacl, |
| 102 | int *format_code, |
| 103 | unsigned char *buf) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 104 | { |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 105 | const char *p; |
| 106 | unsigned len, count, leading_zero_bytes; |
| 107 | int rc; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 108 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 109 | p = nacl->initiatorname; |
| 110 | if (strncasecmp(p, "0x", 2) == 0) |
| 111 | p += 2; |
| 112 | len = strlen(p); |
| 113 | if (len % 2) |
| 114 | return -EINVAL; |
| 115 | |
| 116 | count = min(len / 2, 16U); |
| 117 | leading_zero_bytes = 16 - count; |
| 118 | memset(buf + 8, 0, leading_zero_bytes); |
| 119 | rc = hex2bin(buf + 8 + leading_zero_bytes, p, count); |
| 120 | if (rc < 0) { |
Bart Van Assche | c941e0d | 2019-11-07 13:55:25 -0800 | [diff] [blame] | 121 | pr_debug("hex2bin failed for %s: %d\n", p, rc); |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 122 | return rc; |
| 123 | } |
| 124 | |
| 125 | return 24; |
| 126 | } |
| 127 | |
| 128 | static int iscsi_get_pr_transport_id( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 129 | struct se_node_acl *se_nacl, |
| 130 | struct t10_pr_registration *pr_reg, |
| 131 | int *format_code, |
| 132 | unsigned char *buf) |
| 133 | { |
| 134 | u32 off = 4, padding = 0; |
Mike Christie | 639341b | 2020-07-01 20:43:23 -0500 | [diff] [blame] | 135 | int isid_len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 136 | u16 len = 0; |
| 137 | |
| 138 | spin_lock_irq(&se_nacl->nacl_sess_lock); |
| 139 | /* |
Mike Christie | a6f9b6c | 2020-07-01 20:43:21 -0500 | [diff] [blame] | 140 | * Only null terminate the last field. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 141 | * |
Mike Christie | a6f9b6c | 2020-07-01 20:43:21 -0500 | [diff] [blame] | 142 | * From spc4r37 section 7.6.4.6: TransportID for initiator ports using |
| 143 | * SCSI over iSCSI. |
| 144 | * |
| 145 | * Table 507 TPID=0 Initiator device TransportID |
| 146 | * |
| 147 | * The null-terminated, null-padded (see 4.3.2) ISCSI NAME field shall |
| 148 | * contain the iSCSI name of an iSCSI initiator node (see RFC 7143). |
| 149 | * The first ISCSI NAME field byte containing an ASCII null character |
| 150 | * terminates the ISCSI NAME field without regard for the specified |
| 151 | * length of the iSCSI TransportID or the contents of the ADDITIONAL |
| 152 | * LENGTH field. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 153 | */ |
| 154 | len = sprintf(&buf[off], "%s", se_nacl->initiatorname); |
Mike Christie | a6f9b6c | 2020-07-01 20:43:21 -0500 | [diff] [blame] | 155 | off += len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 156 | if ((*format_code == 1) && (pr_reg->isid_present_at_reg)) { |
| 157 | /* |
| 158 | * Set FORMAT CODE 01b for iSCSI Initiator port TransportID |
| 159 | * format. |
| 160 | */ |
| 161 | buf[0] |= 0x40; |
| 162 | /* |
Mike Christie | a6f9b6c | 2020-07-01 20:43:21 -0500 | [diff] [blame] | 163 | * From spc4r37 Section 7.6.4.6 |
| 164 | * |
| 165 | * Table 508 TPID=1 Initiator port TransportID. |
| 166 | * |
| 167 | * The ISCSI NAME field shall not be null-terminated |
| 168 | * (see 4.3.2) and shall not be padded. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 169 | * |
| 170 | * The SEPARATOR field shall contain the five ASCII |
| 171 | * characters ",i,0x". |
| 172 | * |
| 173 | * The null-terminated, null-padded ISCSI INITIATOR SESSION ID |
| 174 | * field shall contain the iSCSI initiator session identifier |
| 175 | * (see RFC 3720) in the form of ASCII characters that are the |
| 176 | * hexadecimal digits converted from the binary iSCSI initiator |
| 177 | * session identifier value. The first ISCSI INITIATOR SESSION |
Mike Christie | a6f9b6c | 2020-07-01 20:43:21 -0500 | [diff] [blame] | 178 | * ID field byte containing an ASCII null character terminates |
| 179 | * the ISCSI INITIATOR SESSION ID field without regard for the |
| 180 | * specified length of the iSCSI TransportID or the contents |
| 181 | * of the ADDITIONAL LENGTH field. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 182 | */ |
Mike Christie | a6f9b6c | 2020-07-01 20:43:21 -0500 | [diff] [blame] | 183 | buf[off++] = 0x2c; /* ASCII Character: "," */ |
| 184 | buf[off++] = 0x69; /* ASCII Character: "i" */ |
| 185 | buf[off++] = 0x2c; /* ASCII Character: "," */ |
| 186 | buf[off++] = 0x30; /* ASCII Character: "0" */ |
| 187 | buf[off++] = 0x78; /* ASCII Character: "x" */ |
Mike Christie | 639341b | 2020-07-01 20:43:23 -0500 | [diff] [blame] | 188 | len += 5; |
Mike Christie | a6f9b6c | 2020-07-01 20:43:21 -0500 | [diff] [blame] | 189 | |
Mike Christie | 639341b | 2020-07-01 20:43:23 -0500 | [diff] [blame] | 190 | isid_len = sprintf(buf + off, "%s", pr_reg->pr_reg_isid); |
| 191 | off += isid_len; |
| 192 | len += isid_len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 193 | } |
Mike Christie | a6f9b6c | 2020-07-01 20:43:21 -0500 | [diff] [blame] | 194 | buf[off] = '\0'; |
| 195 | len += 1; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 196 | spin_unlock_irq(&se_nacl->nacl_sess_lock); |
| 197 | /* |
| 198 | * The ADDITIONAL LENGTH field specifies the number of bytes that follow |
| 199 | * in the TransportID. The additional length shall be at least 20 and |
| 200 | * shall be a multiple of four. |
| 201 | */ |
| 202 | padding = ((-len) & 3); |
| 203 | if (padding != 0) |
| 204 | len += padding; |
| 205 | |
Bart Van Assche | a85d667 | 2017-05-23 16:48:27 -0700 | [diff] [blame] | 206 | put_unaligned_be16(len, &buf[2]); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 207 | /* |
| 208 | * Increment value for total payload + header length for |
| 209 | * full status descriptor |
| 210 | */ |
| 211 | len += 4; |
| 212 | |
| 213 | return len; |
| 214 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 215 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 216 | static int iscsi_get_pr_transport_id_len( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 217 | struct se_node_acl *se_nacl, |
| 218 | struct t10_pr_registration *pr_reg, |
| 219 | int *format_code) |
| 220 | { |
| 221 | u32 len = 0, padding = 0; |
| 222 | |
| 223 | spin_lock_irq(&se_nacl->nacl_sess_lock); |
| 224 | len = strlen(se_nacl->initiatorname); |
| 225 | /* |
| 226 | * Add extra byte for NULL terminator |
| 227 | */ |
| 228 | len++; |
| 229 | /* |
| 230 | * If there is ISID present with the registration, use format code: |
| 231 | * 01b: iSCSI Initiator port TransportID format |
| 232 | * |
| 233 | * If there is not an active iSCSI session, use format code: |
| 234 | * 00b: iSCSI Initiator device TransportID format |
| 235 | */ |
| 236 | if (pr_reg->isid_present_at_reg) { |
Masanari Iida | 35d1efe | 2012-08-16 22:43:13 +0900 | [diff] [blame] | 237 | len += 5; /* For ",i,0x" ASCII separator */ |
Mike Christie | 639341b | 2020-07-01 20:43:23 -0500 | [diff] [blame] | 238 | len += strlen(pr_reg->pr_reg_isid); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 239 | *format_code = 1; |
| 240 | } else |
| 241 | *format_code = 0; |
| 242 | spin_unlock_irq(&se_nacl->nacl_sess_lock); |
| 243 | /* |
| 244 | * The ADDITIONAL LENGTH field specifies the number of bytes that follow |
| 245 | * in the TransportID. The additional length shall be at least 20 and |
| 246 | * shall be a multiple of four. |
| 247 | */ |
| 248 | padding = ((-len) & 3); |
| 249 | if (padding != 0) |
| 250 | len += padding; |
| 251 | /* |
| 252 | * Increment value for total payload + header length for |
| 253 | * full status descriptor |
| 254 | */ |
| 255 | len += 4; |
| 256 | |
| 257 | return len; |
| 258 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 259 | |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 260 | static char *iscsi_parse_pr_out_transport_id( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 261 | struct se_portal_group *se_tpg, |
Rasmus Villemoes | 094bb5d | 2017-11-21 01:12:43 +0100 | [diff] [blame] | 262 | char *buf, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 263 | u32 *out_tid_len, |
| 264 | char **port_nexus_ptr) |
| 265 | { |
| 266 | char *p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 267 | int i; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 268 | u8 format_code = (buf[0] & 0xc0); |
| 269 | /* |
| 270 | * Check for FORMAT CODE 00b or 01b from spc4r17, section 7.5.4.6: |
| 271 | * |
| 272 | * TransportID for initiator ports using SCSI over iSCSI, |
| 273 | * from Table 388 -- iSCSI TransportID formats. |
| 274 | * |
| 275 | * 00b Initiator port is identified using the world wide unique |
| 276 | * SCSI device name of the iSCSI initiator |
| 277 | * device containing the initiator port (see table 389). |
| 278 | * 01b Initiator port is identified using the world wide unique |
| 279 | * initiator port identifier (see table 390).10b to 11b |
| 280 | * Reserved |
| 281 | */ |
| 282 | if ((format_code != 0x00) && (format_code != 0x40)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 283 | pr_err("Illegal format code: 0x%02x for iSCSI" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 284 | " Initiator Transport ID\n", format_code); |
| 285 | return NULL; |
| 286 | } |
| 287 | /* |
| 288 | * If the caller wants the TransportID Length, we set that value for the |
| 289 | * entire iSCSI Tarnsport ID now. |
| 290 | */ |
Joern Engel | 68edbce | 2014-09-02 17:49:59 -0400 | [diff] [blame] | 291 | if (out_tid_len) { |
| 292 | /* The shift works thanks to integer promotion rules */ |
Mike Christie | 169622e | 2020-07-01 20:43:20 -0500 | [diff] [blame] | 293 | *out_tid_len = get_unaligned_be16(&buf[2]); |
| 294 | /* Add four bytes for iSCSI Transport ID header */ |
| 295 | *out_tid_len += 4; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 296 | } |
Mike Christie | 169622e | 2020-07-01 20:43:20 -0500 | [diff] [blame] | 297 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 298 | /* |
Masanari Iida | 35d1efe | 2012-08-16 22:43:13 +0900 | [diff] [blame] | 299 | * Check for ',i,0x' separator between iSCSI Name and iSCSI Initiator |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 300 | * Session ID as defined in Table 390 - iSCSI initiator port TransportID |
| 301 | * format. |
| 302 | */ |
| 303 | if (format_code == 0x40) { |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 304 | p = strstr(&buf[4], ",i,0x"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 305 | if (!p) { |
Masanari Iida | 35d1efe | 2012-08-16 22:43:13 +0900 | [diff] [blame] | 306 | pr_err("Unable to locate \",i,0x\" separator" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 307 | " for Initiator port identifier: %s\n", |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 308 | &buf[4]); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 309 | return NULL; |
| 310 | } |
| 311 | *p = '\0'; /* Terminate iSCSI Name */ |
Masanari Iida | 35d1efe | 2012-08-16 22:43:13 +0900 | [diff] [blame] | 312 | p += 5; /* Skip over ",i,0x" separator */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 313 | |
| 314 | *port_nexus_ptr = p; |
| 315 | /* |
| 316 | * Go ahead and do the lower case conversion of the received |
| 317 | * 12 ASCII characters representing the ISID in the TransportID |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 318 | * for comparison against the running iSCSI session's ISID from |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 319 | * iscsi_target.c:lio_sess_get_initiator_sid() |
| 320 | */ |
| 321 | for (i = 0; i < 12; i++) { |
Mike Christie | 639341b | 2020-07-01 20:43:23 -0500 | [diff] [blame] | 322 | /* |
| 323 | * The first ISCSI INITIATOR SESSION ID field byte |
| 324 | * containing an ASCII null character terminates the |
| 325 | * ISCSI INITIATOR SESSION ID field without regard for |
| 326 | * the specified length of the iSCSI TransportID or the |
| 327 | * contents of the ADDITIONAL LENGTH field. |
| 328 | */ |
| 329 | if (*p == '\0') |
| 330 | break; |
| 331 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 332 | if (isdigit(*p)) { |
| 333 | p++; |
| 334 | continue; |
| 335 | } |
| 336 | *p = tolower(*p); |
| 337 | p++; |
| 338 | } |
Bodo Stroesser | 13ef143 | 2020-04-08 15:26:09 +0200 | [diff] [blame] | 339 | } else |
| 340 | *port_nexus_ptr = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 341 | |
Rasmus Villemoes | 094bb5d | 2017-11-21 01:12:43 +0100 | [diff] [blame] | 342 | return &buf[4]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 343 | } |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 344 | |
| 345 | int target_get_pr_transport_id_len(struct se_node_acl *nacl, |
| 346 | struct t10_pr_registration *pr_reg, int *format_code) |
| 347 | { |
| 348 | switch (nacl->se_tpg->proto_id) { |
| 349 | case SCSI_PROTOCOL_FCP: |
| 350 | case SCSI_PROTOCOL_SBP: |
| 351 | case SCSI_PROTOCOL_SRP: |
| 352 | case SCSI_PROTOCOL_SAS: |
| 353 | break; |
| 354 | case SCSI_PROTOCOL_ISCSI: |
| 355 | return iscsi_get_pr_transport_id_len(nacl, pr_reg, format_code); |
| 356 | default: |
| 357 | pr_err("Unknown proto_id: 0x%02x\n", nacl->se_tpg->proto_id); |
| 358 | return -EINVAL; |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Most transports use a fixed length 24 byte identifier. |
| 363 | */ |
| 364 | *format_code = 0; |
| 365 | return 24; |
| 366 | } |
| 367 | |
| 368 | int target_get_pr_transport_id(struct se_node_acl *nacl, |
| 369 | struct t10_pr_registration *pr_reg, int *format_code, |
| 370 | unsigned char *buf) |
| 371 | { |
| 372 | switch (nacl->se_tpg->proto_id) { |
| 373 | case SCSI_PROTOCOL_SAS: |
| 374 | return sas_get_pr_transport_id(nacl, format_code, buf); |
| 375 | case SCSI_PROTOCOL_SBP: |
| 376 | return sbp_get_pr_transport_id(nacl, format_code, buf); |
| 377 | case SCSI_PROTOCOL_SRP: |
| 378 | return srp_get_pr_transport_id(nacl, format_code, buf); |
| 379 | case SCSI_PROTOCOL_FCP: |
| 380 | return fc_get_pr_transport_id(nacl, format_code, buf); |
| 381 | case SCSI_PROTOCOL_ISCSI: |
| 382 | return iscsi_get_pr_transport_id(nacl, pr_reg, format_code, |
| 383 | buf); |
| 384 | default: |
| 385 | pr_err("Unknown proto_id: 0x%02x\n", nacl->se_tpg->proto_id); |
| 386 | return -EINVAL; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg, |
Rasmus Villemoes | 094bb5d | 2017-11-21 01:12:43 +0100 | [diff] [blame] | 391 | char *buf, u32 *out_tid_len, char **port_nexus_ptr) |
Christoph Hellwig | 2650d71 | 2015-05-01 17:47:58 +0200 | [diff] [blame] | 392 | { |
| 393 | u32 offset; |
| 394 | |
| 395 | switch (tpg->proto_id) { |
| 396 | case SCSI_PROTOCOL_SAS: |
| 397 | /* |
| 398 | * Assume the FORMAT CODE 00b from spc4r17, 7.5.4.7 TransportID |
| 399 | * for initiator ports using SCSI over SAS Serial SCSI Protocol. |
| 400 | */ |
| 401 | offset = 4; |
| 402 | break; |
| 403 | case SCSI_PROTOCOL_SBP: |
| 404 | case SCSI_PROTOCOL_SRP: |
| 405 | case SCSI_PROTOCOL_FCP: |
| 406 | offset = 8; |
| 407 | break; |
| 408 | case SCSI_PROTOCOL_ISCSI: |
| 409 | return iscsi_parse_pr_out_transport_id(tpg, buf, out_tid_len, |
| 410 | port_nexus_ptr); |
| 411 | default: |
| 412 | pr_err("Unknown proto_id: 0x%02x\n", tpg->proto_id); |
| 413 | return NULL; |
| 414 | } |
| 415 | |
| 416 | *port_nexus_ptr = NULL; |
| 417 | *out_tid_len = 24; |
| 418 | return buf + offset; |
| 419 | } |