#ifndef _SMBSRV_MLRPC_H
#define _SMBSRV_MLRPC_H
#include <stdint.h>
#include "ndl/rpcpdu.ndl"
#include "libmlrpc/mlsvc.h"
#include "libmlrpc/ndr.h"
#include <libkern/OSByteOrder.h>
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
#error Unknown native byte ordering
#endif
#define mlrpc_native_byte_order \
(OSHostByteOrder() == OSBigEndian ? MLRPC_REPLAB_INTG_BIG_ENDIAN \
: MLRPC_REPLAB_INTG_LITTLE_ENDIAN)
#define MLRPC_DRC_MASK_FAULT 0x8000
#define MLRPC_DRC_MASK_SPECIFIER 0xFF00
#define MLRPC_DRC_MASK_PTYPE 0x00FF
#define MLRPC_DRC_OK 0x0000
#define MLRPC_DRC_PTYPE_RPCHDR 0x00FF
#define MLRPC_DRC_PTYPE_API 0x00AA
#define MLRPC_DRC_IS_OK(DRC) (((DRC)&MLRPC_DRC_MASK_SPECIFIER) == 0)
#define MLRPC_DRC_IS_FAULT(DRC) (((DRC)&MLRPC_DRC_MASK_FAULT) != 0)
#define MLRPC_DRC_FAULT_MODE_MISMATCH 0x8100
#define MLRPC_DRC_RECEIVED 0x0200
#define MLRPC_DRC_FAULT_RECEIVED_RUNT 0x8300
#define MLRPC_DRC_FAULT_RECEIVED_MALFORMED 0x8400
#define MLRPC_DRC_DECODED 0x0500
#define MLRPC_DRC_FAULT_DECODE_FAILED 0x8600
#define MLRPC_DRC_ENCODED 0x0700
#define MLRPC_DRC_FAULT_ENCODE_FAILED 0x8800
#define MLRPC_DRC_FAULT_ENCODE_TOO_BIG 0x8900
#define MLRPC_DRC_SENT 0x0A00
#define MLRPC_DRC_FAULT_SEND_FAILED 0x8B00
#define MLRPC_DRC_FAULT_RESOURCE_1 0x9100
#define MLRPC_DRC_FAULT_RESOURCE_2 0x9200
#define MLRPC_DRC_FAULT_PARAM_0_INVALID 0xC000
#define MLRPC_DRC_FAULT_PARAM_0_UNIMPLEMENTED 0xD000
#define MLRPC_DRC_FAULT_PARAM_1_INVALID 0xC100
#define MLRPC_DRC_FAULT_PARAM_1_UNIMPLEMENTED 0xD100
#define MLRPC_DRC_FAULT_PARAM_2_INVALID 0xC200
#define MLRPC_DRC_FAULT_PARAM_2_UNIMPLEMENTED 0xD200
#define MLRPC_DRC_FAULT_PARAM_3_INVALID 0xC300
#define MLRPC_DRC_FAULT_PARAM_3_UNIMPLEMENTED 0xD300
#define MLRPC_DRC_FAULT_OUT_OF_MEMORY 0xF000
#define MLRPC_DRC_FAULT_RPCHDR_PTYPE_INVALID 0xC0FF
#define MLRPC_DRC_FAULT_RPCHDR_PTYPE_UNIMPLEMENTED 0xD0FF
#define MLRPC_DRC_FAULT_REQUEST_PCONT_INVALID 0xC000
#define MLRPC_DRC_FAULT_REQUEST_OPNUM_INVALID 0xC100
#define MLRPC_DRC_FAULT_BIND_PCONT_BUSY 0xC00B
#define MLRPC_DRC_FAULT_BIND_UNKNOWN_SERVICE 0xC10B
#define MLRPC_DRC_FAULT_BIND_NO_SLOTS 0x910B
#define MLRPC_DRC_BINDING_MADE 0x000B
#define MLRPC_DRC_FAULT_API_SERVICE_INVALID 0xC0AA
#define MLRPC_DRC_FAULT_API_BIND_NO_SLOTS 0x91AA
#define MLRPC_DRC_FAULT_API_OPNUM_INVALID 0xC1AA
struct mlrpc_xaction;
typedef struct mlrpc_stub_table {
int (*func)(void *param, struct mlrpc_xaction *mreq);
unsigned short opnum;
} mlrpc_stub_table_t;
typedef struct mlrpc_service {
char *name;
char *desc;
char *endpoint;
char *sec_addr_port;
char *abstract_syntax_uuid;
int abstract_syntax_version;
char *transfer_syntax_uuid;
int transfer_syntax_version;
unsigned bind_instance_size;
int (*bind_req)();
int (*unbind_and_close)();
int (*call_stub)(struct mlrpc_xaction *mreq);
struct ndr_typeinfo *interface_ti;
struct mlrpc_stub_table *stub_table;
} mlrpc_service_t;
typedef struct ndr_hdid {
uint32_t data[5];
} ndr_hdid_t;
typedef struct ndr_handle {
struct ndr_handle *nh_next;
ndr_hdid_t nh_id;
int nh_fid;
const mlrpc_service_t *nh_svc;
void *nh_data;
} ndr_handle_t;
struct mlrpc_binding {
struct mlrpc_binding *next;
mlrpc_p_context_id_t p_cont_id;
unsigned char which_side;
void * context;
struct mlrpc_service *service;
void *instance_specific;
};
#define MLRPC_BIND_SIDE_CLIENT 1
#define MLRPC_BIND_SIDE_SERVER 2
#define MLRPC_BINDING_TO_SPECIFIC(BINDING, TYPE) \
((TYPE *) (BINDING)->instance_specific)
typedef struct mlrpc_heap mlrpc_heap_t;
#define MLRPC_HRST_PRESERVED 1
typedef struct mlrpc_heapref {
mlrpc_heap_t *heap;
char *recv_pdu_buf;
char *send_pdu_buf;
unsigned int state;
} mlrpc_heapref_t;
struct mlrpc_vcb {
uint32_t vc_first_is;
uint32_t vc_length_is;
uint16_t buffer[];
};
typedef struct mlrpc_vcbuf {
uint16_t wclen;
uint16_t wcsize;
struct mlrpc_vcb *vcb;
} mlrpc_vcbuf_t;
mlrpc_heap_t *mlrpc_heap_create(void);
void mlrpc_heap_destroy(mlrpc_heap_t *);
void *mlrpc_heap_malloc(mlrpc_heap_t *, size_t);
char *mlrpc_heap_strsave(mlrpc_heap_t *, const char *);
void mlrpc_heap_mkvcs(mlrpc_heap_t *, const char *, mlrpc_vcbuf_t *);
size_t mlrpc_heap_used(mlrpc_heap_t *);
#define MLRPC_HEAP_MALLOC(MXA, SIZE) \
mlrpc_heap_malloc((MXA)->heap, SIZE)
#define MLRPC_HEAP_NEW(MXA, TYPE) \
mlrpc_heap_malloc((MXA)->heap, sizeof (TYPE))
#define MLRPC_HEAP_NEWN(MXA, TYPE, N) \
mlrpc_heap_malloc((MXA)->heap, sizeof (TYPE)*(N))
#define MLRPC_HEAP_STRSAVE(MXA, STR) \
mlrpc_heap_strsave((MXA)->heap, (STR))
typedef struct mlrpc_xaction {
int fid;
unsigned short ptype;
unsigned short opnum;
struct mlndr_stream recv_mlnds;
mlrpcconn_hdr_t recv_hdr;
struct mlndr_stream send_mlnds;
mlrpcconn_hdr_t send_hdr;
struct mlrpc_binding *binding;
struct mlrpc_binding *binding_list;
mlrpc_heap_t *heap;
struct mlsvc_rpc_context *context;
} ndr_xa_t;
typedef ssize_t (*smbrdr_read_t) (
void * xa_context,
int fid,
uint8_t * buf,
size_t buflen);
typedef ssize_t (*smbrdr_transact_t) (
void * xa_context,
int fid,
const uint8_t * out_buf,
size_t out_len,
uint8_t * in_buf,
size_t in_len);
struct mlrpc_smb_client {
void * smb_context;
smbrdr_transact_t smb_transact;
smbrdr_read_t smb_readx;
};
struct mlrpc_client {
int (*xa_init)(struct mlrpc_client *, struct mlrpc_xaction *,
mlrpc_heap_t *);
int (*xa_exchange)(struct mlrpc_client *, struct mlrpc_xaction *);
int (*xa_read)(struct mlrpc_client *, struct mlrpc_xaction *);
int (*xa_preserve)(struct mlrpc_client *, struct mlrpc_xaction *,
mlrpc_heapref_t *);
int (*xa_destruct)(struct mlrpc_client *, struct mlrpc_xaction *);
void (*xa_release)(struct mlrpc_client *, mlrpc_heapref_t *);
void *context;
struct mlrpc_smb_client smbcli;
struct mlrpc_binding *binding_list;
uint32_t next_call_id;
unsigned next_p_cont_id;
};
#ifndef MTS_WCHAR_T
#define MTS_WCHAR_T
typedef uint16_t mts_wchar_t;
#endif
size_t mts_mbstowcs(mts_wchar_t *, const char *, size_t);
ssize_t mts_mbtowc(mts_wchar_t *, const char *, size_t);
size_t mts_wctomb(char *, mts_wchar_t);
size_t mts_wcstombs(char *, const mts_wchar_t *, size_t);
size_t mts_wcequiv_strlen(const char *);
size_t mts_sbequiv_strlen(const char *);
ssize_t mts_stombs(char *, const char *, size_t);
ssize_t mts_mbstos(char *, const char *);
#define MTS_MB_CHAR_MAX 3
int mlnds_initialize(struct mlndr_stream *, unsigned, int, mlrpc_heap_t *);
void mlnds_destruct(struct mlndr_stream *);
int mlrpc_c_bind(struct mlrpc_client *, const char *, struct mlrpc_binding **);
int mlrpc_c_call(struct mlrpc_binding *, int, void *, mlrpc_heapref_t *);
void mlrpc_c_free_heap(struct mlrpc_binding *, mlrpc_heapref_t *);
int mlrpc_encode_decode_common(struct mlrpc_xaction *, int, unsigned,
struct ndr_typeinfo *, void *);
int mlrpc_decode_call(struct mlrpc_xaction *, void *);
int mlrpc_encode_return(struct mlrpc_xaction *, void *);
int mlrpc_encode_call(struct mlrpc_xaction *, void *);
int mlrpc_decode_return(struct mlrpc_xaction *, void *);
int mlrpc_decode_pdu_hdr(struct mlrpc_xaction *);
int mlrpc_encode_pdu_hdr(struct mlrpc_xaction *);
void mlrpc_decode_frag_hdr(struct mlndr_stream *,
mlrpcconn_request_hdr_t *, const uint8_t *);
unsigned mlrpc_bind_ack_hdr_size(struct mlrpcconn_bind_ack_hdr *);
#if 0
int mlrpc_generic_call_stub(struct mlrpc_xaction *);
#endif
struct mlrpc_stub_table *mlrpc_find_stub_in_svc(mlrpc_service_t *, int);
mlrpc_service_t *mlrpc_find_service_by_name(const char *);
mlrpc_service_t *mlrpc_find_service_by_uuids(ndr_uuid_t *, int,
ndr_uuid_t *, int);
int mlrpc_register_service(mlrpc_service_t *);
void mlrpc_unregister_service(mlrpc_service_t *);
void mlrpc_uuid_to_str(ndr_uuid_t *, char *, size_t);
int mlrpc_str_to_uuid(char *, ndr_uuid_t *);
void mlrpc_binding_pool_initialize(struct mlrpc_binding **,
struct mlrpc_binding pool[], unsigned);
struct mlrpc_binding *mlrpc_find_binding(struct mlrpc_xaction *,
mlrpc_p_context_id_t);
struct mlrpc_binding *mlrpc_new_binding(struct mlrpc_xaction *);
ndr_hdid_t *ndr_hdalloc(const ndr_xa_t *, const void *);
void ndr_hdfree(const ndr_xa_t *, const ndr_hdid_t *);
ndr_handle_t *ndr_hdlookup(const ndr_xa_t *, const ndr_hdid_t *);
void ndr_hdclose(int fid);
#ifdef __cplusplus
}
#endif
#endif