Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ad986ab authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge "delete libnl_2"

parents 4db6ce8e 7097f052
Loading
Loading
Loading
Loading

libnl_2/.gitignore

deleted100644 → 0
+0 −2
Original line number Diff line number Diff line
include/netlink/version.h.in
cscope.*

libnl_2/Android.mk

deleted100644 → 0
+0 −39
Original line number Diff line number Diff line
#######################################
# * Netlink cache not implemented
# * Library is not thread safe
#######################################

LOCAL_PATH := $(call my-dir)


include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
        attr.c \
        cache.c \
        genl/genl.c \
        genl/family.c \
        handlers.c \
        msg.c \
        netlink.c \
        object.c \
        socket.c \
        dbg.c

LOCAL_C_INCLUDES += \
        external/libnl-headers

# Static Library
LOCAL_MODULE := libnl_2
LOCAL_MODULE_TAGS := optional
LOCAL_32_BIT_ONLY := true
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_SRC_FILES :=
LOCAL_WHOLE_STATIC_LIBRARIES:= libnl_2
LOCAL_SHARED_LIBRARIES:= liblog
LOCAL_MODULE := libnl_2
LOCAL_MODULE_TAGS := optional
LOCAL_32_BIT_ONLY := true
include $(BUILD_SHARED_LIBRARY)

libnl_2/README

deleted100644 → 0
+0 −88
Original line number Diff line number Diff line
Netlink Protocol Library

This library is a clean room re-implementation of libnl 2.0 and
re-licensed under Apache 2.0. It was developed primarily to support
wpa_supplicant. However, with additional development can be extended
to support other netlink applications.

Netlink Protocol Format (RFC3549)

+-----------------+-+-------------------+-+
|Netlink Message  |P| Generic Netlink   |P|
|    Header       |A|  Message Header   |A|
|(struct nlmsghdr)|D|(struct genlmsghdr)|D|
+-----------------+-+-------------------+-+-------------+
|len:4|type:2|flags:2|seq:4 pid:4|cmd:1|ver:1|reserved:2|
+--------------------------------+----------------------+
+-----------------+-+-----------------+-+-----------------+-+-----------------+-+---+
|Netlink Attribute|P|Netlink Attribute|P|Netlink Attribute|P|Netlink Attribute|P|...|
|    #0 Header    |A|   #0 Payload    |A|   #1 Header     |A|   #1 Payload    |A|   |
| (struct nlattr) |D|     (void)      |D| (struct nlattr) |D|     (void)      |D|   |
+-----------------+-+-----------------+-+-----------------+-+-----------------+-+---+
|len:2(==4+payload)|type:2|payload|pad|
+-------------------------+-------+---+

NETLINK OVERVIEW

* Each netlink message consists of a bitstream with a netlink header.
* After this header a second header *can* be used specific to the netlink
  family in use. This library was tested using the generic netlink
  protocol defined by struct genlmsghdr to support nl80211.
* After the header(s) netlink attributes can be appended to the message
  which hold can hold basic types such as unsigned integers and strings.
* Attributes can also be nested. This is accomplished by calling "nla_nest_start"
  which creates an empty attribute with nest attributes as its payload. Then to
  close the nest, "nla_nest_end" is called.
* All data structures in this implementation are byte-aligned (Currently 4 bytes).
* Acknowledgements (ACKs) are sent as NLMSG_ERROR netlink message types (0x2) and
  have an error value of 0.

KNOWN ISSUES

  GENERAL
  * Not tested for thread safety

  Android.mk
  * No dynamic library because of netlink cache not implemented and
    not tested for thread safety

  attr.c
  * nla_parse - does not use nla_policy argument

  cache.c
  * netlink cache not implemented and only supports one netlink family id
    which is stored in the nl_cache pointer instead of an actual cache

  netlink.c
  * nl_recvmsgs - does not support nl_cb_overwrite_recv()
  * nl_recv - sets/unsets asynchronous socket flag

SOURCE FILES

