1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SMBSRV_NETBIOS_H 27 #define _SMBSRV_NETBIOS_H 28 29 /* 30 * NetBIOS over TCP/IP interface definitions. NetBIOS over TCP/IP is 31 * documented in the following RFC documents: 32 * 33 * RFC 1001: Protocol Standard for a NetBIOS Service on a TCP/UDP 34 * Transport: Concepts and Methods 35 * 36 * RFC 1002: Protocol Standard for a NetBIOS Service on a TCP/UDP 37 * Transport: Detailed Specifications 38 * 39 * These documents reference RCF883. 40 * RFC 883: Domain Names - Implementation and Specification 41 */ 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 48 /* 49 * NetBIOS names in NetBIOS packets are valid domain names as defined in 50 * RFC 883. Each label is limited to 63 bytes with an overall length of 51 * 255 bytes as described in RFC 1002 section 4.1. This is known as 52 * second-level encoding. In first-level encoding the label lengths are 53 * represented as dots (.). 54 * 55 * RFC 1001 section 14.1 describes first-level encoding of the NetBIOS 56 * name (hostname) and scope. The ASCII name is padded to 15 bytes using 57 * spaces and a one byte type or suffix is written to the 16th byte. 58 * This is then encoded as a 32 byte string. 59 * 60 * NetBIOS Name: NetBIOS 61 * NetBIOS Scope: PROCOM.COM 62 * First Level: EOGFHEECEJEPFDCACACACACACACACACA.PROCOM.COM 63 * Second Level: <32>EOGFHEECEJEPFDCACACACACACACACACA<6>PROCOM<3>COM<0> 64 */ 65 #define NETBIOS_NAME_SZ 16 66 #define NETBIOS_ENCODED_NAME_SZ 32 67 #define NETBIOS_LABEL_MAX 63 68 #define NETBIOS_DOMAIN_NAME_MAX 255 69 #define NETBIOS_DOMAIN_NAME_BUFLEN (NETBIOS_DOMAIN_NAME_MAX + 1) 70 #define NETBIOS_SESSION_REQUEST_DATA_LENGTH \ 71 ((NETBIOS_ENCODED_NAME_SZ + 2) * 2) 72 73 #define NETBIOS_HDR_SZ 4 /* bytes */ 74 /* 75 * Session Packet Types (RFC 1002 4.3.1). 76 */ 77 #define SESSION_MESSAGE 0x00 78 #define SESSION_REQUEST 0x81 79 #define POSITIVE_SESSION_RESPONSE 0x82 80 #define NEGATIVE_SESSION_RESPONSE 0x83 81 #define RETARGET_SESSION_RESPONSE 0x84 82 #define SESSION_KEEP_ALIVE 0x85 83 84 /* 85 * NEGATIVE SESSION RESPONSE packet error code values (RFC 1002 4.3.4). 86 */ 87 #define SESSION_NOT_LISTENING_ON_CALLED_NAME 0x80 88 #define SESSION_NOT_LISTENING_FOR_CALLING_NAME 0x81 89 #define SESSION_CALLED_NAME_NOT_PRESENT 0x82 90 #define SESSION_INSUFFICIENT_RESOURCES 0x83 91 #define SESSION_UNSPECIFIED_ERROR 0x8F 92 93 /* 94 * Time conversions 95 */ 96 #define MILLISECONDS 1 97 #define SECONDS (1000 * MILLISECONDS) 98 #define MINUTES (60 * SECONDS) 99 #define HOURS (60 * MINUTES) 100 #define TO_SECONDS(x) ((x) / 1000) 101 #define TO_MILLISECONDS(x) ((x) * 1000) 102 103 /* 104 * DATAGRAM service definitions 105 */ 106 #define DATAGRAM_DESTINATION_NAME_NOT_PRESENT 0x82 107 #define DATAGRAM_INVALID_SOURCE_NAME_FORMAT 0x83 108 #define DATAGRAM_INVALID_DESTINATION_NAME_FORMAT 0x84 109 110 #define NAME_SERVICE_TCP_PORT 137 111 #define NAME_SERVICE_UDP_PORT 137 112 #define DGM_SRVC_UDP_PORT 138 113 #define SSN_SRVC_TCP_PORT 139 114 #define MAX_DATAGRAM_LENGTH 576 115 #define DATAGRAM_HEADER_LENGTH 14 116 #define DATAGRAM_ERR_HEADER_LENGTH 11 117 #define MAX_NAME_LENGTH 256 118 #define BCAST_REQ_RETRY_COUNT 2 119 #define UCAST_REQ_RETRY_COUNT 2 120 #define BCAST_REQ_RETRY_TIMEOUT (500 * MILLISECONDS) 121 #define UCAST_REQ_RETRY_TIMEOUT (500 * MILLISECONDS) 122 #define CONFLICT_TIMER (1 * SECONDS) 123 #define INFINITE_TTL 0 124 #define DEFAULT_TTL (600 * SECONDS) 125 #define SSN_RETRY_COUNT 4 126 #define SSN_CLOSE_TIMEOUT (30 * SECONDS) 127 /* 128 * K.L. The keep alive time out use to be default to 129 * 900 seconds. It is not long enough for some applications 130 * i.e. MS Access. Therefore, the timeout is increased to 131 * 5400 seconds. 132 */ 133 #define SSN_KEEP_ALIVE_TIMEOUT (90 * 60) /* seconds */ 134 #define FRAGMENT_TIMEOUT (2 * SECONDS) 135 136 /* smb_netbios_util.c */ 137 extern int netbios_first_level_name_decode(char *in, char *name, char *scope); 138 extern int netbios_first_level_name_encode(unsigned char *name, 139 unsigned char *scope, unsigned char *out, int max_out); 140 extern int netbios_name_isvalid(char *in, char *out); 141 142 #ifdef __cplusplus 143 } 144 #endif 145 146 #endif /* _SMBSRV_NETBIOS_H */ 147