1/*
2 * Copyright (c) 2008 - 2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef _UPI_MBUF_H_
25#define _UPI_MBUF_H_
26
27#include <stdint.h>
28/*
29 * User land mbuf routine, never use in kernel code. See kpi_mbuf.h in the kernel
30 * for more details. This code was derived from the darwin source and tries to
31 * following the same kpis. Any differnece are kept in the routine themself
32 * and never exposed to the calling process.
33 *
34 * See darwin ./bsd/sys/kpi_mbuf.h
35 */
36#ifndef KERNEL
37
38enum {
39	MBUF_TYPE_FREE		= 0,	/* should be on free list */
40	MBUF_TYPE_DATA		= 1,	/* dynamic (data) allocation */
41	MBUF_TYPE_HEADER	= 2,	/* packet header */
42	MBUF_TYPE_SOCKET	= 3,	/* socket structure */
43	MBUF_TYPE_PCB		= 4,	/* protocol control block */
44	MBUF_TYPE_RTABLE	= 5,	/* routing tables */
45	MBUF_TYPE_HTABLE	= 6,	/* IMP host tables */
46	MBUF_TYPE_ATABLE	= 7,	/* address resolution tables */
47	MBUF_TYPE_SONAME	= 8,	/* socket name */
48	MBUF_TYPE_SOOPTS	= 10,	/* socket options */
49	MBUF_TYPE_FTABLE	= 11,	/* fragment reassembly header */
50	MBUF_TYPE_RIGHTS	= 12,	/* access rights */
51	MBUF_TYPE_IFADDR	= 13,	/* interface address */
52	MBUF_TYPE_CONTROL	= 14,	/* extra-data protocol message */
53	MBUF_TYPE_OOBDATA	= 15	/* expedited data  */
54};
55typedef uint32_t mbuf_type_t;
56
57/* Currently we only support MBUF_WAITOK */
58enum {
59	MBUF_WAITOK	= 0,	/* Ok to block to get memory */
60	MBUF_DONTWAIT	= 1	/* Don't block, fail if blocking would be required */
61};
62typedef uint32_t mbuf_how_t;
63
64struct smb_mbuf;
65typedef	struct smb_mbuf* mbuf_t;
66
67mbuf_t mbuf_free(mbuf_t mbuf);
68void mbuf_freem(mbuf_t mbuf);
69int mbuf_gethdr(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf);
70int mbuf_get(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf);
71int mbuf_getcluster(mbuf_how_t how, mbuf_type_t type, size_t size, mbuf_t *mbuf);
72int mbuf_attachcluster(mbuf_how_t how, mbuf_type_t type,
73					   mbuf_t *mbuf, void * extbuf, void (*extfree)(caddr_t , size_t, caddr_t),
74					   size_t extsize, caddr_t extarg);
75size_t mbuf_len(const mbuf_t mbuf);
76size_t mbuf_maxlen(const mbuf_t mbuf);
77void mbuf_setlen(mbuf_t mbuf, size_t len);
78size_t mbuf_pkthdr_len(const mbuf_t mbuf);
79void mbuf_pkthdr_setlen(mbuf_t mbuf, size_t len);
80void mbuf_pkthdr_adjustlen(mbuf_t mbuf, int amount);
81mbuf_t mbuf_next(const mbuf_t mbuf);
82int mbuf_setnext(mbuf_t mbuf, mbuf_t next);
83void * mbuf_data(const mbuf_t mbuf);
84size_t mbuf_trailingspace(const mbuf_t mbuf);
85int mbuf_copydata(const mbuf_t mbuf, size_t offset, size_t length, void *out_data);
86
87#endif // #ifndef KERNEL
88#endif // _UPI_MBUF_H_
89