* Android.mk - Android makefile
* README - This file
* attr.c - Netlink attributes
* cache.c - Netlink cache
* genl/family.c - Generic netlink family id
* genl/genl.c - Generic netlink
* handlers.c - Netlink callbacks
* msg.c - Netlink messages construction
* netlink.c - Netlink socket communication
* object.c - libnl object wrapper
* socket.c - Netlink kernel socket utils

IMPORTANT HEADER FILES - NOTE: These are based on the the origin GPL libnl headers

* netlink-types.h - Contains many important structs for libnl
  to represent netlink objects
* netlink/netlink-kernel.h - Netlink kernel headers and field constants.
* netlink/msg.h - macros for iterating over netlink messages
* netlink/attr.h - netlink attribute constants, iteration macros and setters

REFERENCES

* nl80211.h
* netlink_types.h
* $LINUX_KERNEL/net/wireless/nl80211.c
* http://www.infradead.org/~tgr/libnl/doc-3.0/index.html
* http://www.netfilter.org/projects/libmnl/doxygen/index.html

libnl_2/attr.c

deleted100644 → 0
+0 −239
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* NOTICE: This is a clean room re-implementation of libnl */

#include <errno.h>
#include "netlink/netlink.h"
#include "netlink/msg.h"
#include "netlink/attr.h"
#include "netlink-types.h"

/* Return payload of string attribute. */
char *nla_get_string(struct nlattr *nla)
{
	return (char *) nla_data(nla);
}

/* Return payload of 16 bit integer attribute. */
uint16_t nla_get_u16(struct nlattr *nla)
{
	return *((uint16_t *) nla_data(nla));
}

/* Return payload of 32 bit integer attribute. */
uint32_t nla_get_u32(struct nlattr *nla)
{
	return *((uint32_t *) nla_data(nla));
}

/* Return value of 8 bit integer attribute. */
uint8_t nla_get_u8(struct nlattr *nla)
{
	return *((uint8_t *) nla_data(nla));
}

/* Return payload of uint64_t attribute. */
uint64_t nla_get_u64(struct nlattr *nla)
{
	uint64_t tmp;
	nla_memcpy(&tmp, nla, sizeof(tmp));
	return tmp;
}

/* Head of payload */
void *nla_data(const struct nlattr *nla)
{
	return (void *) ((char *) nla + NLA_HDRLEN);
}

/* Return length of the payload . */
int nla_len(const struct nlattr *nla)
{
	return nla->nla_len - NLA_HDRLEN;
}

int nla_padlen(int payload)
{
	return NLA_ALIGN(payload) - payload;
}

/* Start a new level of nested attributes. */
struct nlattr *nla_nest_start(struct nl_msg *msg, int attrtype)
{
	struct nlattr *start = (struct nlattr *)nlmsg_tail(msg->nm_nlh);
	int rc;

	rc = nla_put(msg, attrtype, 0, NULL);
	if (rc < 0)
		return NULL;

	return start;
}

/* Finalize nesting of attributes. */
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
{
	/* Set attribute size */
	start->nla_len = (unsigned char *)nlmsg_tail(nlmsg_hdr(msg)) -
				(unsigned char *)start;
	return 0;
}

/* Return next attribute in a stream of attributes. */
struct nlattr *nla_next(const struct nlattr *nla, int *remaining)
{
	struct nlattr *next_nla = NULL;
	if (nla->nla_len >= sizeof(struct nlattr) &&
	   nla->nla_len <= *remaining){
		next_nla = (struct nlattr *) \
			((char *) nla + NLA_ALIGN(nla->nla_len));
		*remaining = *remaining - NLA_ALIGN(nla->nla_len);
	}

	return next_nla;

}

/* Check if the attribute header and payload can be accessed safely. */
int nla_ok(const struct nlattr *nla, int remaining)
{
	return remaining > 0 &&
		nla->nla_len >= sizeof(struct nlattr) &&
		sizeof(struct nlattr) <= (unsigned int) remaining &&
		nla->nla_len <= remaining;
}

/* Create attribute index based on a stream of attributes. */
/* NOTE: Policy not used ! */
int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head,
	int len, struct nla_policy *policy)
{
	struct nlattr *pos;
	int rem;

	/* First clear table */
	memset(tb, 0, (maxtype + 1) * sizeof(struct nlattr *));

	nla_for_each_attr(pos, head, len, rem) {
		int type = nla_type(pos);

		if ((type <= maxtype) && (type != 0))
			tb[type] = pos;
	}

	return 0;
}


/* Create attribute index based on nested attribute. */
int nla_parse_nested(struct nlattr *tb[], int maxtype,
		struct nlattr *nla, struct nla_policy *policy)
{
	return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy);
}


/* Add a unspecific attribute to netlink message. */
int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
{
	struct nlattr *nla;

	/* Reserve space and init nla header */
	nla = nla_reserve(msg, attrtype, datalen);
	if (nla) {
		memcpy(nla_data(nla), data, datalen);
		return 0;
	}

	return -EINVAL;
}

/* Add 8 bit integer attribute to netlink message. */
int nla_put_u8(struct nl_msg *msg, int attrtype, uint8_t value)
{
	return nla_put(msg, attrtype, sizeof(uint8_t), &value);
}

/* Add 16 bit integer attribute to netlink message. */
int nla_put_u16(struct nl_msg *msg, int attrtype, uint16_t value)
{
	return nla_put(msg, attrtype, sizeof(uint16_t), &value);
}

/* Add 32 bit integer attribute to netlink message. */
int nla_put_u32(struct nl_msg *msg, int attrtype, uint32_t value)
{
	return nla_put(msg, attrtype, sizeof(uint32_t), &value);
}

/* Add 64 bit integer attribute to netlink message. */
int nla_put_u64(struct nl_msg *msg, int attrtype, uint64_t value)
{
	return nla_put(msg, attrtype, sizeof(uint64_t), &value);
}

/* Add nested attributes to netlink message. */
/* Takes the attributes found in the nested message and appends them
 * to the message msg nested in a container of the type attrtype. The
 * nested message may not have a family specific header */
int nla_put_nested(struct nl_msg *msg, int attrtype, struct nl_msg *nested)
{
	int rc;

	rc = nla_put(msg, attrtype, nlmsg_attrlen(nlmsg_hdr(nested), 0),
			nlmsg_attrdata(nlmsg_hdr(nested), 0));
	return rc;

}

/* Return type of the attribute. */
int nla_type(const struct nlattr *nla)
{
	return (int)nla->nla_type & NLA_TYPE_MASK;
}

/* Reserves room for an attribute in specified netlink message and fills
 * in the attribute header (type,length). Return NULL if insufficient space */
struct nlattr *nla_reserve(struct nl_msg *msg, int attrtype, int data_len)
{

	struct nlattr *nla;
	const unsigned int NEW_SIZE = NLMSG_ALIGN(msg->nm_nlh->nlmsg_len) +
					NLA_ALIGN(NLA_HDRLEN + data_len);

	/* Check enough space for attribute */
	if (NEW_SIZE > msg->nm_size)
		return NULL;

	nla = (struct nlattr *)nlmsg_tail(msg->nm_nlh);
	nla->nla_type = attrtype;
	nla->nla_len = NLA_HDRLEN + data_len;
	memset((unsigned char *)nla + nla->nla_len, 0, nla_padlen(data_len));
	msg->nm_nlh->nlmsg_len = NEW_SIZE;
	return nla;
}

/* Copy attribute payload to another memory area. */
int nla_memcpy(void *dest, struct nlattr *src, int count)
{
	if (!src || !dest)
		return 0;
	if (count > nla_len(src))
		count = nla_len(src);
	memcpy(dest, nla_data(src), count);
	return count;
}

libnl_2/cache.c

deleted100644 → 0
+0 −37
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* NOTICE: This is a clean room re-implementation of libnl */

#include "netlink/cache.h"
#include "netlink/object.h"

void nl_cache_free(struct nl_cache *cache)
{

}

void nl_cache_clear(struct nl_cache *cache)
{

}

void nl_cache_remove(struct nl_object *obj)
{

}

Loading