diff -u -r -N kame/freebsd5/include/Makefile kame-lies/freebsd5/include/Makefile
--- kame/freebsd5/include/Makefile	Fri May 13 03:37:18 2005
+++ kame-lies/freebsd5/include/Makefile	Thu Jul 28 23:22:10 2005
@@ -34,6 +34,7 @@
 	netipsec netipx netkey netnatm netncp netsmb nfs nfsclient nfsserver \
 	pccard posix4 sys vm
 #LDIRS+=	altq
+LDIRS+= lies
 
 LSUBDIRS=	cam/scsi \
 	dev/acpica dev/an dev/bktr dev/firewire \
diff -u -r -N kame/freebsd5/sys/conf/files kame-lies/freebsd5/sys/conf/files
--- kame/freebsd5/sys/conf/files	Fri May 13 03:37:03 2005
+++ kame-lies/freebsd5/sys/conf/files	Thu Jul 28 23:16:38 2005
@@ -363,6 +363,7 @@
 dev/ata/atapi-tape.c	optional atapist
 dev/ata/atapi-cam.c	optional atapicam
 dev/ath/if_ath.c	optional ath
+dev/ath/if_athlies.c	optional ath
 dev/ath/if_ath_pci.c	optional ath pci
 dev/ath/if_ath_pci.c	optional ath card
 dev/awi/am79c930.c	optional awi
@@ -1249,6 +1250,13 @@
 libkern/strtoul.c	standard
 libkern/strtouq.c	standard
 libkern/strvalid.c	standard
+lies/lies.c             optional lies
+lies/lies_80211.c       optional lies
+lies/lies_aepp.c        optional lies
+lies/lies_emu.c         optional lies
+lies/lies_l2.c          optional lies
+lies/lies_pipem.c       optional lies
+lies/lies_osdep.c       optional lies
 net/bpf.c		standard
 net/bpf_filter.c	count bpf
 net/bridge.c		optional bridge
diff -u -r -N kame/freebsd5/sys/conf/options kame-lies/freebsd5/sys/conf/options
--- kame/freebsd5/sys/conf/options	Fri May 13 03:37:03 2005
+++ kame-lies/freebsd5/sys/conf/options	Thu Jul 28 23:16:39 2005
@@ -729,3 +729,7 @@
 DCONS_POLL_HZ		opt_dcons.h
 DCONS_FORCE_CONSOLE	opt_dcons.h
 DCONS_FORCE_GDB		opt_dcons.h
+
+# LIES
+LIES			opt_lies.h
+LIES_80211		opt_lies.h
diff -u -r -N kame/freebsd5/sys/dev/ath/if_ath.c kame-lies/freebsd5/sys/dev/ath/if_ath.c
--- kame/freebsd5/sys/dev/ath/if_ath.c	Fri May 13 03:37:04 2005
+++ kame-lies/freebsd5/sys/dev/ath/if_ath.c	Thu Jul 28 23:35:47 2005
@@ -45,6 +45,7 @@
  */
 
 #include "opt_inet.h"
+#include "opt_lies.h"
 
 #include <sys/param.h>
 #include <sys/systm.h> 
@@ -83,6 +84,14 @@
 #include <dev/ath/if_athvar.h>
 #include <contrib/dev/ath/ah_desc.h>
 
+#ifdef LIES_80211
+#include <lies/lies_aepp.h>
+#include <lies/lies.h>
+#include <lies/lies_osdep.h>
+#include <lies/lies_80211.h>
+#include <dev/ath/if_athlies.h>
+#endif
+
 /* unalligned little endian access */     
 #define LE_READ_2(p)							\
 	((u_int16_t)							\
@@ -357,6 +366,16 @@
 	sc->sc_rx_th.wr_ihdr.it_len = htole16(sc->sc_rx_th_len);
 	sc->sc_rx_th.wr_ihdr.it_present = htole32(ATH_RX_RADIOTAP_PRESENT);
 
+#ifdef LIES_80211
+        bzero(&sc->sc_lnode, sizeof(sc->sc_lnode));
+	if ((sc->sc_lif = lies_80211_ifattach(ifp->if_xname,ic->ic_myaddr))
+	    == NULL)
+		goto bad2;
+	sc->sc_lif->lif_osif = sc; /* XXX */
+	sc->sc_lif->lif_connect = ath_lies_connect; 
+	timeout(ath_lies_timer, sc, hz);
+#endif
+
 	return 0;
 bad2:
 	ath_desc_free(sc);
@@ -1798,6 +1817,10 @@
 		rh->arh_rssi = ds->ds_rxstat.rs_rssi;
 		rh->arh_antenna = ds->ds_rxstat.rs_antenna;
 
+#ifdef LIES_80211
+		ath_lies_updateframe(sc, m, ds);
+#endif
+
 		/*
 		 * Send frame up for processing.
 		 */
@@ -2532,6 +2555,12 @@
 
 	ath_hal_setledstate(ah, leds[nstate]);	/* set LED */
 
+#ifdef LIES_80211
+	if ((ic->ic_state == IEEE80211_S_RUN) &&
+	    (nstate != IEEE80211_S_RUN))
+		ath_lies_disassoc(sc, ic->ic_bss->ni_bssid);
+#endif
+
 	if (nstate == IEEE80211_S_INIT) {
 		sc->sc_imask &= ~(HAL_INT_SWBA | HAL_INT_BMISS);
 		ath_hal_intrset(ah, sc->sc_imask);
@@ -2556,8 +2585,12 @@
 	DPRINTF(ATH_DEBUG_ANY, ("%s: RX filter 0x%x bssid %s\n",
 		 __func__, rfilt, ether_sprintf(bssid)));
 
-	if (nstate == IEEE80211_S_RUN && ic->ic_opmode == IEEE80211_M_STA)
+	if (nstate == IEEE80211_S_RUN && ic->ic_opmode == IEEE80211_M_STA) {
 		ath_hal_setassocid(ah, bssid, ni->ni_associd);
+#ifdef LIES_80211
+		ath_lies_assoc(sc, ni->ni_bssid);
+#endif		
+	}
 	else
 		ath_hal_setassocid(ah, bssid, 0);
 	if (ic->ic_flags & IEEE80211_F_WEPON) {
diff -u -r -N kame/freebsd5/sys/dev/ath/if_athlies.c kame-lies/freebsd5/sys/dev/ath/if_athlies.c
--- kame/freebsd5/sys/dev/ath/if_athlies.c	Thu Jan  1 09:00:00 1970
+++ kame-lies/freebsd5/sys/dev/ath/if_athlies.c	Thu Jul 28 23:46:22 2005
@@ -0,0 +1,316 @@
+#include "opt_inet.h"
+#include "opt_lies.h"
+
+#include <sys/param.h>
+#include <sys/systm.h> 
+#include <sys/sysctl.h>
+#include <sys/mbuf.h>   
+#include <sys/malloc.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/errno.h>
+#include <sys/callout.h>
+#include <sys/bus.h>
+#include <sys/endian.h>
+
+#include <machine/bus.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_arp.h>
+#include <net/ethernet.h>
+#include <net/if_llc.h>
+
+#include <net80211/ieee80211_var.h>
+
+#include <net/bpf.h>
+
+#ifdef INET
+#include <netinet/in.h> 
+#include <netinet/if_ether.h>
+#endif
+
+#include <dev/ath/if_athvar.h>
+#include <contrib/dev/ath/ah_desc.h>
+
+#ifdef LIES_80211
+
+#include <lies/lies_aepp.h>
+#include <lies/lies.h>
+#include <lies/lies_osdep.h>
+#include <lies/lies_80211.h>
+
+#include <dev/ath/if_athlies.h>
+
+
+u_int32_t       ath_lies_qual_vg = 34;
+SYSCTL_INT(_debug, OID_AUTO, ath_vg, CTLFLAG_RW, &ath_lies_qual_vg,
+           0, "atheros quality abstraction threshold");
+u_int32_t       ath_lies_qual_g = 27;
+SYSCTL_INT(_debug, OID_AUTO, ath_g, CTLFLAG_RW, &ath_lies_qual_g,
+           0, "atheros quality abstraction threshold" );
+u_int32_t       ath_lies_qual_f = 22;
+SYSCTL_INT(_debug, OID_AUTO, ath_f, CTLFLAG_RW, &ath_lies_qual_f,
+           0,  "atheros quality abstraction threshold");
+u_int32_t       ath_lies_qual_b = 15;
+SYSCTL_INT(_debug, OID_AUTO, ath_b, CTLFLAG_RW, &ath_lies_qual_b,
+           0,  "atheros quality abstraction threshold");
+
+static u_int8_t ath_lies_rssi2qual(u_int32_t);
+
+void
+ath_lies_timer(arg)
+	void *arg;
+{
+	struct ath_softc *sc = (struct ath_softc *)arg;
+	struct ath_lies_node *node;
+	struct ath_lies_node *tnode;
+
+	LIST_FOREACH_SAFE(node, &sc->sc_lnode, aln_list, tnode) {
+		node->aln_life++;
+
+		if (node->aln_life > ALN_LIFELIMIT) {
+			ath_lies_node_remove(node);
+			continue ;
+		}
+
+		if (node->aln_count == 0) {
+			node->aln_currssi = 0;
+			continue ;
+		}
+		
+		node->aln_currssi = node->aln_sumrssi / node->aln_count;
+		node->aln_sumrssi = 0;
+		node->aln_count = 0;
+	}
+
+	ath_lies_abstract(sc);
+
+	timeout(ath_lies_timer, sc, hz);
+}
+
+struct ath_lies_node *
+ath_lies_node_find(sc, addr)
+	struct ath_softc *sc;
+	u_int8_t *addr;
+{
+	struct ath_lies_node *node;
+
+	LIST_FOREACH(node, &sc->sc_lnode, aln_list) {
+		if (IEEE80211_ADDR_EQ(addr, node->aln_bssid))
+			return node;
+	}
+	
+	return NULL;
+}
+
+struct ath_lies_node *
+ath_lies_node_add(sc, addr)
+	struct ath_softc *sc;
+	u_int8_t *addr;
+{
+	struct ath_lies_node *aln = NULL;
+
+	aln = (struct ath_lies_node *)malloc(
+		sizeof(struct ath_lies_node), M_TEMP, M_NOWAIT);
+
+	if (aln == NULL)
+		return NULL;
+
+	memset(aln, 0, sizeof(struct ath_lies_node));
+	memcpy(aln->aln_bssid, addr, IEEE80211_ADDR_LEN);
+
+	LIST_INSERT_HEAD(&sc->sc_lnode, aln, aln_list);
+
+	return aln;
+}
+
+void
+ath_lies_node_remove(node)
+	struct ath_lies_node *node;
+{
+	LIST_REMOVE(node, aln_list);
+	free(node, M_TEMP);
+}
+
+void
+ath_lies_updateframe(sc, m, ds)
+	struct ath_softc *sc;
+	struct mbuf *m;
+	struct ath_desc *ds;
+{
+	struct ath_lies_node *node;
+	struct ieee80211_frame_min *wh =
+		mtod(m, struct ieee80211_frame_min *);
+
+	node = ath_lies_node_find(sc, wh->i_addr2);
+	if (node == NULL)
+		node = ath_lies_node_add(sc, wh->i_addr2);
+
+	node->aln_sumrssi += ds->ds_rxstat.rs_rssi;
+	node->aln_count ++;
+	node->aln_life = 0;
+
+	return;
+}
+
+void
+ath_lies_updateparam()
+{
+	return ;
+}
+
+void
+ath_lies_abstract(sc)
+	struct ath_softc *sc;
+{
+	struct ath_lies_node *node;
+	struct lies_80211_peer *peer;
+	u_int8_t oqual, qual;
+
+	LIST_FOREACH(node, &sc->sc_lnode, aln_list) {
+		peer = lies_80211_peer_find(sc->sc_lif, node->aln_bssid, 
+					    AEPP_PARAM_ARCH_MAC);
+		if (peer == NULL) {
+			peer = lies_80211_peer_add(sc->sc_lif,
+						    node->aln_bssid,
+						    AEPP_PARAM_ARCH_MAC);
+			if (peer == NULL)
+				continue;
+		}
+
+		/* quality update */
+		oqual = peer->peer_qual;
+		qual = ath_lies_rssi2qual(node->aln_currssi);
+		peer->peer_qual = qual;
+		
+		/* make indications according quality change */
+		if((qual >= 4 ) && (4 > oqual)) {
+			if(!(peer->peer_state & LIES_80211_PEER_ENABLE)) {
+				peer->peer_state |= LIES_80211_PEER_ENABLE;
+                                lies_80211_peerfound_indication(sc->sc_lif);
+                        }
+                }
+		if((oqual > 2) && (2 >= qual)) {
+			if(peer->peer_state & LIES_80211_PEER_ACTIVE) {
+                                lies_80211_linktobedown_indication(
+					sc->sc_lif, peer);
+                        }
+			if(peer->peer_state & LIES_80211_PEER_ENABLE) {
+				peer->peer_state &= ~LIES_80211_PEER_ENABLE;
+                                lies_80211_peerlost_indication(sc->sc_lif);
+                        }
+                }
+	}
+
+	/* delete no need peer */
+	
+	return ;
+}
+
+void
+ath_lies_assoc(sc, bssid)
+	struct ath_softc *sc;
+	u_int8_t *bssid;
+{
+	struct lies_80211_peer *peer;
+	peer = lies_80211_peer_find(sc->sc_lif, bssid, AEPP_PARAM_ARCH_MAC);
+	if (peer == NULL) {
+		peer = lies_80211_peer_add(sc->sc_lif, bssid,
+					   AEPP_PARAM_ARCH_MAC);
+		if (peer == NULL)
+			return ;
+	}
+	peer->peer_state |= LIES_80211_PEER_ACTIVE;
+
+	lies_80211_linkup_indication(sc->sc_lif, peer);
+}
+
+void
+ath_lies_disassoc(sc, bssid)
+	struct ath_softc *sc;
+	u_int8_t *bssid;
+{
+	struct lies_80211_peer *peer;
+	peer = lies_80211_peer_find(sc->sc_lif, bssid, AEPP_PARAM_ARCH_MAC);
+	if (peer == NULL) {
+		peer = lies_80211_peer_add(sc->sc_lif, bssid,
+					   AEPP_PARAM_ARCH_MAC);
+		if (peer == NULL)
+			return ;
+	}
+	peer->peer_state &= ~LIES_80211_PEER_ACTIVE;
+
+	lies_80211_linkdown_indication(sc->sc_lif, peer);
+}
+
+int
+ath_lies_connect(osif, bssid)
+	void *osif;
+	u_int8_t *bssid;
+{
+	struct ath_softc *sc = (struct ath_softc *)osif;
+	struct ieee80211com *ic = &sc->sc_ic;
+	struct ieee80211_node *ni = NULL, *oni = NULL;
+
+	printf("<%s:%d>\n",__FUNCTION__, __LINE__);
+
+	IEEE80211_NODE_LOCK(ic);
+	TAILQ_FOREACH(ni, &ic->ic_node, ni_list) {
+                if (IEEE80211_ADDR_EQ(ni->ni_macaddr, bssid)) {
+                        oni = ic->ic_bss;
+
+                        ic->ic_bss = ni;
+			if (ic->ic_state == IEEE80211_S_RUN) {
+				ic->ic_state = IEEE80211_S_AUTH;
+				ath_lies_disassoc(sc, bssid);
+			}
+			else {
+				ic->ic_state = IEEE80211_S_AUTH;
+			}	
+			printf("<%s:%d>Send authentication frame.\n"
+				,__FUNCTION__, __LINE__);
+                        IEEE80211_SEND_MGMT(ic, ni
+                                            , IEEE80211_FC0_SUBTYPE_AUTH, 1);
+
+                        IEEE80211_NODE_UNLOCK(ic);
+                        return 0;
+                }
+        }
+	printf("<%s:%d>Peer not found.\n",__FUNCTION__, __LINE__);
+        IEEE80211_NODE_UNLOCK(ic);
+	return 0;
+}
+
+static u_int8_t
+ath_lies_rssi2qual(rssi)
+	u_int32_t rssi;
+{
+	u_int8_t qual = 0;
+
+        if(rssi > ath_lies_qual_vg) {
+                qual = 5;
+        }
+        else if(rssi > ath_lies_qual_g) {
+                qual = 4;
+        }
+        else if(rssi > ath_lies_qual_f) {
+                qual = 3;
+        }
+        else if(rssi > ath_lies_qual_b) {
+                qual = 2;
+        }
+        else if(rssi > 0) {
+                qual = 1;
+        }
+        else {
+                qual = 0;
+        }
+        return qual;	
+
+}
+#endif
diff -u -r -N kame/freebsd5/sys/dev/ath/if_athlies.h kame-lies/freebsd5/sys/dev/ath/if_athlies.h
--- kame/freebsd5/sys/dev/ath/if_athlies.h	Thu Jan  1 09:00:00 1970
+++ kame-lies/freebsd5/sys/dev/ath/if_athlies.h	Thu Jul 28 23:47:14 2005
@@ -0,0 +1,36 @@
+#ifndef _ATH_IF_ATHLIES_H_
+#define _ATH_IF_ATHLIES_H_
+
+struct ath_lies_node {
+	LIST_ENTRY(ath_lies_node) aln_list;
+
+	u_int8_t aln_bssid[IEEE80211_ADDR_LEN];
+	u_int8_t aln_essid[IEEE80211_NWID_LEN];
+
+	u_int32_t aln_currssi;
+
+	u_int32_t aln_sumrssi;
+	u_int32_t aln_count;
+	
+	u_int32_t aln_life;
+};
+
+#define ALN_LIFELIMIT 60
+
+void ath_lies_timer(void *);
+struct ath_lies_node *ath_lies_node_find(struct ath_softc *, u_int8_t *);
+struct ath_lies_node *ath_lies_node_add(struct ath_softc *, u_int8_t *);
+void ath_lies_node_remove(struct ath_lies_node *);
+void ath_lies_updateframe(struct ath_softc *,
+			  struct mbuf *, struct ath_desc *);
+void ath_lies_updateparam(void);
+
+void ath_lies_abstract(struct ath_softc *);
+
+void ath_lies_assoc(struct ath_softc *, u_int8_t *);
+void ath_lies_disassoc(struct ath_softc *, u_int8_t *);
+
+int ath_lies_connect(void *, u_int8_t *);
+int ath_lies_disconnect(void);
+
+#endif
diff -u -r -N kame/freebsd5/sys/dev/ath/if_athvar.h kame-lies/freebsd5/sys/dev/ath/if_athvar.h
--- kame/freebsd5/sys/dev/ath/if_athvar.h	Fri May 13 00:09:51 2005
+++ kame-lies/freebsd5/sys/dev/ath/if_athvar.h	Thu Jul 28 23:16:39 2005
@@ -157,6 +157,11 @@
 	struct callout		sc_cal_ch;	/* callout handle for cals */
 	struct callout		sc_scan_ch;	/* callout handle for scan */
 	struct ath_stats	sc_stats;	/* interface statistics */
+
+#ifdef LIES_80211
+	struct lies_80211_if	*sc_lif;	/* iface structure for LIES*/
+	LIST_HEAD(, ath_lies_node) sc_lnode;	/* node info for LIES */
+#endif
 };
 #define	sc_tx_th		u_tx_rt.th
 #define	sc_rx_th		u_rx_rt.th
diff -u -r -N kame/freebsd5/sys/dev/em/if_em.c kame-lies/freebsd5/sys/dev/em/if_em.c
--- kame/freebsd5/sys/dev/em/if_em.c	Fri May 13 03:37:05 2005
+++ kame-lies/freebsd5/sys/dev/em/if_em.c	Thu Jul 28 23:16:39 2005
@@ -33,7 +33,11 @@
 
 /*$FreeBSD: src/sys/dev/em/if_em.c,v 1.44.2.8 2005/03/23 13:30:21 glebius Exp $*/
 
+#include "opt_lies.h"		/* LIES */
+
 #include <dev/em/if_em.h>
+#include <net/netisr.h>		/* LIES */
+#include <lies/lies_pipem.h>	/* LIES */
 
 /*********************************************************************
  *  Set this to one to display debug statistics                                                   
@@ -1065,6 +1069,9 @@
 			adapter->link_speed = 0;
 			adapter->link_duplex = 0;
 			adapter->link_active = 0;
+#ifdef LIES
+			/* XXX LIES LinkDown.indication code is to be written. XXX */
+#endif /* LIES */
 		}
 	}
 
@@ -1670,6 +1677,9 @@
 em_print_link_status(struct adapter * adapter)
 {
 	struct ifnet *ifp = &adapter->interface_data.ac_if;
+#ifdef LIES
+	struct mbuf *m = NULL;
+#endif
 
 	if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
 		if (adapter->link_active == 0) {
@@ -1688,6 +1698,40 @@
 			if (ifp->if_carp)
 				carp_carpdev_state(ifp->if_carp);
 #endif
+#ifdef LIES
+                        /* Get Mbuf for soft-intr to LIES */
+                        m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
+                        if (m == NULL) {
+                                printf("em%d: <%s:%d> Can't allocate mbuf.\n", adapter->unit, __FUNCTION__, __LINE__);
+                        } else {
+                                struct pipem_hdr *pehdr;
+                                struct pipem_connectinfo *cinfo;
+
+                                /*
+                                 * Create Physical Informagtion Packet for
+                                 * Wireless Environment Emulator on Mbuf
+                                 *
+                                 * 1. Pseudo etherhet header
+                                 * 2. Pipem header
+                                 * 3. Connect information
+                                 */
+                                m->m_len = m->m_pkthdr.len = sizeof(struct pipem_hdr) + sizeof(struct pipem_connectinfo);
+                                pehdr = mtod(m, struct pipem_hdr *);
+                                memset(pehdr, 0, sizeof(struct pipem_hdr));
+                                pehdr->pipem_ver = htons(PIPEM_VERSION);
+                                pehdr->pipem_len = htons(0x0006);
+                                cinfo = (struct pipem_connectinfo *)(pehdr + 1);
+                                memset(cinfo, 0, sizeof(struct pipem_connectinfo));
+                                cinfo->pipemle_type = htons(PIPEM_CONNECTINFO);
+                                cinfo->pipemle_len = htons(0x0006);
+                                cinfo->pipemle_addr = htons(0x0000);    /* XXX Be a MAC addr */
+
+                                /* Kick soft-intr to lies_input() */
+                                EM_UNLOCK(adapter);
+                                netisr_dispatch(NETISR_LIES, m);
+                                EM_LOCK(adapter);
+                        }
+#endif /* LIES */
 		}
 	} else {
 		if (adapter->link_active == 1) {
diff -u -r -N kame/freebsd5/sys/kern/kern_event.c kame-lies/freebsd5/sys/kern/kern_event.c
--- kame/freebsd5/sys/kern/kern_event.c	Fri May 13 00:13:51 2005
+++ kame-lies/freebsd5/sys/kern/kern_event.c	Thu Jul 28 23:16:39 2005
@@ -25,6 +25,8 @@
  * SUCH DAMAGE.
  */
 
+#include "opt_lies.h"		/* LIES */
+
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/sys/kern/kern_event.c,v 1.79.2.6 2005/03/25 16:28:04 jmg Exp $");
 
@@ -57,6 +59,10 @@
 #include <sys/taskqueue.h>
 #include <sys/uio.h>
 
+#include <lies/lies.h>		/* LIES */
+#include <lies/lies_aepp.h>	/* LIES */
+#include <lies/lies_osdep.h>	/* LIES */
+
 #include <vm/uma.h>
 
 MALLOC_DEFINE(M_KQUEUE, "kqueue", "memory for kqueue system");
@@ -127,6 +133,11 @@
 static int	filt_timerattach(struct knote *kn);
 static void	filt_timerdetach(struct knote *kn);
 static int	filt_timer(struct knote *kn, long hint);
+#ifdef LIES
+static int	filt_liesattach(struct knote *kn);
+static void	filt_liesdetach(struct knote *kn);
+static int	filt_lies(struct knote *kn, long hint);
+#endif /* LIES */
 
 static struct filterops file_filtops =
 	{ 1, filt_fileattach, NULL, NULL };
@@ -137,6 +148,10 @@
 	{ 0, filt_procattach, filt_procdetach, filt_proc };
 static struct filterops timer_filtops =
 	{ 0, filt_timerattach, filt_timerdetach, filt_timer };
+#ifdef LIES
+static struct filterops lies_filtops =
+	{ 0, filt_liesattach, filt_liesdetach, filt_lies };
+#endif /* LIES */
 
 static uma_zone_t	knote_zone;
 static int 		kq_ncallouts = 0;
@@ -223,6 +238,9 @@
 	{ &timer_filtops },			/* EVFILT_TIMER */
 	{ &file_filtops },			/* EVFILT_NETDEV */
 	{ &fs_filtops },			/* EVFILT_FS */
+#ifdef LIES
+	{ &lies_filtops },			/* EVFILT_LIES */
+#endif /* LIES */
 };
 
 /*
@@ -473,6 +491,133 @@
 	return (kn->kn_data != 0);
 }
 
+#ifdef LIES
+static int
+filt_liesattach(struct knote *kn)
+{
+	int error;			/* for error handling */
+	char *req, *cnf;		/* confirm temp buffer */
+
+	/* initialize buffer for making confirm */
+	req = malloc(AEPP_MAXSIZE, M_KQUEUE, M_WAITOK);
+	cnf = malloc(AEPP_MAXSIZE, M_KQUEUE, M_WAITOK);
+	memset(req, 0, AEPP_MAXSIZE);
+	memset(cnf, 0, AEPP_MAXSIZE);
+
+	printf("<%s:%d> LIES is attached to kqueue.\n", __FUNCTION__, __LINE__);
+
+	/* AEPP request registration just after attached */
+	if (kn->kn_kevent.udata != NULL && req != NULL) {
+
+		/* read AEPP request */
+		error = copyin(kn->kn_kevent.udata, req, AEPP_MAXSIZE);
+		if (error) {
+			printf("<%s:%d> Copyin error.\n", __FUNCTION__, __LINE__);
+			free(req, M_KQUEUE);
+			free(cnf, M_KQUEUE);
+			return (1);
+		}
+		printf("<%s:%d> Copyin AEPP request : Address:0x%x Class:%d.\n", __FUNCTION__, __LINE__, (u_int)kn->kn_kevent.udata, ((struct aepp_hdr *)req)->aepp_class);
+
+		/*
+		 * Call LIES - OS independent Function
+		 */
+		lies_dispatcher(req, cnf);
+
+		/* return AEPP confirm */
+		error = copyout(cnf, kn->kn_kevent.udata, AEPP_MAXSIZE);
+		if (error) {
+			printf("<%s:%d> Copyout error.\n", __FUNCTION__, __LINE__);
+			free(req, M_KQUEUE);
+			free(cnf, M_KQUEUE);
+			return (1);
+		}
+		printf("<%s:%d> Copyout AEPP confirm : Address:0x%x Class:%d.\n", __FUNCTION__, __LINE__, (u_int)kn->kn_kevent.udata, ((struct aepp_hdr *)cnf)->aepp_class);
+	}
+	free(req, M_KQUEUE);
+	free(cnf, M_KQUEUE);
+
+	kn->kn_flags |= EV_CLEAR;		/* automatically set */
+
+	switch (kn->kn_filter) {
+	case EVFILT_LIES:
+		kn->kn_fop = &lies_filtops;
+		break;
+	default:
+		return (1);
+	}
+
+	knlist_add(&(lies_sel.si_note), kn, 0);
+
+	return (0);
+}
+
+static void
+filt_liesdetach(struct knote *kn)
+{
+	printf("<%s:%d> LIES is detached from kqueue.\n", __FUNCTION__, __LINE__);
+
+	/*
+	 * Call LIES - OS independent Function
+	 * XXX Init all of LIES, so now we assume only one apllication uses LIES.
+	 */
+	lies_initialize_all();
+
+	knlist_remove(&(lies_sel.si_note), kn, 0);
+}
+
+static int
+filt_lies(struct knote *kn, long hint)
+{
+	struct liesbuf *buf;
+	struct aepp_hdr *hdr;
+
+	/*
+	 * this function called by following three cases
+	 *
+	 * 1. some event occurs(KNOTE), hint is not 0, 
+	 *    and hint is set to kn_fflags.
+	 *
+	 * 2. called by kqueue_scan(f_event), hint is 0, 
+	 *    but kn_fflags is not 0.
+	 *    (when scanning ends, kn_fflags is cleared by EV_CLEAR)
+	 *
+	 * 3. called by kqueue_register, hint is 0, 
+	 *    kn_fflags is 0.
+	 * 
+	 *  if two event occurs at the sametime, 
+	 *  knote is enqueued and is set fflags at first event, 
+	 *  knote is only set fflags at second event.
+	 */
+
+	printf("<%s:%d> LIES filter works for kqueue.\n", __FUNCTION__, __LINE__);
+
+	if (kn == NULL)
+		return 0;
+
+	if (kn->kn_sfflags & hint)
+		kn->kn_fflags |= hint;
+
+	/* called by device interrupt when an event ocuurs (because hint != 0) */
+	if (hint & NOTE_LIES) {
+		/* check all the remaining INDICATIONs */
+		LIST_FOREACH(buf, &indlist, lb_list) {
+			hdr = (struct aepp_hdr *)(buf->lb_buf);
+			if (kn->kn_kevent.ident == (hdr->aepp_type | (hdr->aepp_tgid << 16))) {
+				if (buf->lb_check != LIES_BUF_CHECKED) {
+					buf->lb_check = LIES_BUF_CHECKED;
+					return (kn->kn_fflags != 0);	/* notify */
+				}
+			}
+		}
+		/* if there is no INDICATION, don't notify */
+		return 0;
+	}
+
+	return (kn->kn_fflags != 0);	/* notify */
+}
+#endif /* LIES */
+
 /*
  * MPSAFE
  */
@@ -1053,6 +1198,11 @@
 	struct knote *kn, *marker;
 	int count, timeout, nkev, error;
 	int haskqglobal;
+#ifdef LIES
+	int lieserror;
+	struct aepp_hdr *hdr;
+	struct liesbuf* buf;
+#endif /* LIES*/
 
 	count = maxevents;
 	nkev = 0;
@@ -1179,6 +1329,37 @@
 				kq->kq_count--;
 				continue;
 			}
+#ifdef LIES
+			/* copyout AEPP indication from buffer inside kernel */
+			if(kn->kn_kevent.filter == EVFILT_LIES && kn->kn_kevent.udata != 0) {
+				/* check all the remaining INDICATION */
+				LIST_FOREACH(buf, &indlist, lb_list) {
+					/* if checked by filt_lies(), it is waiting copuout */
+					if(buf->lb_check != LIES_BUF_CHECKED) {
+						continue;
+					}
+
+					/* get pointer to INDICATION */
+					hdr = (struct aepp_hdr *)(buf->lb_buf);
+
+					/* compare tgtype and tgid, if matched, then copyout */
+					if (kn->kn_kevent.ident != (hdr->aepp_type | (hdr->aepp_tgid << 16)))
+						continue;
+
+					/* copyout the INDICATION to userland */
+					lieserror = copyout(buf->lb_buf, kn->kn_kevent.udata, AEPP_MAXSIZE);
+					if (lieserror) {
+						printf("<%s:%d> Copyout error.\n", __FUNCTION__, __LINE__);
+						return(lieserror);
+					}
+
+					printf("<%s:%d> Copyout AEPP indication : Address:0x%x Class:%d.\n", __FUNCTION__, __LINE__, (u_int)kn->kn_kevent.udata, hdr->aepp_class);
+
+					/* free the INDICATION from the table */
+					lies_remove_liesbuf(buf);
+				}
+			}
+#endif /* LIES */
 			*kevp = kn->kn_kevent;
 			KQ_LOCK(kq);
 			if (kn->kn_flags & EV_CLEAR) {
diff -u -r -N kame/freebsd5/sys/lies/lies_osdep.c kame-lies/freebsd5/sys/lies/lies_osdep.c
--- kame/freebsd5/sys/lies/lies_osdep.c	Thu Jan  1 09:00:00 1970
+++ kame-lies/freebsd5/sys/lies/lies_osdep.c	Thu Jul 28 23:16:39 2005
@@ -0,0 +1,148 @@
+#include "opt_lies.h"
+
+#include <sys/param.h>		/* for __P of net/netisr.h */
+#include <sys/kernel.h>		/* for SYSINIT */
+#include <sys/socket.h>		/* for AF_LIES, net/if_var.h */
+#include <sys/event.h>		/* for KNOTE */
+#include <sys/selinfo.h>	/* for struct selinfo */
+#include <sys/systm.h>		/* for printf */
+
+#include <net/netisr.h>		/* for NETISR_LIES */
+#include <net/if.h>		/* for if_var */
+#include <net/if_var.h>		/* for ifqueue */
+#include <net/ethernet.h>	/* for ether_header */
+
+#include <sys/sysctl.h>		/* for SYSCTL_INT */
+
+#include <lies/lies_aepp.h>	/* original */
+#include <lies/lies_l2.h>	/* original */
+#include <lies/lies_osdep.h>	/* original */
+
+static void lies_input(struct mbuf*);
+static void lies_init(void);
+
+#ifdef LIES
+
+const int liesintrq_present = 1;
+struct ifqueue liesintrq;
+//char liesbuf[AEPP_MAXSIZE];	/* temp buf for LIES kqueue only project */
+struct selinfo lies_sel;	/* knote list for LIES */
+struct liesbuf_head indlist;
+
+u_int32_t lies_debug = 0;
+SYSCTL_INT(_debug, OID_AUTO, lies, CTLFLAG_RW, &lies_debug, 0
+           , "LIES debugging printfs");
+
+void
+lies_input(struct mbuf *m)
+{
+	struct aepp_hdr *hdr;
+
+	if (m == NULL) {
+		printf("<%s:%d> LIES with NULL buffer.\n", __FUNCTION__, __LINE__);
+		return;
+	}
+
+	printf("<%s:%d> LIES starts processing.\n", __FUNCTION__, __LINE__);
+
+	/*
+	 * 1. If information is from wireless device driver
+	 *    call lies_l2_aepp_input()
+	 * 2. If information is from emulator (pipem: Physical Information Packet)
+	 *    call lies_emu_pipem_input()
+	 * 3. If information is from wired device driver
+	 *    3-1: if It's AEPP, call lies_l2_aepp_input()
+	 *    3-2: if it's PIPEM, call lies_emu_pipem_input()
+	 *
+	 * Now, we choose 2 and 3-2.
+	 * Remove ethernet header
+	 * Call LIES OS-independent code for emulator
+	 */
+	/* XXX */
+	hdr = mtod(m, struct aepp_hdr *);
+	if (hdr->aepp_ver == AEPP_VERSION1) {
+		lies_l2_aepp_input(mtod(m, void *));
+	}
+	else {
+		lies_emu_pipem_input(mtod(m, void *));
+	}
+
+	/* Free Memory for PIPEM */
+	m_freem(m);
+}
+
+int
+lies_send_indication(hdr)
+	struct aepp_hdr *hdr;
+{
+	struct mbuf *m;
+	struct aepp_hdr *d;
+	
+	/* Allocate mbuf */
+        m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
+	if (m == NULL) {
+                return -1;
+        }
+
+	d = mtod(m, struct aepp_hdr *);
+	memcpy(d, hdr, hdr->aepp_len + AEPP_HDRSIZE);
+
+	/* Set mbuf parameter */
+        m->m_len = hdr->aepp_len + AEPP_HDRSIZE;
+        m->m_pkthdr.len = m->m_len;
+        m->m_flags |= M_PKTHDR;
+	/* XXX  m->m_pkthdr.rcvif = ifp;*/
+
+        /* to netisr  */
+        netisr_dispatch(NETISR_LIES, m);
+
+	return 0;
+}
+
+static void
+lies_init(void)
+{
+	printf("<%s:%d> Initializing LIES.\n", __FUNCTION__, __LINE__);
+
+#define LIESQUEUE_MAXLEN 50
+	liesintrq.ifq_maxlen = LIESQUEUE_MAXLEN;
+	mtx_init(&liesintrq.ifq_mtx, "lies_inq", NULL, MTX_DEF);
+	netisr_register(NETISR_LIES, lies_input, &liesintrq, NETISR_MPSAFE);
+
+	knlist_init(&(lies_sel.si_note), NULL);	/* for MTX in FreeBSD5.3 */
+}
+
+int
+lies_add_liesbuf(void *aepp)
+{
+	struct liesbuf *buf;
+
+	buf = malloc(sizeof(struct liesbuf), M_TEMP, M_NOWAIT);
+
+	if(buf == NULL) {
+		return -1;
+	}
+
+	memset(buf, 0, sizeof(struct liesbuf));
+
+	buf->lb_check = LIES_BUF_DEFAULT;
+	buf->lb_buf = (char *)aepp;
+
+	LIST_INSERT_HEAD(&indlist, buf, lb_list);
+
+	return 0;
+}
+
+int
+lies_remove_liesbuf(struct liesbuf *buf)
+{
+	LIST_REMOVE(buf, lb_list);
+
+	free(buf->lb_buf, M_TEMP);
+	free(buf, M_TEMP);
+
+	return 0;
+}
+
+SYSINIT(lies, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, lies_init, 0);
+#endif /* LIES */
diff -u -r -N kame/freebsd5/sys/lies/lies_osdep.h kame-lies/freebsd5/sys/lies/lies_osdep.h
--- kame/freebsd5/sys/lies/lies_osdep.h	Thu Jan  1 09:00:00 1970
+++ kame-lies/freebsd5/sys/lies/lies_osdep.h	Thu Jul 28 23:16:39 2005
@@ -0,0 +1,29 @@
+#ifndef	_LIES_LIES_OSDEP_H_
+#define _LIES_LIES_OSDEP_H_
+
+#include <sys/queue.h>
+
+#define LIES_VERSION	1
+
+struct liesbuf {
+	u_int16_t lb_check;
+	char *lb_buf;
+	LIST_ENTRY(liesbuf) lb_list;
+};
+#define LIES_BUF_DEFAULT 0x00
+#define LIES_BUF_CHECKED 0x01
+
+extern struct ifqueue liesintrq;	/* LIES PIP input queue */
+extern struct selinfo lies_sel;		/* knote list for LIES */
+//extern char liesbuf[AEPP_MAXSIZE];	/* temp buf for LIES kqueue only project */
+LIST_HEAD(liesbuf_head, liesbuf);
+extern struct liesbuf_head indlist;
+extern u_int32_t lies_debug;
+
+int lies_send_indication(struct aepp_hdr *);
+
+int lies_add_liesbuf(void *);
+int lies_remove_liesbuf(struct liesbuf *);
+
+
+#endif	/* _LIES_LIES_OSDEP_H_ */
diff -u -r -N kame/freebsd5/sys/net/ethernet.h kame-lies/freebsd5/sys/net/ethernet.h
--- kame/freebsd5/sys/net/ethernet.h	Tue Nov  9 03:20:09 2004
+++ kame-lies/freebsd5/sys/net/ethernet.h	Thu Jul 28 23:16:39 2005
@@ -104,6 +104,7 @@
 #define	ETHERTYPE_VINES 	0x0BAD	/* Banyan VINES */
 #define	ETHERTYPE_VINESLOOP	0x0BAE	/* Banyan VINES Loopback */
 #define	ETHERTYPE_VINESECHO	0x0BAF	/* Banyan VINES Echo */
+#define ETHERTYPE_LIES		0x0C00	/* LIES */
 
 /*		       0x1000 - 0x100F	   Berkeley Trailer */
 /*
diff -u -r -N kame/freebsd5/sys/net/if_ethersubr.c kame-lies/freebsd5/sys/net/if_ethersubr.c
--- kame/freebsd5/sys/net/if_ethersubr.c	Fri Jun 17 14:36:11 2005
+++ kame-lies/freebsd5/sys/net/if_ethersubr.c	Thu Jul 28 23:16:39 2005
@@ -38,6 +38,7 @@
 #include "opt_mac.h"
 #include "opt_netgraph.h"
 #include "opt_carp.h"
+#include "opt_lies.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -810,6 +811,15 @@
 		isr = NETISR_AARP;
 		break;
 #endif /* NETATALK */
+#ifdef LIES
+	case ETHERTYPE_LIES:
+		/*
+		 * Receiving Physical Information Packet
+		 * from Wireless Environment Emulator 
+		 */
+		isr = NETISR_LIES;
+		break;
+#endif /* LIES */
 	default:
 #ifdef IPX
 		if (ef_inputp && ef_inputp(ifp, eh, m) == 0)
diff -u -r -N kame/freebsd5/sys/net/netisr.h kame-lies/freebsd5/sys/net/netisr.h
--- kame/freebsd5/sys/net/netisr.h	Fri May 13 00:16:15 2005
+++ kame-lies/freebsd5/sys/net/netisr.h	Thu Jul 28 23:16:39 2005
@@ -50,6 +50,7 @@
  */
 #define	NETISR_POLL	0		/* polling callback, must be first */
 #define	NETISR_IP	2		/* same as AF_INET */
+#define NETISR_LIES	3		/* LIES */
 #define	NETISR_ROUTE	14		/* routing socket */
 #define	NETISR_AARP	15		/* Appletalk ARP */
 #define	NETISR_ATALK2	16		/* Appletalk phase 2 */
diff -u -r -N kame/freebsd5/sys/sys/event.h kame-lies/freebsd5/sys/sys/event.h
--- kame/freebsd5/sys/sys/event.h	Fri May 13 00:20:51 2005
+++ kame-lies/freebsd5/sys/sys/event.h	Thu Jul 28 23:16:39 2005
@@ -38,8 +38,9 @@
 #define EVFILT_TIMER		(-7)	/* timers */
 #define EVFILT_NETDEV		(-8)	/* network devices */
 #define EVFILT_FS		(-9)	/* filesystem events */
+#define EVFILT_LIES		(-10)	/* LIES */
 
-#define EVFILT_SYSCOUNT		9
+#define EVFILT_SYSCOUNT		10	/* LIES */
 
 #define EV_SET(kevp_, a, b, c, d, e, f) do {	\
 	struct kevent *kevp = (kevp_);		\
@@ -113,6 +114,11 @@
 #define NOTE_LINKUP	0x0001			/* link is up */
 #define NOTE_LINKDOWN	0x0002			/* link is down */
 #define NOTE_LINKINV	0x0004			/* link state is invalid */
+
+/*
+ * data/hint flags for EVFILT_LIES
+ */
+#define NOTE_LIES	0x0001			/* note is not separated by AEPP type */
 
 /*
  * This is currently visible to userland to work around broken
diff -u -r -N kame/freebsd5/sys/sys/socket.h kame-lies/freebsd5/sys/sys/socket.h
--- kame/freebsd5/sys/sys/socket.h	Fri May 13 03:37:17 2005
+++ kame-lies/freebsd5/sys/sys/socket.h	Thu Jul 28 23:16:40 2005
@@ -206,7 +206,8 @@
 #define	AF_ARP		35
 #define	AF_BLUETOOTH	36		/* Bluetooth sockets */
 #define AF_MOBILITY	37
-#define	AF_MAX		38
+#define AF_LIES		38
+#define	AF_MAX		39
 #endif
 
 /*
@@ -292,6 +293,7 @@
 #define	PF_ARP		AF_ARP
 #define	PF_BLUETOOTH	AF_BLUETOOTH
 #define	PF_MOBILITY	AF_MOBILITY
+#define PF_LIES		AF_LIES
 
 #define	PF_MAX		AF_MAX
 
diff -u -r -N kame/kame/sys/lies/CVS/Entries kame-lies/kame/sys/lies/CVS/Entries
--- kame/kame/sys/lies/CVS/Entries	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/CVS/Entries	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,11 @@
+/lies.c/1.5/Mon Jan 17 09:44:03 2005//
+/lies.h/1.4/Sun Jan  9 10:52:40 2005//
+/lies_aepp.c/1.3/Mon Jan 17 09:44:03 2005//
+/lies_aepp.h/1.5/Sun Jan  9 10:52:40 2005//
+/lies_emu.c/1.14/Wed Jan 26 13:06:38 2005//
+/lies_l2.c/1.9/Mon Jan 17 09:44:03 2005//
+/lies_l2.h/1.7/Mon Jan 17 09:44:03 2005//
+/lies_list.h/1.3/Sun Jan  9 07:04:07 2005//
+/lies_pipem.c/1.2/Fri Jan  7 13:51:14 2005//
+/lies_pipem.h/1.5/Tue Jan 18 04:53:23 2005//
+D
diff -u -r -N kame/kame/sys/lies/CVS/Repository kame-lies/kame/sys/lies/CVS/Repository
--- kame/kame/sys/lies/CVS/Repository	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/CVS/Repository	Thu Jul 28 23:16:40 2005
@@ -0,0 +1 @@
+widemip-pre53-lies/kame/sys/lies
diff -u -r -N kame/kame/sys/lies/CVS/Root kame-lies/kame/sys/lies/CVS/Root
--- kame/kame/sys/lies/CVS/Root	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/CVS/Root	Thu Jul 28 23:16:40 2005
@@ -0,0 +1 @@
+/home/mitsuya/cvsroot
diff -u -r -N kame/kame/sys/lies/lies.c kame-lies/kame/sys/lies/lies.c
--- kame/kame/sys/lies/lies.c	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies.c	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,108 @@
+#ifdef LIESTEST
+
+#include <stdio.h>
+#include "lies.h"
+#include "lies_l2.h"
+#include "lies_aepp.h"
+
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+
+#include "opt_lies.h"
+#include <sys/param.h>
+#include <lies/lies.h>
+#include <lies/lies_l2.h>
+#include <lies/lies_aepp.h>
+
+#if __FreeBSD_version >= 500000
+#include <sys/systm.h>
+#endif
+
+#elif defined(linux) 
+#include "lies.h"
+#include "lies_l2.h"
+#include "lies_aepp.h"
+#ifdef __KERNEL__
+#include <linux/param.h>
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/slab.h>
+#else
+#include <sys/param.h>
+#endif /* __KERNEL__ */
+
+#endif /* LIESTEST */
+
+#ifdef LIES
+
+/*
+ * OS dependent code calls lies_dispatcher
+ * for sending REQUEST and receiving CONFIRM
+ */
+int
+lies_dispatcher(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+	struct aepp_hdr *aepphdr;
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: Start Dispatch.\n", __FUNCTION__);
+#else
+	printf("<%s>: Start Dispatch.\n", __FUNCTION__);
+#endif
+
+	aepphdr = (struct aepp_hdr *) aepp_req;
+
+	switch (aepphdr->aepp_layer) {
+	case AEPP_LAYER1:
+		break;
+
+	case AEPP_LAYER2:
+		lies_l2_dispatcher(aepp_req, aepp_cnf);
+		break;
+
+	case AEPP_LAYER3:
+		break;
+
+	case AEPP_LAYER4:
+		break;
+
+	case AEPP_LAYER5:
+		break;
+
+	case AEPP_LAYER6:
+		break;
+
+	case AEPP_LAYER7:
+		break;
+
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+int
+lies_initialize_all(void)
+{
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: Initializing All of LIES.\n", __FUNCTION__);
+#else
+	printf("<%s>: Initializing All of LIES.\n", __FUNCTION__);
+#endif
+
+	/* initialize request table */
+	lies_initialize_req_list();
+	lies_initialize_lists(LIST_PEER);
+
+	/* maybe these are already initialized */
+	lies_initialize_lists(LIST_NEW_PEER);
+	lies_initialize_lists(LIST_PEERFOUND);
+	lies_initialize_lists(LIST_PEERLOST);
+	lies_initialize_lists(LIST_CHANGE);
+	lies_initialize_lists(LIST_THRESHOLD);
+	return 0;
+}
+
+#endif /* LIES */
diff -u -r -N kame/kame/sys/lies/lies.h kame-lies/kame/sys/lies/lies.h
--- kame/kame/sys/lies/lies.h	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies.h	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,9 @@
+#ifndef _LIES_LIES_H_
+#define _LIES_LIES_H_
+
+#define LIES_VERSION	1
+
+int lies_dispatcher(void *, void *);
+int lies_initialize_all(void);
+
+#endif
diff -u -r -N kame/kame/sys/lies/lies_80211.c kame-lies/kame/sys/lies/lies_80211.c
--- kame/kame/sys/lies/lies_80211.c	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_80211.c	Thu Jul 28 23:29:47 2005
@@ -0,0 +1,558 @@
+#ifdef LIESTEST
+#include <stdio.h>
+#include "lies_aepp.h"
+#include "lies_l2.h"
+#include "lies.h"
+
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+
+#include "opt_lies.h"
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/malloc.h>
+#include <sys/event.h>
+#include <sys/selinfo.h>
+#include <lies/lies_aepp.h>
+#include <lies/lies_l2.h>
+#include <lies/lies.h>
+#include <lies/lies_osdep.h>
+
+#if __FreeBSD_version >= 500000
+#include <sys/systm.h>
+
+#endif
+#endif
+
+#ifdef LIES_80211
+#include <lies/lies_80211.h>
+
+struct lif_head liflist;
+
+static void lies_make_peerlist(struct lies_80211_if *, void *);
+
+/*
+ * request registration function
+ */
+int
+lies_80211_register_request(aepp_req)
+	void *aepp_req;
+{
+	/* XXX */
+
+	return 0;
+}
+
+int
+lies_80211_get_peerlist(req, plhdr)
+	struct aepp_hdr *req;
+	struct aepp_peerlist_hdr *plhdr;
+{
+	struct aepp_hdr *hdr = (struct aepp_hdr *)req;
+        struct aepp_ifid *ifid = (struct aepp_ifid *)(hdr + 1);
+	struct lies_80211_if *lif = NULL;
+	struct lies_80211_if *i_lif = NULL;
+	
+	/* ifid to lies_80211_if */
+	if (ifid->aepple_arch == AEPP_PARAM_ARCH_MAC) {
+		LIST_FOREACH(i_lif, &liflist, lif_next) {
+			if (memcmp(ifid->aepple_ifid,
+				   i_lif->lif_macaddr, AEPP_IDSIZE) == 0) {
+				lif = i_lif;
+				break;
+			}
+		}
+	}
+	else if (ifid->aepple_arch == AEPP_PARAM_ARCH_IFNAME) {
+		LIST_FOREACH(i_lif, &liflist, lif_next) {
+			if (memcmp(ifid->aepple_ifid,
+				   i_lif->lif_name, AEPP_IDSIZE) == 0) {
+				lif = i_lif;
+				break;
+			}
+		}
+	}
+	else {
+		return -1; /* Unsupported architecture */
+	}
+
+	if (lif == NULL)
+		return -1; /* Not Found*/
+
+	lies_make_peerlist(lif, plhdr);
+	
+	return 0;
+}
+
+int
+lies_80211_get_status(req, peer)
+	struct aepp_hdr *req;
+	struct aepp_peer *peer;
+{
+	struct aepp_hdr *hdr = (struct aepp_hdr *)req;
+        struct aepp_ifid *ifid = (struct aepp_ifid *)(hdr + 1);
+	struct lies_80211_if *lif = NULL;
+	struct lies_80211_if *i_lif = NULL;
+	
+	/* ifid to lies_80211_if */
+	if (ifid->aepple_arch == AEPP_PARAM_ARCH_MAC) {
+		LIST_FOREACH(i_lif, &liflist, lif_next) {
+			if (memcmp(ifid->aepple_ifid,
+				   i_lif->lif_macaddr, AEPP_IDSIZE) == 0) {
+				lif = i_lif;
+				break;
+			}
+		}
+	}
+	else if (ifid->aepple_arch == AEPP_PARAM_ARCH_IFNAME) {
+		LIST_FOREACH(i_lif, &liflist, lif_next) {
+			if (memcmp(ifid->aepple_ifid,
+				   i_lif->lif_name, AEPP_IDSIZE) == 0) {
+				lif = i_lif;
+				break;
+			}
+		}
+	}
+	else {
+		return -1; /* Unsupported architecture */
+	}
+
+	if (lif == NULL)
+		return -1; /* Not Found*/
+
+	/* XXX */
+	
+	return 0;
+}
+
+/*
+ * Make Indication Functions
+ */
+int
+lies_80211_peerfound_indication(lif)
+	struct lies_80211_if *lif;
+{
+	struct aepp_hdr *hdr;
+        struct aepp_ifid *ifid;
+        struct aepp_iftype *iftype;
+        struct aepp_peerlist_hdr *peerlist;
+	u_int8_t buf[AEPP_MAXSIZE];
+        int count;
+        u_int type;
+
+	memset(buf, 0, AEPP_MAXSIZE);
+
+	/* aepp payload length */
+        count = 0;
+
+        /* Init aepp header */
+        hdr = (struct aepp_hdr *)buf;
+
+        /* Set aepp ifid  */
+        ifid = (struct aepp_ifid *)(hdr + 1);
+        lies_aepp_set_ifid(ifid, AEPP_PARAM_ARCH_IFNAME
+                           , lif->lif_name); /* name + unit */
+        count += ifid->aepple_len;
+
+        /* Set aepp iftype */
+        iftype = (struct aepp_iftype *)(ifid + 1);
+        type = AEPP_PARAM_IF_IEEE80211;
+        lies_aepp_set_iftype(iftype, type);
+        count += iftype->aepple_len;
+
+        /* Set aepp peerlist */
+        peerlist = (struct aepp_peerlist_hdr *)(iftype + 1);
+        lies_make_peerlist(lif, peerlist);
+        count += peerlist->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2
+                        , AEPP_CLASS_IND, 0, 0, 0, 0, 0
+                        , AEPP_TYPE_PEERFOUND, count);
+	
+	lies_send_indication(hdr);
+	
+	return 0;
+}
+
+int
+lies_80211_peerlost_indication(lif)
+        struct lies_80211_if *lif;
+{
+	struct aepp_hdr *hdr;
+        struct aepp_ifid *ifid;
+        struct aepp_iftype *iftype;
+        struct aepp_peerlist_hdr *peerlist;
+	u_int8_t buf[AEPP_MAXSIZE];
+        int count;
+        u_int type;
+
+	memset(buf, 0, AEPP_MAXSIZE);
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Init aepp header*/
+        hdr = (struct aepp_hdr *)buf;
+
+        /* Set aepp ifid  */
+        ifid = (struct aepp_ifid *)(hdr + 1);
+        lies_aepp_set_ifid(ifid, AEPP_PARAM_ARCH_IFNAME
+                           , lif->lif_name); /* name + unit */
+        count += ifid->aepple_len;
+
+        /* Set aepp iftype */
+        iftype = (struct aepp_iftype *)(ifid + 1);
+        type = AEPP_PARAM_IF_IEEE80211;
+        lies_aepp_set_iftype(iftype, type);
+        count += iftype->aepple_len;
+
+        /* Set aepp peerlist */
+        peerlist = (struct aepp_peerlist_hdr *)(iftype + 1);
+        lies_make_peerlist(lif, peerlist);
+        count += peerlist->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2
+                        , AEPP_CLASS_IND, 0, 0, 0, 0, 0
+                        , AEPP_TYPE_PEERLOST, count);
+	
+	lies_send_indication(hdr);
+
+        return 0;
+}
+
+int
+lies_80211_linkup_indication(lif, lpeer)
+        struct lies_80211_if *lif;
+	struct lies_80211_peer *lpeer;
+{
+        struct aepp_hdr *hdr;
+        struct aepp_ifid *ifid;
+        struct aepp_iftype *iftype;
+        struct aepp_peer *peer;
+	u_int8_t buf[AEPP_MAXSIZE];
+        int count;
+        u_int type;
+
+	memset(buf, 0, AEPP_MAXSIZE);
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Init aepp header*/
+        hdr = (struct aepp_hdr *)buf;
+
+        /* Set aepp ifid  */
+        ifid = (struct aepp_ifid *)(hdr + 1);
+        lies_aepp_set_ifid(ifid, AEPP_PARAM_ARCH_IFNAME
+                           , lif->lif_name); /* name + unit */
+        count += ifid->aepple_len;
+
+        /* Set aepp iftype */
+        iftype = (struct aepp_iftype *)(ifid + 1);
+        type = AEPP_PARAM_IF_IEEE80211;
+        lies_aepp_set_iftype(iftype, type);
+        count += iftype->aepple_len;
+
+        /* Set aepp peer */
+        peer = (struct aepp_peer *)(iftype + 1);
+        lies_aepp_set_peer(peer, AEPP_PARAM_ARCH_SSID, AEPP_PARAM_ARCH_MAC
+                           ,lpeer->peer_netid, lpeer->peer_attid);
+        count += peer->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2
+                        , AEPP_CLASS_IND, 0, 0, 0, 0, 0
+                        , AEPP_TYPE_LINKUP, count);
+	
+	lies_send_indication(hdr);
+
+        return 0;
+}
+
+int
+lies_80211_linkdown_indication(lif, lpeer)
+        struct lies_80211_if *lif;
+	struct lies_80211_peer *lpeer;
+{
+        struct aepp_hdr *hdr;
+        struct aepp_ifid *ifid;
+        struct aepp_iftype *iftype;
+        struct aepp_peer *peer;
+	u_int8_t buf[AEPP_MAXSIZE];
+        int count;
+        u_int type;
+
+	memset(buf, 0, AEPP_MAXSIZE);
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Init aepp header*/
+        hdr = (struct aepp_hdr *)buf;
+
+        /* Set aepp ifid  */
+        ifid = (struct aepp_ifid *)(hdr + 1);
+        lies_aepp_set_ifid(ifid, AEPP_PARAM_ARCH_IFNAME
+                           , lif->lif_name); /* name + unit */
+        count += ifid->aepple_len;
+
+        /* Set aepp iftype */
+        iftype = (struct aepp_iftype *)(ifid + 1);
+        type = AEPP_PARAM_IF_IEEE80211;
+        lies_aepp_set_iftype(iftype, type);
+        count += iftype->aepple_len;
+
+        /* Set aepp peer */
+        peer = (struct aepp_peer *)(iftype + 1);
+        lies_aepp_set_peer(peer, AEPP_PARAM_ARCH_SSID, AEPP_PARAM_ARCH_MAC
+                           ,lpeer->peer_netid, lpeer->peer_attid);
+        count += peer->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2
+                        , AEPP_CLASS_IND, 0, 0, 0, 0, 0
+                        , AEPP_TYPE_LINKDOWN, count);
+	
+	lies_send_indication(hdr);
+
+        return 0;
+}
+
+int
+lies_80211_linktobedown_indication(lif, lpeer)
+        struct lies_80211_if *lif;
+	struct lies_80211_peer *lpeer;
+{
+        struct aepp_hdr *hdr;
+        struct aepp_ifid *ifid;
+        struct aepp_iftype *iftype;
+        struct aepp_peer *peer;
+	u_int8_t buf[AEPP_MAXSIZE];
+        int count;
+        u_int type;
+
+	memset(buf, 0, AEPP_MAXSIZE);
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Init aepp header*/
+        hdr = (struct aepp_hdr *)buf;
+
+        /* Set aepp ifid  */
+        ifid = (struct aepp_ifid *)(hdr + 1);
+        lies_aepp_set_ifid(ifid, AEPP_PARAM_ARCH_IFNAME
+                           , lif->lif_name); /* name + unit */
+        count += ifid->aepple_len;
+
+        /* Set aepp iftype */
+        iftype = (struct aepp_iftype *)(ifid + 1);
+        type = AEPP_PARAM_IF_IEEE80211;
+        lies_aepp_set_iftype(iftype, type);
+        count += iftype->aepple_len;
+
+        /* Set aepp peer */
+        peer = (struct aepp_peer *)(iftype + 1);
+        lies_aepp_set_peer(peer, AEPP_PARAM_ARCH_SSID, AEPP_PARAM_ARCH_MAC
+                           ,lpeer->peer_netid, lpeer->peer_attid);
+        count += peer->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2
+                        , AEPP_CLASS_IND, 0, 0, 0, 0, 0
+                        , AEPP_TYPE_LINKTOBEDOWN, count);
+	
+	lies_send_indication(hdr);
+
+        return 0;
+}
+
+int
+lies_80211_linkconnect(req) 
+	struct aepp_hdr *req;
+{
+        struct aepp_ifid *ifid;
+        struct aepp_iftype *iftype;
+	struct aepp_peer *peer;
+	int error;
+
+	printf("<%s:%d>\n",__FUNCTION__, __LINE__);
+
+	ifid = (struct aepp_ifid *)(req + 1);
+        iftype = (struct aepp_iftype *)(ifid + 1);
+	peer = (struct aepp_peer *)(iftype + 1);
+
+		struct lies_80211_if *lif = NULL;
+	struct lies_80211_if *i_lif = NULL;
+	
+	/* ifid to lies_80211_if */
+	if (ifid->aepple_arch == AEPP_PARAM_ARCH_MAC) {
+		LIST_FOREACH(i_lif, &liflist, lif_next) {
+			if (memcmp(ifid->aepple_ifid,
+				   i_lif->lif_macaddr, AEPP_IDSIZE) == 0) {
+				lif = i_lif;
+				break;
+			}
+		}
+	}
+	else if (ifid->aepple_arch == AEPP_PARAM_ARCH_IFNAME) {
+		LIST_FOREACH(i_lif, &liflist, lif_next) {
+			if (memcmp(ifid->aepple_ifid,
+				   i_lif->lif_name, AEPP_IDSIZE) == 0) {
+				lif = i_lif;
+				break;
+			}
+		}
+	}
+	else {
+		return -1; /* Unsupported architecture */
+	}
+
+	if (lif == NULL)
+		return -1; /* Not Found */
+	else if (lif->lif_connect == NULL)
+		return -1; /* No connect function */
+
+	error = lif->lif_connect(lif->lif_osif, peer->aepple_attid);
+	return error;
+}
+
+
+/*
+ * Other functions
+ */
+static void
+lies_make_peerlist(lif, aepple)
+        struct lies_80211_if *lif;
+        void *aepple;
+{
+        struct aepp_peerlist_hdr *hdr;
+        struct aepp_peerlist_le *le;
+        struct lies_80211_peer *peer;
+        int count;
+
+        hdr = (struct aepp_peerlist_hdr *)aepple;
+        le = (struct aepp_peerlist_le *)(hdr + 1);
+        count = 0;
+
+        LIST_FOREACH(peer, &lif->lif_peer, peer_next) {
+                if (peer->peer_state == LIES_80211_PEER_ENABLE) {
+                        le->aepple_netarch = peer->peer_netarch;
+                        le->aepple_attarch = peer->peer_attarch;
+                        memcpy(le->aepple_netid, peer->peer_netid,
+			       AEPP_NETIDSIZE);
+                        memcpy(le->aepple_attid, peer->peer_attid, 
+			       AEPP_IDSIZE);
+                        le->aepple_rate = peer->peer_rate;
+                        le->aepple_shift = peer->peer_shift;
+                        le->aepple_qual = peer->peer_qual;
+                        le->aepple_noise = 0; /* XXX */
+                        
+                        le ++;
+                        count += sizeof(struct aepp_peerlist_le);
+                }
+        }
+
+        lies_aepp_set_peerlist_hdr(hdr, count);
+}
+
+struct lies_80211_if *
+lies_80211_ifattach(name, macaddr)
+	u_int8_t *name;
+	u_int8_t *macaddr;
+{
+	struct lies_80211_if *lif;
+	lif = malloc(sizeof(struct lies_80211_if), M_TEMP, M_NOWAIT);
+
+	if (lif == NULL)
+		return NULL;
+
+	memset(lif, 0, sizeof(struct lies_80211_if));
+
+	memcpy(lif->lif_name, name, AEPP_IDSIZE);
+	memcpy(lif->lif_macaddr, macaddr, AEPP_IDSIZE);
+
+	LIST_INSERT_HEAD(&liflist, lif, lif_next);
+
+	return lif;
+}
+
+int
+lies_80211_ifdetach(lif)
+	struct lies_80211_if *lif;
+{
+	struct lies_80211_peer *peer = NULL;
+
+	LIST_REMOVE(lif, lif_next);
+
+	while ((peer = LIST_FIRST(&lif->lif_peer)) != NULL) {
+		LIST_REMOVE(peer, peer_next);
+		free(peer, M_TEMP);
+	}
+
+	free(lif, M_TEMP);
+
+	return 0;
+}
+
+struct lies_80211_peer *
+lies_80211_peer_find(lif, addr, arch)
+	struct lies_80211_if *lif;
+	u_int8_t *addr;
+	u_int16_t arch;
+{
+	struct lies_80211_peer *peer = NULL;
+	u_int8_t addrlen = 0;
+
+	if (arch == AEPP_PARAM_ARCH_MAC)
+		addrlen = 6;
+	else
+		return NULL; /* unsupported */
+
+	LIST_FOREACH(peer, &lif->lif_peer, peer_next) {
+		if (memcmp(addr, peer->peer_attid, addrlen) == 0)
+			return peer;
+	}
+	
+	return NULL;
+}
+
+struct lies_80211_peer *
+lies_80211_peer_add(lif, addr, arch)
+	struct lies_80211_if *lif;
+	u_int8_t *addr;
+	u_int16_t arch;
+{
+	struct lies_80211_peer *peer = NULL;
+	u_int8_t addrlen = 0;
+
+ 	if (arch == AEPP_PARAM_ARCH_MAC)
+		addrlen = 6;
+	else
+		return NULL; /* unsupported */
+
+	peer = (struct lies_80211_peer *)malloc(
+		sizeof(struct lies_80211_peer), M_TEMP, M_NOWAIT);
+
+	if (peer == NULL)
+		return NULL;
+
+	memset(peer, 0, sizeof(struct lies_80211_peer));
+	memcpy(peer->peer_attid, addr, addrlen);
+	peer->peer_attarch = arch;
+
+	LIST_INSERT_HEAD(&lif->lif_peer, peer, peer_next);
+
+	return peer;
+}
+
+void
+lies_80211_peer_remove(peer)
+	struct lies_80211_peer *peer;
+{
+	LIST_REMOVE(peer, peer_next);
+	free(peer, M_TEMP);
+}
+
+#endif /* LIES_80211 */
diff -u -r -N kame/kame/sys/lies/lies_80211.h kame-lies/kame/sys/lies/lies_80211.h
--- kame/kame/sys/lies/lies_80211.h	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_80211.h	Thu Jul 28 23:32:03 2005
@@ -0,0 +1,57 @@
+#ifndef _LIES_80211_H_
+#define _LIES_80211_H_
+
+LIST_HEAD(lif_head, lies_80211_if);
+extern struct lif_head liflist;
+
+struct lies_80211_if {
+	u_int8_t lif_name[AEPP_IDSIZE];
+	u_int8_t lif_macaddr[AEPP_IDSIZE];
+
+        int (*lif_connect)(void *, u_int8_t *);
+        void *lif_osif;
+
+	LIST_HEAD(,lies_80211_peer) lif_peer;
+	LIST_ENTRY(lies_80211_if) lif_next;
+};
+
+struct lies_80211_peer {
+	u_int16_t peer_netarch;
+	u_int16_t peer_attarch;
+        u_int8_t peer_netid[AEPP_NETIDSIZE];
+        u_int8_t peer_attid[AEPP_IDSIZE];
+        u_int8_t peer_rate;
+        u_int8_t peer_shift;
+        u_int8_t peer_qual; /* XXX temporally 8bit */
+        u_int8_t peer_state;
+
+        LIST_ENTRY(lies_80211_peer) peer_next;
+};
+
+#define LIES_80211_PEER_ENABLE 0x01
+#define LIES_80211_PEER_ACTIVE 0x02
+
+int lies_80211_register_request(void *);
+int lies_80211_get_peerlist(struct aepp_hdr *, struct aepp_peerlist_hdr *);
+int lies_80211_get_status(struct aepp_hdr *, struct aepp_peer *);
+
+int lies_80211_peerfound_indication(struct lies_80211_if *);
+int lies_80211_peerlost_indication(struct lies_80211_if *);
+int lies_80211_linkup_indication(struct lies_80211_if *,
+				 struct lies_80211_peer *);
+int lies_80211_linkdown_indication(struct lies_80211_if *,
+				   struct lies_80211_peer *);
+int lies_80211_linktobedown_indication(struct lies_80211_if *,
+				       struct lies_80211_peer *);
+int lies_80211_linkconnect(struct aepp_hdr *);
+
+struct lies_80211_if *lies_80211_ifattach(u_int8_t *, u_int8_t *);
+int lies_80211_ifdetach(struct lies_80211_if *);
+
+struct lies_80211_peer *lies_80211_peer_find(struct lies_80211_if *,
+					     u_int8_t *, u_int16_t);
+struct lies_80211_peer *lies_80211_peer_add(struct lies_80211_if *,
+					    u_int8_t *, u_int16_t);
+void lies_80211_peer_remove(struct lies_80211_peer *);
+
+#endif /* _LIES_80211_H_ */
diff -u -r -N kame/kame/sys/lies/lies_aepp.c kame-lies/kame/sys/lies/lies_aepp.c
--- kame/kame/sys/lies/lies_aepp.c	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_aepp.c	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,254 @@
+#ifdef LIESTEST
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "lies_aepp.h"
+
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+
+#include "opt_lies.h"
+#include <sys/param.h>
+#include <lies/lies_aepp.h>
+
+#if __FreeBSD_version >= 500000
+#include <sys/systm.h>
+#endif
+
+#elif defined(linux)
+#include "lies_aepp.h"
+#ifdef __KERNEL__
+#include <linux/param.h>
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/slab.h>
+#else
+#include <sys/param.h>
+#endif /* __KERNEL__ */
+
+#endif
+
+#ifdef LIES
+
+int
+lies_aepp_set_hdr(hdr, ver, layer, class, req, cnf, res, tgtype, tgid, type, len)
+	struct aepp_hdr *hdr;
+	u_int ver;
+	u_int layer;
+	u_int class;
+	u_int req;
+	u_int cnf;
+	u_int8_t res;
+	u_int8_t tgtype;
+	u_int32_t tgid;
+	u_int16_t type;
+	u_int16_t len;
+{
+	if(hdr == NULL) {  
+		return -1;
+	}
+
+	hdr->aepp_ver = ver;
+	hdr->aepp_layer = layer;
+	hdr->aepp_class = class;
+	hdr->aepp_req = req;
+	hdr->aepp_cnf = cnf;
+	hdr->aepp_res = res;
+	hdr->aepp_tgtype = tgtype;
+	hdr->aepp_tgid = tgid;
+	hdr->aepp_type = type;
+	hdr->aepp_len = len;
+
+	return 0;
+}
+int
+lies_aepp_print_hdr(hdr)
+	struct aepp_hdr *hdr;
+{
+	if(hdr == NULL) {  
+		return -1;
+	}
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "--- aepp header ---\n version: %d\n layer: %d\n class: %d\n request: %d\n confirm: %d\n response: %d\n target type: %d\n target id: %d\n type: %d\n length: %d\n-------------------\n", hdr->aepp_ver, hdr->aepp_layer, hdr->aepp_class, hdr->aepp_req, hdr->aepp_cnf, hdr->aepp_res, hdr->aepp_tgtype, hdr->aepp_tgid, hdr->aepp_type, hdr->aepp_len);
+#else
+	printf("--- aepp header ---\n version: %d\n layer: %d\n class: %d\n request: %d\n confirm: %d\n response: %d\n target type: %d\n target id: %d\n type: %d\n length: %d\n-------------------\n", hdr->aepp_ver, hdr->aepp_layer, hdr->aepp_class, hdr->aepp_req, hdr->aepp_cnf, hdr->aepp_res, hdr->aepp_tgtype, hdr->aepp_tgid, hdr->aepp_type, hdr->aepp_len);
+#endif
+
+	return 0;
+}
+
+
+int
+lies_aepp_set_ifid(ifid, arch, id)
+	struct aepp_ifid *ifid;
+	u_int16_t arch;
+	u_char id[AEPP_IDSIZE];    
+{
+	if( ifid == NULL) {
+		return -1;
+	}
+  
+	ifid->aepple_type = AEPP_PARAM_TYPE_IFID;
+	ifid->aepple_len = sizeof(struct aepp_ifid);
+	ifid->aepple_arch = arch;
+	if ( id != NULL ) {
+		memcpy(ifid->aepple_ifid, id, AEPP_IDSIZE);
+	}
+
+	return 0;
+}
+
+
+int
+lies_aepp_set_iftype(iftype, type)
+	struct aepp_iftype *iftype;
+	u_int16_t type;
+{
+	if(iftype == NULL) {  
+		return -1;
+	}
+  
+	iftype->aepple_type = AEPP_PARAM_TYPE_IFTYPE;
+	iftype->aepple_len = sizeof(struct aepp_iftype);
+	iftype->aepple_iftype = type;
+
+	return 0;
+}
+
+
+int
+lies_aepp_set_ifrate(ifrate, rate, shift)
+	struct aepp_ifrate *ifrate;
+	u_int8_t rate;
+	u_int8_t shift;
+{
+	if(ifrate == NULL) {
+		return -1;
+	}
+  
+	ifrate->aepple_type = AEPP_PARAM_TYPE_IFRATE;
+	ifrate->aepple_len = sizeof(struct aepp_ifrate);
+	ifrate->aepple_rate = rate;
+	ifrate->aepple_shift = shift;
+
+	return 0;
+}
+
+
+int
+lies_aepp_set_peer(peer, netarch, attarch, netid, attid)
+	struct aepp_peer *peer;
+	u_int16_t netarch;
+	u_int16_t attarch;
+	u_char netid[AEPP_NETIDSIZE];
+	u_char attid[AEPP_IDSIZE];
+{
+	if(peer == NULL) {
+		return -1;
+	}
+
+	peer->aepple_type = AEPP_PARAM_TYPE_PEER;
+	peer->aepple_len = sizeof(struct aepp_peer);
+	peer->aepple_netarch = netarch;
+	peer->aepple_attarch = attarch;
+	if (netid != NULL) {
+		memcpy(peer->aepple_netid, netid, AEPP_NETIDSIZE);
+	}
+	if (attid != NULL) {
+		memcpy(peer->aepple_attid, attid, AEPP_IDSIZE);
+	}
+
+	return 0;
+}
+
+
+int
+lies_aepp_set_condition(cond, rate, shift, qual, noise)
+	struct aepp_condition *cond;
+	u_int8_t rate;
+	u_int8_t shift;
+	u_int16_t qual;
+	u_int16_t noise;
+{
+	if(cond == NULL) {
+		return -1;
+	}
+
+	cond->aepple_type = AEPP_PARAM_TYPE_CONDITION;
+	cond->aepple_len = sizeof(struct aepp_condition);
+	cond->aepple_rate = rate;
+	cond->aepple_shift = shift;
+	cond->aepple_qual = qual;
+	cond->aepple_noise = noise;
+
+	return 0;
+}
+
+
+int
+lies_aepp_set_threshold(pointer, th)
+	void *pointer;
+	u_int16_t th;
+{
+	struct aepp_threshold *p = (struct aepp_threshold *)pointer;
+	if(pointer == NULL) {  
+		return -1;
+	}
+  
+	p->aepple_type = AEPP_PARAM_TYPE_THRESHOLD;
+	p->aepple_len = sizeof(struct aepp_threshold);
+	p->aepple_th = th;
+
+	return 0;
+}
+
+
+int
+lies_aepp_set_peerlist_hdr(plhdr, len)
+	struct aepp_peerlist_hdr *plhdr;
+	u_int16_t len;
+{
+	if(plhdr == NULL) {
+		return -1;
+	}
+
+	plhdr->aepple_type = AEPP_PARAM_TYPE_PEERLIST;
+	plhdr->aepple_len = len;
+
+	return 0;
+}
+
+
+int
+lies_aepp_set_peerlist_le(plle, netarch, attarch, netid, attid, rate, shift, qual, noise)
+	struct aepp_peerlist_le *plle;
+	u_int16_t netarch;
+	u_int16_t attarch;
+	u_char netid[AEPP_NETIDSIZE];
+	u_char attid[AEPP_IDSIZE];
+	u_int8_t rate;
+	u_int8_t shift;
+	u_int16_t qual;
+	u_int16_t noise;
+{
+	if(plle == NULL) {
+		return -1;
+	}
+  
+	plle->aepple_netarch = netarch;
+	plle->aepple_attarch = attarch;
+	if (netid != NULL) {
+		memcpy(plle->aepple_netid, netid, sizeof(plle->aepple_netid));
+	}
+	if (attid != NULL) {
+		memcpy(plle->aepple_attid, attid, sizeof(plle->aepple_attid));
+	}
+	plle->aepple_rate = rate;
+	plle->aepple_shift = shift;
+	plle->aepple_qual = qual;
+	plle->aepple_noise = noise;
+
+	return 0;
+}
+
+#endif /* LIES */
diff -u -r -N kame/kame/sys/lies/lies_aepp.h kame-lies/kame/sys/lies/lies_aepp.h
--- kame/kame/sys/lies/lies_aepp.h	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_aepp.h	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,176 @@
+#ifndef _LIES_LIES_AEPP_H_
+#define _LIES_LIES_AEPP_H_
+
+/***** Abstract Entity Parameter Packet ****/
+#if defined(linux) && defined(__KERNEL__)
+
+#include <linux/types.h>
+#else
+#include <sys/types.h>
+
+#endif
+
+#define AEPP_VERSION	0x1
+
+#define AEPP_VERSION1	0x1
+
+#define AEPP_LAYER1	0x1
+#define AEPP_LAYER2	0x2
+#define AEPP_LAYER3	0x3
+#define AEPP_LAYER4	0x4
+#define AEPP_LAYER5	0x5
+#define AEPP_LAYER6	0x6
+#define AEPP_LAYER7	0x7
+
+#define AEPP_CLASS_REQ	0x0
+#define AEPP_CLASS_CNF	0x1
+#define AEPP_CLASS_IND	0x2
+#define AEPP_CLASS_RESP	0x3
+
+#define AEPP_REQ_ENABLE		0x0
+#define AEPP_REQ_DISABLE	0x1
+
+#define AEPP_CNF_ACK	0x0
+#define AEPP_CNF_ERROR	0x1
+
+#define AEPP_TYPE_PEERLIST		0x0001
+#define AEPP_TYPE_PEERFOUND		0x0002
+#define AEPP_TYPE_PEERLOST		0x0003
+#define AEPP_TYPE_LINKUP		0x0004
+#define AEPP_TYPE_LINKDOWN		0x0005
+#define AEPP_TYPE_LINKTOBEDOWN		0x0006
+#define AEPP_TYPE_LINKSTATUS		0x0007
+#define AEPP_TYPE_LINKCONNECT		0x0008
+#define AEPP_TYPE_LINKDISCONNECT	0x0009
+
+#define AEPP_TGTYPE_USERLAND_PROCESS	0x0001
+#define AEPP_TGTYPE_KERNEL_FUNCTION	0x0002
+
+#define AEPP_PARAM_TYPE_IFID		0x0001
+#define AEPP_PARAM_TYPE_IFTYPE		0x0002
+#define AEPP_PARAM_TYPE_IFOPT		0x0003
+#define AEPP_PARAM_TYPE_IFRATE		0x0004
+#define AEPP_PARAM_TYPE_PEER		0x0005
+#define AEPP_PARAM_TYPE_CONDITION	0x0006
+#define AEPP_PARAM_TYPE_PEERLIST	0x0007
+#define AEPP_PARAM_TYPE_SECURITY	0x0008
+#define AEPP_PARAM_TYPE_THRESHOLD	0x0009
+
+#define AEPP_PARAM_ARCH_MAC	0x0001
+#define AEPP_PARAM_ARCH_SSID	0x0002
+#define AEPP_PARAM_ARCH_IFNAME	0x0003
+
+#define AEPP_PARAM_IF_ETHER	0x0001
+#define AEPP_PARAM_IF_IEEE80211	0x8001
+#define AEPP_PARAM_IF_EMULATOR  0x8080
+
+#define AEPP_IDSIZE		16
+#define AEPP_NETIDSIZE		32
+#define AEPP_HDRSIZE		12
+#define AEPP_MAXSIZE		1500
+
+
+struct aepp_hdr{
+	u_int aepp_ver:4;
+	u_int aepp_layer:4;
+	u_int aepp_class:4;
+	u_int aepp_req:2;
+	u_int aepp_cnf:2;
+	u_int aepp_res:8;
+	u_int aepp_tgtype:8;
+	u_int aepp_tgid:32;
+	u_int aepp_type:16;
+	u_int aepp_len:16;
+};
+
+struct aepple_hdr{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+};
+
+struct aepp_ifid{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+	u_int aepple_arch:16;
+	u_char aepple_ifid[AEPP_IDSIZE];
+};
+
+struct aepp_iftype{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+	u_int aepple_iftype:16;
+};
+
+/* To Be Defined */
+struct aepp_iftypeopt{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+};
+
+struct aepp_ifrate{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+	u_int aepple_rate:8;
+	u_int aepple_shift:8;
+};
+
+struct aepp_peer{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+	u_int aepple_netarch:16;
+	u_int aepple_attarch:16;
+	u_char aepple_netid[AEPP_NETIDSIZE];
+	u_char aepple_attid[AEPP_IDSIZE];
+};
+
+struct aepp_condition{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+	u_int aepple_rate:8;
+	u_int aepple_shift:8;
+	u_int aepple_qual:16;
+	u_int aepple_noise:16;
+};
+
+struct aepp_threshold{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+	u_int aepple_th:16;
+};
+
+/* To Be Defined*/
+struct aepp_security{
+	u_int aepple_type:16;
+	u_int aepple_len:16;
+};
+
+struct aepp_peerlist_hdr{
+	u_int aepple_type:16;
+	u_int aepple_len:16; 
+};
+
+struct aepp_peerlist_le{
+	u_int aepple_netarch:16;
+	u_int aepple_attarch:16;
+	u_char aepple_netid[AEPP_NETIDSIZE];
+	u_char aepple_attid[AEPP_IDSIZE];
+	u_int aepple_rate:8;
+	u_int aepple_shift:8;
+	u_int aepple_qual:16;
+	u_int aepple_noise:16;
+};
+
+
+int lies_aepp_set_hdr(struct aepp_hdr *, u_int, u_int, u_int, u_int, u_int, u_int8_t, u_int8_t, u_int32_t, u_int16_t, u_int16_t);
+int lies_aepp_print_hdr(struct aepp_hdr *);
+int lies_aepp_set_ifid(struct aepp_ifid *, u_int16_t, u_char *);
+int lies_aepp_set_iftype(struct aepp_iftype *, u_int16_t);
+int lies_aepp_set_ifrate(struct aepp_ifrate *, u_int8_t, u_int8_t);
+int lies_aepp_set_peer(struct aepp_peer *, u_int16_t, u_int16_t, u_char *, u_char *);
+int lies_aepp_set_condition(struct aepp_condition *, u_int8_t, u_int8_t, u_int16_t, u_int16_t);
+int lies_aepp_set_threshold(void *, u_int16_t);
+int lies_aepp_set_peerlist_hdr(struct aepp_peerlist_hdr *, u_int16_t);
+int lies_aepp_set_peerlist_le(struct aepp_peerlist_le *, u_int16_t, u_int16_t, u_char *, u_char *, u_int8_t, u_int8_t, u_int16_t, u_int16_t);
+
+
+#endif
diff -u -r -N kame/kame/sys/lies/lies_emu.c kame-lies/kame/sys/lies/lies_emu.c
--- kame/kame/sys/lies/lies_emu.c	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_emu.c	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,855 @@
+#ifdef LIESTEST
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include "lies_pipem.h"
+#include "lies_aepp.h"
+#include "lies_list.h"
+#include "lies_l2.h"
+
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+
+#include "opt_lies.h"
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/malloc.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+//#include <net/if.h>
+//#include <net/if_var.h>
+#include <lies/lies_pipem.h>
+#include <lies/lies_aepp.h>
+#include <lies/lies_list.h>
+#include <lies/lies_l2.h>
+
+#if __FreeBSD_version >= 500000
+#include <sys/systm.h>
+#endif
+
+#elif defined(linux)
+
+#include "lies_pipem.h"
+#include "lies_aepp.h"
+#include "lies_list.h"
+#include "lies_l2.h"
+#ifdef __KERNEL__
+#include <linux/param.h>
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/slab.h>
+#else
+#include <sys/param.h>
+#endif /* __KERNEL__ */
+
+#endif
+
+/* definition for peer quality */
+#define VERYGOOD 80
+#define GOOD     60
+#define FAIR     40
+#define BAD      30
+#define VERYBAD  20
+
+/* definition for request type */
+#define PEERFOUND    0x02
+#define PEERLOST     0x03
+#define LINKUP       0x04
+#define LINKDOWN     0x05
+#define LINKTOBEDOWN 0x06
+
+/* emulator's peer timeout time */
+#define TIMEOUT      10
+
+int current_peer = 0;
+
+int lies_regist_peer_table(void *);
+int lies_regist_new_peer_table(void *);
+struct lies_table_peer * lies_make_table_peer(struct pipem_peerinfo *peerinfo);
+struct lies_table_new_peer * lies_make_table_new_peer(struct pipem_peerinfo *peerinfo);
+
+int lies_compare_peer_table(void);
+int lies_regist_peer_change(struct lies_table_peer *peer, struct lies_table_new_peer *new_peer);
+int lies_emu_convert_peerlist(struct aepp_peerlist_le *peerlist_le, struct lies_table_peer *peer);
+int lies_compare_threshold_table(void);
+int lies_update_peer_table(struct lies_table_new_peer *peer);
+int lies_timeout_peer(void);
+int lies_make_indication(int pri_type, struct lies_table_peer_change *change);
+
+#ifdef LIES
+
+/* Permanent Current-Peer-List */
+LIES_LIST_HEAD(lies_peer_list, lies_table_peer) lies_peer_list;
+
+/* Temporary New-Peer-List */
+LIES_LIST_HEAD(lies_new_peer_list, lies_table_new_peer) lies_new_peer_list;
+
+/* Peer-List.diff between Current-Peer-List and New-Peer-List */
+LIES_LIST_HEAD(lies_peer_change_list, lies_table_peer_change) lies_peer_change_list;
+
+LIES_LIST_HEAD(lies_peerfound_list, lies_table_peerfound) lies_peerfound_list;
+LIES_LIST_HEAD(lies_peerlost_list, lies_table_peerlost) lies_peerlost_list;
+LIES_LIST_HEAD(lies_threshold_list, lies_table_threshold) lies_threshold_list;
+
+/*
+ * input frame from emulator
+ */
+void *
+lies_emu_pipem_input(void *pipem)
+{
+	char *pipem_next;
+	int size;
+	struct pipem_hdr *pipemhdr;
+	struct pipemle_hdr *next_pipemle;
+	struct pipem_peerinfo *peerinfo;
+	struct pipem_connectinfo *connectinfo;
+	struct pipem_disconnectinfo *disconnectinfo;
+	struct lies_table_peer_change change;
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: PIPEM is coming for INDICATION.\n", __FUNCTION__);
+#else
+	printf("<%s>: PIPEM is coming for INDICATION.\n", __FUNCTION__);
+#endif
+
+	pipemhdr = (struct pipem_hdr *) pipem;
+	size = ntohs(pipemhdr->pipem_len);
+	pipem_next = (char *)(pipemhdr +1);
+
+	do { /* make 1 table while there is peerinfo or else */
+
+		next_pipemle = (struct pipemle_hdr*)pipem_next;
+
+		switch (ntohs(next_pipemle->pipemle_type)) {
+		case PIPEM_PEERINFO:
+			/* PeerFound, PeerLost, PeerList */
+			peerinfo = (struct pipem_peerinfo *)next_pipemle;
+
+#if defined(linux) && defined(__KERNEL__)
+			printk(KERN_INFO "<%s>: PEER: 0x%x QUAL: %d.\n", __FUNCTION__, ntohs(peerinfo->pipemle_addr), ntohs(peerinfo->pipemle_qual));
+#else
+			printf("<%s>: PEER: 0x%x QUAL: %d.\n", __FUNCTION__, ntohs(peerinfo->pipemle_addr), ntohs(peerinfo->pipemle_qual));
+#endif
+
+			/* Add to the New-Peer-List */
+			lies_regist_new_peer_table(peerinfo);
+			break;
+		case PIPEM_CONNECTREQ:
+			/* NOT SUPPORTED */
+			break;
+		case PIPEM_DISCONNECTREQ:
+			/* NOT SUPPORTED */
+			break;
+		case PIPEM_CONNECTINFO:
+			/* LinkUp */
+			connectinfo = (struct pipem_connectinfo *)next_pipemle;
+			change.peer_addr = ntohs(connectinfo->pipemle_addr);
+
+			/* save current peer address */
+			current_peer = ntohs(connectinfo->pipemle_addr);
+
+#if defined(linux) && defined(__KERNEL__)
+			printk(KERN_INFO "<%s>: CONNECT TO PEER: 0x%x.\n", __FUNCTION__, ntohs(connectinfo->pipemle_addr));
+#else
+			printf("<%s>: CONNECT TO PEER: 0x%x.\n", __FUNCTION__, ntohs(connectinfo->pipemle_addr));
+#endif
+
+			/* make AEPP */
+			lies_make_indication(LINKUP, &change);
+			break;
+		case PIPEM_DISCONNECTINFO:
+			/* LinkDown */
+			disconnectinfo = (struct pipem_disconnectinfo *)next_pipemle;
+			change.peer_addr = ntohs(disconnectinfo->pipemle_addr);
+
+			/* remove current peer address */
+			if (current_peer == ntohs(disconnectinfo->pipemle_addr))
+				current_peer = 0;
+
+#if defined(linux) && defined(__KERNEL__)
+			printk(KERN_INFO "<%s>: DISCONNECT FROM PEER: 0x%x.\n", __FUNCTION__, ntohs(disconnectinfo->pipemle_addr));
+#else
+			printf("<%s>: DISCONNECT FROM PEER: 0x%x.\n", __FUNCTION__, ntohs(disconnectinfo->pipemle_addr));
+#endif
+			/* make AEPP */
+			lies_make_indication(LINKDOWN, &change);
+			break;
+		case PIPEM_SYNCINFO:
+			/* NOT SUPPORTED */
+			break;
+		case PIPEM_SCANREQ:
+			/* NOT SUPPORTED */
+			break;
+		default:
+			/* NOT SUPPORTED */
+			break;
+		}
+
+		size -= ntohs(next_pipemle->pipemle_len);
+		pipem_next += ntohs(next_pipemle->pipemle_len);
+	} while (size > 0);
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: PIPEM is parsed.\n", __FUNCTION__);
+#else
+	printf("<%s>: PIPEM is parced.\n", __FUNCTION__);
+#endif
+
+	/*
+	 * If new_peer_list is made,
+	 * 1. diff Current-Peer-List New-Peer-List > Peer-List.diff
+	 * 2. Compare Peer-List.diff and registered thresholds
+	 * 3. Make Current-Peer-List, Init New-Peer-List
+	 */
+	if (LIES_LIST_FIRST(&lies_new_peer_list) != NULL) {
+		/* make difference between new_peer_list and current peer_list */
+		lies_compare_peer_table();
+
+		/* compare threshold_table and make indication*/
+		lies_compare_threshold_table();
+
+		/* initialize new_peer_table and update current_peer_table */
+		lies_initialize_lists(LIST_NEW_PEER);
+	}
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: PIPEM is processed.\n", __FUNCTION__);
+#else
+	printf("<%s>: PIPEM is processed.\n", __FUNCTION__);
+#endif
+
+	return 0;
+}
+
+
+/* Regist Peer to New-Peer-Table */
+int
+lies_regist_new_peer_table(void *peerinfo)
+{
+	struct lies_table_new_peer *new_table_peer;
+
+	new_table_peer = lies_make_table_new_peer(peerinfo);
+	LIES_LIST_INSERT_HEAD(&lies_new_peer_list, new_table_peer, new_peer_field);
+
+	return 0;
+}
+
+/* Make 1 table of New-Peer-Table called by lies_regist_new_peer_table */
+struct lies_table_new_peer *
+lies_make_table_new_peer(struct pipem_peerinfo *peerinfo)
+{
+	struct timeval tp;
+	struct lies_table_new_peer *tablepeer;
+
+#if defined(linux) && defined(__KERNEL__)
+	tablepeer = (struct lies_table_new_peer *) kmalloc(sizeof(struct lies_table_new_peer), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	tablepeer = (struct lies_table_new_peer *) malloc(sizeof(struct lies_table_new_peer), M_TEMP, M_NOWAIT);
+#else
+	tablepeer = (struct lies_table_new_peer *) malloc(sizeof(struct lies_table_new_peer));
+#endif
+
+#if defined(linux) && defined(__KERNEL__)
+	do_gettimeofday(&tp);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	microtime(&tp);
+#else
+	gettimeofday(&tp, NULL);
+#endif
+
+	tablepeer->peer_time = tp;
+	tablepeer->peer_addr = ntohs(peerinfo->pipemle_addr);
+	tablepeer->peer_qual = ntohs(peerinfo->pipemle_qual);
+
+	return tablepeer;
+}
+
+/* compare current and new peer-table (then make diff list) */
+int 
+lies_compare_peer_table()
+{
+	struct lies_table_peer *peer;
+	struct lies_table_new_peer *new_peer;
+	int fbreak = 0;
+
+	/*
+	 * While loop for each New-Peer in New-Peer-List
+	 */
+	LIES_LIST_FOREACH(new_peer, &lies_new_peer_list, new_peer_field) {
+
+		/*
+		 * While loop for each Current-Peer in Current-Peer-List
+		 */
+		LIES_LIST_FOREACH(peer, &lies_peer_list, peer_field){
+
+			/* Compare Addresses of New-Peer and Current-Peer */
+			if(peer->peer_addr == new_peer->peer_addr){
+
+				/* diff Current-Peer-List New-Peer-List > Peer-List.diff */
+				lies_regist_peer_change(peer, new_peer);
+
+				lies_update_peer_table(new_peer);/* update new quality */
+				fbreak = 1;
+				break;
+			}
+		}
+
+		if(fbreak == 0){/* new_peer is entirely new */
+			struct lies_table_peer tmp_peer;
+
+			tmp_peer.peer_addr = new_peer->peer_addr;
+			tmp_peer.peer_qual = 0;
+			lies_regist_peer_change(&tmp_peer, new_peer);
+			lies_update_peer_table(new_peer); /* add new_peer to current peer_list */
+		}
+	}
+
+	/* remove timeout peer */
+	lies_timeout_peer();
+
+	return 0;
+}
+
+/* initialize LIES_LIST (all lists without request_list) */
+int
+lies_initialize_lists(int list_type){
+	struct lies_table_peer *peer_head;
+	struct lies_table_new_peer *new_peer_head;
+	struct lies_table_peer_change *change_head;
+	struct lies_table_peerfound *peerfound_head;
+	struct lies_table_peerlost *peerlost_head;
+	struct lies_table_threshold *threshold_head;
+
+	switch (list_type) {
+	case LIST_PEER:
+		LIES_LIST_FOREACH(peer_head, &lies_peer_list, peer_field){
+			LIES_LIST_REMOVE(peer_head, peer_field);
+#if defined(linux) && defined(__KERNEL__)
+			kfree(peer_head);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+			free(peer_head, M_TEMP);
+#else
+			free(peer_head);
+#endif
+		}
+		LIES_LIST_INIT(&lies_peer_list);
+		break;
+	case LIST_NEW_PEER:
+		LIES_LIST_FOREACH(new_peer_head, &lies_new_peer_list, new_peer_field){
+			LIES_LIST_REMOVE(new_peer_head, new_peer_field);
+#if defined(linux) && defined(__KERNEL__)
+			kfree(new_peer_head);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+			free(new_peer_head, M_TEMP);
+#else
+			free(new_peer_head);
+#endif
+		}
+		LIES_LIST_INIT(&lies_new_peer_list);
+		break;
+	case LIST_CHANGE:
+		LIES_LIST_FOREACH(change_head, &lies_peer_change_list, peer_change_field){
+			LIES_LIST_REMOVE(change_head, peer_change_field);
+#if defined(linux) && defined(__KERNEL__)
+			kfree(change_head);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+			free(change_head, M_TEMP);
+#else
+			free(change_head);
+#endif
+		}
+		LIES_LIST_INIT(&lies_peer_change_list);
+		break;
+	case LIST_PEERFOUND:
+		LIES_LIST_FOREACH(peerfound_head, &lies_peerfound_list, peerfound_field){
+			LIES_LIST_REMOVE(peerfound_head, peerfound_field);
+#if defined(linux) && defined(__KERNEL__)
+			kfree(peerfound_head);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+			free(peerfound_head, M_TEMP);
+#else
+			free(peerfound_head);
+#endif
+		}
+		LIES_LIST_INIT(&lies_peerfound_list);
+		break;
+	case LIST_PEERLOST:
+		LIES_LIST_FOREACH(peerlost_head, &lies_peerlost_list, peerlost_field){
+			LIES_LIST_REMOVE(peerlost_head, peerlost_field);
+#if defined(linux) && defined(__KERNEL__)
+			kfree(peerlost_head);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+			free(peerlost_head, M_TEMP);
+#else
+			free(peerlost_head);
+#endif
+		}
+		LIES_LIST_INIT(&lies_peerlost_list);
+		break;
+	case LIST_THRESHOLD:
+		LIES_LIST_FOREACH(threshold_head, &lies_threshold_list, threshold_field){
+			LIES_LIST_REMOVE(threshold_head, threshold_field);
+#if defined(linux) && defined(__KERNEL__)
+			kfree(threshold_head);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+			free(threshold_head, M_TEMP);
+#else
+			free(threshold_head);
+#endif
+		}
+		LIES_LIST_INIT(&lies_threshold_list);
+		break;
+	}
+	return 0;
+}
+
+
+/* 
+ * just register the changes of the peers to compare with request-table
+ * this peer's quality goes to ...
+ * diff Current-Peer-List New-Peer-List > Peer-List.diff
+ */
+int
+lies_regist_peer_change(struct lies_table_peer *peer, struct lies_table_new_peer *new_peer)
+{
+	struct lies_table_peer_change *peer_change;
+
+#if defined(linux) && defined(__KERNEL__)
+	peer_change = (struct lies_table_peer_change *)kmalloc(sizeof(struct lies_table_peer_change), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	peer_change = (struct lies_table_peer_change *)malloc(sizeof(struct lies_table_peer_change), M_TEMP, M_NOWAIT);
+#else
+	peer_change = (struct lies_table_peer_change *)malloc(sizeof(struct lies_table_peer_change));
+#endif
+
+	peer_change->peer_addr = new_peer->peer_addr;
+	peer_change->peer_qual_before = peer->peer_qual;
+	peer_change->peer_qual_after = new_peer->peer_qual;
+	LIES_LIST_INSERT_HEAD(&lies_peer_change_list, peer_change, peer_change_field);
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: PEER: 0x%x QUAL: %d -> %d.\n", __FUNCTION__, peer_change->peer_addr, peer_change->peer_qual_before, peer_change->peer_qual_after);
+#else
+	printf("<%s>: PEER: 0x%x QUAL: %d -> %d.\n", __FUNCTION__, peer_change->peer_addr, peer_change->peer_qual_before, peer_change->peer_qual_after);
+#endif
+
+	return 0;
+}
+
+/* compare with request-table and make aepp */
+int
+lies_compare_threshold_table(){
+	struct lies_table_peer_change *change;
+	struct lies_table_threshold *threshold;
+	struct lies_table_peerfound *peerfound;
+	struct lies_table_peerlost *peerlost;
+
+	/*
+	 * While loop for each Peer-List.diff
+	 */
+
+	LIES_LIST_FOREACH(change, &lies_peer_change_list, peer_change_field){
+
+		/*
+		 * While loop for each registered threshold
+		 */
+		LIES_LIST_FOREACH(threshold, &lies_threshold_list, threshold_field){
+
+			/* compare threshold for PeerFound */
+			if(change->peer_qual_before < change->peer_qual_after){
+				if((threshold->pri_type == PEERFOUND) && /* warning:KIMEUCHI! */
+				   (change->peer_qual_before <= GOOD) && (GOOD < change->peer_qual_after)){ /* PeerFound */
+					/* add to PeerFound List */
+#if defined(linux) && defined(__KERNEL__)
+					peerfound = (struct lies_table_peerfound *) kmalloc(sizeof(struct lies_table_peerfound), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+					peerfound = (struct lies_table_peerfound *) malloc(sizeof(struct lies_table_peerfound), M_TEMP, M_NOWAIT);
+#else
+					peerfound = (struct lies_table_peerfound *) malloc(sizeof(struct lies_table_peerfound));
+#endif
+					peerfound->peer_addr = change->peer_addr;
+					LIES_LIST_INSERT_HEAD(&lies_peerfound_list, peerfound, peerfound_field);
+				}
+			}
+			else if(change->peer_qual_before > change->peer_qual_after){
+				/* compare threshold for PeerLost */
+				if((threshold->pri_type == PEERLOST) && /* warning:KIMEUCHI! */
+				   (change->peer_qual_before >= FAIR)&& (FAIR > change->peer_qual_after)){/* PeerLost */
+					/* add to PeerLost List */
+#if defined(linux) && defined(__KERNEL__)
+					peerlost = (struct lies_table_peerlost *) kmalloc(sizeof(struct lies_table_peerlost), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+					peerlost = (struct lies_table_peerlost *) malloc(sizeof(struct lies_table_peerlost), M_TEMP, M_NOWAIT);
+#else
+					peerlost = (struct lies_table_peerlost *) malloc(sizeof(struct lies_table_peerlost));
+#endif
+
+					peerlost->peer_addr = change->peer_addr;
+					LIES_LIST_INSERT_HEAD(&lies_peerlost_list, peerlost, peerlost_field);
+				}
+				/* compare threshold for LinkToBeDown */
+				else if((threshold->pri_type == LINKTOBEDOWN) && /* warning:KIMEUCHI! */
+					(change->peer_addr == current_peer) &&
+					(change->peer_qual_before >= GOOD) && (GOOD > change->peer_qual_after)){ /* LinkTobeDown */
+					lies_make_indication(threshold->pri_type,change); 
+				}
+			}
+		}
+	}
+
+	/*
+	 * Make INDICATION and Init List
+	 */
+	if(LIES_LIST_FIRST(&lies_peerfound_list) != NULL){
+		lies_make_indication(PEERFOUND,change);/* PeerFound */
+		lies_initialize_lists(LIST_PEERFOUND);
+	}
+	else if(LIES_LIST_FIRST(&lies_peerlost_list) != NULL){
+		lies_make_indication(PEERLOST,change); /* PeerLost*/
+		lies_initialize_lists(LIST_PEERLOST);
+	}	
+
+	lies_initialize_lists(LIST_CHANGE);
+	return 0;
+}
+
+/*
+ * Make INDICATION
+ * (fill parameters without target)
+ */
+int 
+lies_make_indication(int pri_type, struct lies_table_peer_change *change)
+{
+	struct aepp_hdr *hdr;
+	//struct aepple_hdr *l2_hdr;
+	//struct aepp_ifid *ifid;
+	//struct aepp_iftype *iftype;
+	char *aepp_ind;
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: Make INDICATON.\n", __FUNCTION__);
+#else
+	printf("<%s>: Make INDICATON.\n", __FUNCTION__);
+#endif
+
+#if defined(linux) && defined(__KERNEL__)
+	aepp_ind = kmalloc(AEPP_MAXSIZE, GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	aepp_ind = malloc(AEPP_MAXSIZE, M_TEMP, M_NOWAIT);
+#else
+	aepp_ind = malloc(AEPP_MAXSIZE);
+#endif
+
+	hdr = (struct aepp_hdr *)aepp_ind;
+
+	switch(pri_type){
+	case PEERFOUND:
+		lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2, AEPP_CLASS_IND, 0, 0, 0, 0, 0, AEPP_TYPE_PEERFOUND, 0);
+		break;
+	case PEERLOST:
+		lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2, AEPP_CLASS_IND, 0, 0, 0, 0, 0, AEPP_TYPE_PEERLOST, 0);
+		break;
+	case LINKUP:
+		lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2, AEPP_CLASS_IND, 0, 0, 0, 0, 0, AEPP_TYPE_LINKUP, 0);
+		break;
+	case LINKDOWN:
+		lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2, AEPP_CLASS_IND, 0, 0, 0, 0, 0, AEPP_TYPE_LINKDOWN, 0);
+		break;
+	case LINKTOBEDOWN:
+		lies_aepp_set_hdr(hdr, AEPP_VERSION, AEPP_LAYER2, AEPP_CLASS_IND, 0, 0, 0, 0, 0, AEPP_TYPE_LINKTOBEDOWN, 0);
+		break;
+	}
+
+	/*
+	 * make aepp
+	 * pass indication to lies_l2_aepp_input@lies_l2.c
+	 */
+	lies_l2_aepp_input(aepp_ind);
+
+	/*
+	 * Free each INDICATION
+	 */
+#if defined(linux) && defined(__KERNEL__)
+	kfree(aepp_ind);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	free(aepp_ind, M_TEMP);
+#else
+	free(aepp_ind);
+#endif
+
+	return 0;
+}
+
+
+/* update/add current peer-table */ 
+int
+lies_update_peer_table(struct lies_table_new_peer *new_peer)
+{
+	struct lies_table_peer *var;
+	int fbreak = 0;
+
+	LIES_LIST_FOREACH(var, &lies_peer_list, peer_field){
+		if(var->peer_addr == new_peer->peer_addr){
+			/* update the quality and the time */
+			var->peer_qual = new_peer->peer_qual;
+			var->peer_time.tv_sec = new_peer->peer_time.tv_sec;
+			var->peer_time.tv_usec = new_peer->peer_time.tv_usec;
+			fbreak = 1;
+			break;
+		}
+	}
+
+	/* 
+	 * new_peer is certainly new peer 
+	 * so add new_peer to current peer_list 
+	 */
+	if(fbreak == 0){
+#if defined(linux) && defined(__KERNEL__)
+		printk(KERN_INFO "<%s>: New Peer 0x%x Appeared.\n", __FUNCTION__, new_peer->peer_addr);
+#else
+		printf("<%s>: New Peer 0x%x Appeared.\n", __FUNCTION__, new_peer->peer_addr);
+#endif
+
+#if defined(linux) && defined(__KERNEL__)
+		var = (struct lies_table_peer*)kmalloc(sizeof(struct lies_table_peer), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+		var = (struct lies_table_peer*)malloc(sizeof(struct lies_table_peer), M_TEMP, M_NOWAIT);
+#else
+		var = (struct lies_table_peer*)malloc(sizeof(struct lies_table_peer));
+#endif
+		var->peer_qual = new_peer->peer_qual;
+		var->peer_addr = new_peer->peer_addr;
+		var->peer_time.tv_sec = new_peer->peer_time.tv_sec;
+		var->peer_time.tv_usec = new_peer->peer_time.tv_usec;
+		LIES_LIST_INSERT_HEAD(&lies_peer_list, var, peer_field);
+	}
+	return 0;
+}
+
+/* remove timeout peer */
+int
+lies_timeout_peer(void){
+	/* remove timeout peers (the list is already updated) */
+	struct timeval  tp;
+	struct lies_table_peer *var;
+	struct lies_table_threshold *threshold;
+	struct lies_table_peerlost *peerlost;
+
+#if defined(linux) && defined(__KERNEL__)
+	do_gettimeofday(&tp);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	microtime(&tp);
+#else
+	gettimeofday(&tp, NULL);
+#endif
+	LIES_LIST_FOREACH(var, &lies_peer_list, peer_field){
+		if(((tp.tv_sec) - (var->peer_time.tv_sec)) > TIMEOUT){
+#if defined(linux) && defined(__KERNEL__)
+			printk(KERN_INFO "<%s>: Peer 0x%x  is timeout.\n", __FUNCTION__, var->peer_addr);
+#else
+			printf("<%s>: Peer 0x%x  is timeout.\n", __FUNCTION__, var->peer_addr);
+#endif
+			/* remove timeout peer from current peer-table */
+			LIES_LIST_REMOVE(var, peer_field);
+			
+			/* then make peerlost indication if request exist in threshold_list */
+			LIES_LIST_FOREACH(threshold, &lies_threshold_list, threshold_field){
+				if(threshold->pri_type == PEERLOST){
+					/* add to PeerLost List */
+#if defined(linux) && defined(__KERNEL__)
+                                        peerlost = (struct lies_table_peerlost *) kmalloc(sizeof(struct lies_table_peerlost), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+                                        peerlost = (struct lies_table_peerlost *) malloc(sizeof(struct lies_table_peerlost), M_TEMP, M_NOWAIT);
+#else
+                                        peerlost = (struct lies_table_peerlost *) malloc(sizeof(struct lies_table_peerlost));
+#endif
+                                        peerlost->peer_addr = var->peer_addr;
+                                        LIES_LIST_INSERT_HEAD(&lies_peerlost_list, peerlost, peerlost_field);
+					break;
+				}
+			}
+		}
+	}
+	return 0;
+}
+
+/* regist requested threshold to device driver */
+int
+lies_regist_threshold(u_int type){
+	
+	struct lies_table_threshold *table_threshold;
+#if defined(linux) && defined(__KERNEL__)
+	table_threshold = (struct lies_table_threshold *)kmalloc(sizeof(struct lies_table_threshold), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	table_threshold = (struct lies_table_threshold *)malloc(sizeof(struct lies_table_threshold), M_TEMP, M_NOWAIT);
+#else
+	table_threshold = (struct lies_table_threshold *)malloc(sizeof(struct lies_table_threshold));
+#endif
+	/* tell emu.device condition quality */
+	table_threshold->pri_type = type;
+	LIES_LIST_INSERT_HEAD(&lies_threshold_list, table_threshold, threshold_field);
+
+	return 0;
+}
+
+/* remove requested threshold(like LINKUP) from threshold_list */
+int
+lies_remove_threshold(u_int type){
+	struct lies_table_threshold *var;
+	
+	LIES_LIST_FOREACH(var, &lies_threshold_list, threshold_field){
+		if(var->pri_type == type){
+			LIES_LIST_REMOVE(var, threshold_field);
+		}
+	}
+	return 0;
+}
+
+char *
+lies_get_emu_peerlist()
+{
+	char *peerlist;
+	int peer_count = 0;
+	struct lies_table_peer *peer;
+	struct aepp_peerlist_hdr *peerlist_hdr;
+	struct aepp_peerlist_le *peerlist_le_next;
+
+	peer = NULL;	/* XXX */
+
+	/* malloc MAX size of peerlist */
+#if defined(linux) && defined(__KERNEL__)
+	peerlist = kmalloc(PIPEM_MAXSIZE, GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	peerlist = malloc(PIPEM_MAXSIZE, M_TEMP, M_NOWAIT);
+#else
+	peerlist = malloc(PIPEM_MAXSIZE);
+#endif	
+
+	peerlist_hdr = (struct aepp_peerlist_hdr *)peerlist;
+	/* fill in peerlist_hdr */
+	peerlist_hdr->aepple_type = AEPP_PARAM_TYPE_PEERLIST; /* len is lator */
+	
+	peerlist_le_next = (struct aepp_peerlist_le *)(peerlist_hdr +1);
+
+	/* make peerlist from lies_table_peer */
+	while(LIES_LIST_NEXT(peer, peer_field) != NULL){
+
+		/* fill in peerlist_le from emulator's peelist */
+		lies_emu_convert_peerlist(peerlist_le_next, peer);
+
+		peer_count ++;
+		peerlist_le_next = (struct aepp_peerlist_le *)(peerlist_le_next +1);
+	}
+
+	peerlist_hdr->aepple_len = (peer_count) * (sizeof(struct aepp_peerlist_le));
+	peerlist = (char *)peerlist_hdr;
+	return peerlist;
+}
+
+/* convert emulator's peerlist into aepp_peerlist */
+int
+lies_emu_convert_peerlist(struct aepp_peerlist_le *peerlist_le, struct lies_table_peer *peer)
+{
+	peerlist_le->aepple_attid[AEPP_IDSIZE-1] = (u_char) peer->peer_addr;
+	peerlist_le->aepple_qual = peer->peer_qual;
+
+	return 0;
+}
+
+/*
+ * Send Physical Information Packet to Ethernet
+ */
+int
+lies_emu_send_linkconnect(aepp_req)
+	void *aepp_req;
+{
+#if 0
+	struct aepp_hdr *hdr;
+        struct aepp_ifid *ifid;
+        struct aepp_iftype *iftype;
+#if defined(linux) && defined(__KERNEL__)
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	int ifindex;
+	struct ifnet *ifp;
+	struct mbuf *m;
+	struct sockaddr sa;
+	struct pipem_hdr *pipemhdr;		/* XXX will also be used in LINUX? */
+	struct pipem_connectreq *connectreq;	/* XXX will also be used in LINUX? */
+#endif
+
+	/*
+	 * XXX we assume AEPP is constracted into the following order
+	 * 1. AEPP header
+	 * 2. IFTYPE
+	 * 3. IFID
+	 * 4. and so on...
+	 */
+	hdr = (struct aepp_hdr *)aepp_req;
+        ifid = (struct aepp_ifid *)(hdr + 1);
+        iftype = (struct aepp_iftype *)(ifid + 1);
+
+#if defined(linux) && defined(__KERNEL__)
+	/* XXX ToBeWritten */
+	return -1;
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+#if 0
+	switch (ifid->aepple_arch) {
+	case AEPP_PARAM_ARCH_MAC:
+		/* XXX Not Supported yet... */
+		return -1;
+	case AEPP_PARAM_ARCH_SSID:
+		/* Not Supported */
+		return -1;
+	case AEPP_PARAM_ARCH_IFNAME:
+		/* rezolve ifindex from ifname */
+		ifindex = if_nametoindex(ifid->aepple_ifid);
+		ifp = ifnet_byindex(ifindex);
+		break;
+	default:
+		/* Not Supported */
+		return -1;
+	}
+
+	/* See ether_output and arprequest */
+
+	/* Make Physical Information Packet frame */
+	m = m_gethdr(M_DONTWAIT, MT_DATA);
+	if (m == NULL)
+		return;
+	m->m_len = sizeof(struct pipem_hdr) + sizeof(struct pipem_connectreq);
+	m->m_pkthdr.len = m->m_len;
+	MH_ALIGN(m, m->m_len);
+
+	pipemhdr = mtod(m, struct pipem_hdr *);
+	memset(pipemhdr, 0, sizeof(struct pipem_hdr));
+	/* XXX FILL BUFFER */
+
+	connectreq = (struct pipem_connectreq *)(pipemhdr + 1);
+	memset(connectreq, 0, sizeof(struct pipem_connectreq));
+	/* XXX FILL BUFFER */
+
+	sa.sa_family = AF_LIES;	/* XXX really need this? */
+	sa.sa_len = 2;  /* XXX why 2? */
+	m->m_flags |= M_BCAST;
+
+	/* Send Physical Information Packet frame to the Ethernet */
+	(*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0);
+#endif /* test */
+#endif
+#endif
+	return 0;
+}
+
+int
+lies_emu_send_linkdisconnect(aepp_req)
+	void *aepp_req;
+{
+	/* XXX make LIES frame */
+
+	/* XXX call OS dependent code for sending LIES frame */
+
+	return 0;
+}
+
+#endif /* LIES */
diff -u -r -N kame/kame/sys/lies/lies_l2.c kame-lies/kame/sys/lies/lies_l2.c
--- kame/kame/sys/lies/lies_l2.c	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_l2.c	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,1124 @@
+#ifdef LIESTEST
+#include <stdio.h>
+#include "lies_aepp.h"
+#include "lies_l2.h"
+#include "lies.h"
+
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+
+#include "opt_lies.h"
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/malloc.h>
+#include <sys/event.h>
+#include <sys/selinfo.h>
+#include <lies/lies_aepp.h>
+#include <lies/lies_l2.h>
+#include <lies/lies.h>
+#include <lies/lies_osdep.h>
+
+#if __FreeBSD_version >= 500000
+#include <sys/systm.h>
+#ifdef LIES_80211
+#include <lies/lies_80211.h>
+#endif
+#endif
+
+#elif defined(linux)
+
+#include "lies_aepp.h"
+#include "lies_l2.h"
+#include "lies.h"
+#ifdef __KERNEL__
+#include <linux/param.h>
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/slab.h>
+#else
+#include <sys/param.h>
+#endif /* __KERNEL__ */
+
+#endif
+
+int lies_l2_aepp_peerlist_request(void *, void *);
+int lies_l2_aepp_peerfound_request(void *, void *);
+int lies_l2_aepp_peerlost_request(void *, void *);
+int lies_l2_aepp_linkup_request(void *, void *);
+int lies_l2_aepp_linkdown_request(void *, void *);
+int lies_l2_aepp_linktobedown_request(void *, void *);
+int lies_l2_aepp_linkstatus_request(void *, void *);
+int lies_l2_aepp_linkconnect_request(void *, void *);
+int lies_l2_aepp_linkdisconnect_request(void *, void *);
+
+int lies_l2_aepp_peerlist_confirm(void *, void *);
+int lies_l2_aepp_peerfound_confirm(void *, void *);
+int lies_l2_aepp_peerlost_confirm(void *, void *);
+int lies_l2_aepp_linkup_confirm(void *, void *);
+int lies_l2_aepp_linkdown_confirm(void *, void *);
+int lies_l2_aepp_linktobedown_confirm(void *, void *);
+int lies_l2_aepp_linkstatus_confirm(void *, void *);
+int lies_l2_aepp_linkconnect_confirm(void *, void *);
+int lies_l2_aepp_linkdisconnect_confirm(void *, void *);
+
+int lies_l2_aepp_peerfound_indication(void *);
+int lies_l2_aepp_peerlost_indication(void *);
+int lies_l2_aepp_linkup_indication(void *);
+int lies_l2_aepp_linkdown_indication(void *);
+int lies_l2_aepp_linktobedown_indication(void *);
+
+int lies_l2_aepp_indication(void *);
+
+int lies_l2_register_reqtype(void *, void *);
+int lies_l2_register_request (void *, void *);
+
+int lies_register_ether_reqtype(struct aepp_hdr *);
+#ifdef LIES_80211
+int lies_register_80211_reqtype(struct aepp_hdr *);
+#endif
+
+
+struct lies_table_req * lies_make_table_req(void *);
+
+#ifdef LIES
+
+LIES_LIST_HEAD(lies_req_list, lies_table_req) lies_req_list;
+
+/*
+ * dispatch L2 protocol/abstract entity processor
+ */
+int
+lies_l2_dispatcher(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+	struct aepp_hdr *hdr;
+
+	hdr = (struct aepp_hdr *)aepp_req;
+
+	if(hdr->aepp_class == AEPP_CLASS_REQ) {
+		switch(hdr->aepp_type) {
+		case AEPP_TYPE_PEERLIST:
+			lies_l2_aepp_peerlist_request(aepp_req, aepp_cnf);
+			break;
+
+		case AEPP_TYPE_PEERFOUND:
+			lies_l2_aepp_peerfound_request(aepp_req, aepp_cnf);
+			break;
+
+		case AEPP_TYPE_PEERLOST:
+			lies_l2_aepp_peerlost_request(aepp_req, aepp_cnf);
+			break;
+
+		case AEPP_TYPE_LINKUP:
+			lies_l2_aepp_linkup_request(aepp_req, aepp_cnf);
+			break;
+
+		case AEPP_TYPE_LINKDOWN:
+			lies_l2_aepp_linkdown_request(aepp_req, aepp_cnf);
+			break;
+
+		case AEPP_TYPE_LINKTOBEDOWN:
+			lies_l2_aepp_linktobedown_request(aepp_req, aepp_cnf);
+			break;
+
+		case AEPP_TYPE_LINKSTATUS:
+			lies_l2_aepp_linkstatus_request(aepp_req, aepp_cnf);
+			break;
+
+		case AEPP_TYPE_LINKCONNECT:
+			lies_l2_aepp_linkconnect_request(aepp_req, aepp_cnf);
+			break;
+
+		case AEPP_TYPE_LINKDISCONNECT:
+			lies_l2_aepp_linkdisconnect_request(aepp_req, aepp_cnf);
+			break;
+
+		default:
+#if defined(linux) && defined(__KERNEL__)
+			printk(KERN_INFO "%s:%d:%s: Unknown AEPP type 0x%x.\n", __FILE__, __LINE__, __FUNCTION__, hdr->aepp_type);
+#else
+			printf("%s:%d:%s: Unknown AEPP type 0x%x.\n", __FILE__, __LINE__, __FUNCTION__, hdr->aepp_type);
+#endif
+			break;
+		}
+	}
+
+	return 0;
+}
+
+/* PeerList Request */
+int
+lies_l2_aepp_peerlist_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: PeerList Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: PeerList Request.\n", __FUNCTION__);
+#endif
+
+	/* make comfirm */
+	lies_l2_aepp_peerlist_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/* PeerFound Request */
+int
+lies_l2_aepp_peerfound_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: PeerFound Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: PeerFound Request.\n", __FUNCTION__);
+#endif
+
+	/* register indication to device driver, and recieve confirm */
+	lies_l2_register_reqtype(aepp_req, aepp_cnf);
+
+	/* register request to request table */
+	lies_l2_register_request(aepp_req, aepp_cnf);
+
+	/* make comfirm */
+	lies_l2_aepp_peerfound_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/* PeerLost Request */
+int
+lies_l2_aepp_peerlost_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: PeerLost Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: PeerLost Request.\n", __FUNCTION__);
+#endif
+
+	/* register indication to device driver, and recieve confirm */
+	lies_l2_register_reqtype(aepp_req, aepp_cnf);
+
+	/* register request to request table */
+	lies_l2_register_request(aepp_req, aepp_cnf);
+
+	/* make comfirm */
+	lies_l2_aepp_peerlost_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/* LinkUp Request */
+int
+lies_l2_aepp_linkup_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: LinkUp Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: LinkUp Request.\n", __FUNCTION__);
+#endif
+
+	/* register indication to device driver, and recieve confirm */
+	lies_l2_register_reqtype(aepp_req, aepp_cnf);
+
+	/* register request to request table */
+	lies_l2_register_request(aepp_req, aepp_cnf);
+
+	/* make comfirm */
+	lies_l2_aepp_linkup_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/* LinkDown Request */
+int
+lies_l2_aepp_linkdown_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: LinkDown Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: LinkDown Request.\n", __FUNCTION__);
+#endif
+
+	/* register indication to device driver, and recieve confirm */
+	lies_l2_register_reqtype(aepp_req, aepp_cnf);
+
+	/* register request to request table */
+	lies_l2_register_request(aepp_req, aepp_cnf);
+
+	/* make comfirm */
+	lies_l2_aepp_linkdown_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/* LinkToBeDown Request */
+int
+lies_l2_aepp_linktobedown_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: LinkToBeDown Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: LinkToBeDown Request.\n", __FUNCTION__);
+#endif
+
+	/* register indication to device driver, and recieve confirm */
+	lies_l2_register_reqtype(aepp_req, aepp_cnf);
+
+	/* register request to request table */
+	lies_l2_register_request(aepp_req, aepp_cnf);
+
+	/* make comfirm */
+	lies_l2_aepp_linktobedown_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/* LinkStatus Request */
+int
+lies_l2_aepp_linkstatus_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: LinkStatus Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: LinkStatus Request.\n", __FUNCTION__);
+#endif
+
+	/* XXX get link status */
+
+	/* make comfirm */
+	lies_l2_aepp_linkstatus_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/* LinkConnect Request */
+int
+lies_l2_aepp_linkconnect_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+	int error;
+	struct aepp_hdr *hdr;
+	struct aepp_ifid *ifid;
+	struct aepp_iftype *iftype;
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: LinkConnect Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: LinkConnect Request.\n", __FUNCTION__);
+#endif
+
+	hdr = (struct aepp_hdr *)aepp_req;
+
+	ifid = (struct aepp_ifid *)(hdr + 1);
+	iftype = (struct aepp_iftype *)(ifid + 1);
+
+	/* do connect */
+	if(iftype->aepple_iftype == AEPP_PARAM_IF_EMULATOR){
+		error = lies_emu_send_linkconnect(aepp_req);
+	}
+	else if(iftype->aepple_iftype == AEPP_PARAM_IF_ETHER){
+		/* YU-SEN */
+	}
+#ifdef LIES_80211
+	else if(iftype->aepple_iftype == AEPP_PARAM_IF_IEEE80211){
+		/* MU-SEN */
+		error = lies_80211_linkconnect(aepp_req);
+	}
+#endif
+
+	/* make comfirm */
+	lies_l2_aepp_linkconnect_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/* LinkDisconnect Request */
+int
+lies_l2_aepp_linkdisconnect_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+	int error;
+	struct aepp_hdr *hdr;
+	struct aepp_ifid *ifid;
+	struct aepp_iftype *iftype;
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: LinkDisconnect Request.\n", __FUNCTION__);
+#else
+	printf("<%s>: LinkDisconnect Request.\n", __FUNCTION__);
+#endif
+
+	hdr = (struct aepp_hdr *)aepp_req;
+
+	ifid = (struct aepp_ifid *)(hdr + 1);
+	iftype = (struct aepp_iftype *)(ifid + 1);
+
+	/* do disconnect */
+	if(iftype->aepple_iftype == AEPP_PARAM_IF_EMULATOR){
+		error = lies_emu_send_linkdisconnect(aepp_req);
+	}
+	else if(iftype->aepple_iftype == AEPP_PARAM_IF_ETHER){
+		/* YU-SEN */
+	} else {
+		/* MU-SEN */
+		//wireless_disconnect();
+	}
+
+	/* make comfirm */
+	lies_l2_aepp_linkdisconnect_confirm(aepp_req, aepp_cnf);
+
+	return 0;
+}
+
+/*
+ * Make CONFIRM
+ */
+int
+lies_l2_aepp_peerlist_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+	struct aepp_hdr *rhdr = (struct aepp_hdr *)aepp_req;
+	struct aepp_hdr *chdr = (struct aepp_hdr *)aepp_cnf;
+	struct aepp_ifid *rifid, *cifid;
+	struct aepp_iftype *riftype,*ciftype;
+	struct aepp_peerlist_hdr *peerlist;
+
+	char /**peerlist,*/ *peerlist_tmp;    /* buffers for peerlist */
+	struct aepp_peerlist_hdr *peerlist_hdr;
+	int peerlist_size=0;
+
+	int count;
+
+	/* aepp payload length */
+	count = 0;
+
+	/* Set aepp ifid  */
+	rifid = (struct aepp_ifid *)(rhdr + 1);
+	cifid = (struct aepp_ifid *)(chdr + 1);
+	lies_aepp_set_ifid(cifid, rifid->aepple_arch, rifid->aepple_ifid);
+	count += cifid->aepple_len;
+
+	/* Set aepp iftype */
+	riftype = (struct aepp_iftype *)(rifid + 1);
+	ciftype = (struct aepp_iftype *)(cifid + 1);
+	lies_aepp_set_iftype(ciftype, riftype->aepple_iftype);
+        count += ciftype->aepple_len;
+
+	/* Set aepp peerlist */
+	peerlist = (struct aepp_peerlist_hdr *)(ciftype + 1);
+
+	/* get PeerList */
+	if(riftype->aepple_iftype == AEPP_PARAM_IF_EMULATOR){
+		peerlist_tmp = lies_get_emu_peerlist(); /* peerlist_tmp is allocated in lies_get_emu_peerlist(). need free!! */
+		peerlist_hdr = (struct aepp_peerlist_hdr *)peerlist_tmp;
+		peerlist_size = peerlist_hdr->aepple_len + sizeof(struct aepp_peerlist_hdr);
+		count += peerlist_size;
+		memcpy(peerlist, peerlist_tmp, peerlist_size);
+	}
+	else if(riftype->aepple_iftype == AEPP_PARAM_IF_ETHER){
+		/* YU-SEN */
+	}
+#ifdef LIES_80211
+	else if(riftype->aepple_iftype == AEPP_PARAM_IF_IEEE80211){
+		/* MU-SEN */
+		lies_80211_get_peerlist(aepp_req, (void *)peerlist);
+		count += peerlist->aepple_len + sizeof(struct aepp_peerlist_hdr);
+	}
+#endif
+
+	/* Set aepp header */
+	lies_aepp_set_hdr(chdr, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF
+			  , 0, AEPP_CNF_ACK, 0, rhdr->aepp_tgtype
+			  , rhdr->aepp_tgid, AEPP_TYPE_PEERLIST, count);
+
+	return 0;
+}
+
+int
+lies_l2_aepp_peerfound_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+        struct aepp_hdr *rhdr = (struct aepp_hdr *)aepp_req;
+        struct aepp_hdr *chdr = (struct aepp_hdr *)aepp_cnf;
+        struct aepp_ifid *rifid, *cifid;
+        struct aepp_iftype *riftype,*ciftype;
+        int count;
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Set aepp ifid  */
+        rifid = (struct aepp_ifid *)(rhdr + 1);
+        cifid = (struct aepp_ifid *)(chdr + 1);
+        lies_aepp_set_ifid(cifid, rifid->aepple_arch, rifid->aepple_ifid);
+        count += cifid->aepple_len;
+
+        /* Set aepp iftype */
+        riftype = (struct aepp_iftype *)(rifid + 1);
+        ciftype = (struct aepp_iftype *)(cifid + 1);
+        lies_aepp_set_iftype(ciftype, riftype->aepple_iftype);
+        count += ciftype->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(chdr, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF
+                          , 0, AEPP_CNF_ACK, 0, rhdr->aepp_tgtype
+                          , rhdr->aepp_tgid, AEPP_TYPE_PEERFOUND, count);
+
+        return 0;
+}
+
+int
+lies_l2_aepp_peerlost_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+        struct aepp_hdr *rhdr = (struct aepp_hdr *)aepp_req;
+        struct aepp_hdr *chdr = (struct aepp_hdr *)aepp_cnf;
+        struct aepp_ifid *rifid, *cifid;
+        struct aepp_iftype *riftype,*ciftype;
+        int count;
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Set aepp ifid  */
+        rifid = (struct aepp_ifid *)(rhdr + 1);
+        cifid = (struct aepp_ifid *)(chdr + 1);
+        lies_aepp_set_ifid(cifid, rifid->aepple_arch, rifid->aepple_ifid);
+        count += cifid->aepple_len;
+
+        /* Set aepp iftype */
+        riftype = (struct aepp_iftype *)(rifid + 1);
+        ciftype = (struct aepp_iftype *)(cifid + 1);
+        lies_aepp_set_iftype(ciftype, riftype->aepple_iftype);
+        count += ciftype->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(chdr, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF
+                          , 0, AEPP_CNF_ACK, 0, rhdr->aepp_tgtype
+                          , rhdr->aepp_tgid, AEPP_TYPE_PEERLOST, count);
+
+        return 0;
+}
+
+int
+lies_l2_aepp_linkup_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+        struct aepp_hdr *rhdr = (struct aepp_hdr *)aepp_req;
+        struct aepp_hdr *chdr = (struct aepp_hdr *)aepp_cnf;
+        struct aepp_ifid *rifid, *cifid;
+        struct aepp_iftype *riftype,*ciftype;
+        int count;
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Set aepp ifid  */
+        rifid = (struct aepp_ifid *)(rhdr + 1);
+        cifid = (struct aepp_ifid *)(chdr + 1);
+        lies_aepp_set_ifid(cifid, rifid->aepple_arch, rifid->aepple_ifid);
+        count += cifid->aepple_len;
+
+        /* Set aepp iftype */
+        riftype = (struct aepp_iftype *)(rifid + 1);
+        ciftype = (struct aepp_iftype *)(cifid + 1);
+        lies_aepp_set_iftype(ciftype, riftype->aepple_iftype);
+        count += ciftype->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(chdr, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF
+                          , 0, AEPP_CNF_ACK, 0, rhdr->aepp_tgtype
+                          , rhdr->aepp_tgid, AEPP_TYPE_LINKUP, count);
+
+        return 0;
+}
+
+int
+lies_l2_aepp_linkdown_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+        struct aepp_hdr *rhdr = (struct aepp_hdr *)aepp_req;
+        struct aepp_hdr *chdr = (struct aepp_hdr *)aepp_cnf;
+        struct aepp_ifid *rifid, *cifid;
+        struct aepp_iftype *riftype,*ciftype;
+        int count;
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Set aepp ifid  */
+        rifid = (struct aepp_ifid *)(rhdr + 1);
+        cifid = (struct aepp_ifid *)(chdr + 1);
+        lies_aepp_set_ifid(cifid, rifid->aepple_arch, rifid->aepple_ifid);
+        count += cifid->aepple_len;
+
+        /* Set aepp iftype */
+        riftype = (struct aepp_iftype *)(rifid + 1);
+        ciftype = (struct aepp_iftype *)(cifid + 1);
+        lies_aepp_set_iftype(ciftype, riftype->aepple_iftype);
+        count += ciftype->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(chdr, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF
+                          , 0, AEPP_CNF_ACK, 0, rhdr->aepp_tgtype
+                          , rhdr->aepp_tgid, AEPP_TYPE_LINKDOWN, count);
+
+        return 0;
+}
+
+int
+lies_l2_aepp_linktobedown_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+        struct aepp_hdr *rhdr = (struct aepp_hdr *)aepp_req;
+        struct aepp_hdr *chdr = (struct aepp_hdr *)aepp_cnf;
+        struct aepp_ifid *rifid, *cifid;
+        struct aepp_iftype *riftype,*ciftype;
+        int count;
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Set aepp ifid  */
+        rifid = (struct aepp_ifid *)(rhdr + 1);
+        cifid = (struct aepp_ifid *)(chdr + 1);
+        lies_aepp_set_ifid(cifid, rifid->aepple_arch, rifid->aepple_ifid);
+        count += cifid->aepple_len;
+
+        /* Set aepp iftype */
+        riftype = (struct aepp_iftype *)(rifid + 1);
+        ciftype = (struct aepp_iftype *)(cifid + 1);
+        lies_aepp_set_iftype(ciftype, riftype->aepple_iftype);
+        count += ciftype->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(chdr, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF
+                          , 0, AEPP_CNF_ACK, 0, rhdr->aepp_tgtype
+                          , rhdr->aepp_tgid, AEPP_TYPE_LINKTOBEDOWN, count);
+
+        return 0;
+}
+
+int
+lies_l2_aepp_linkstatus_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+	/* Header Template */
+	lies_aepp_set_hdr(aepp_cnf, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF, 0, 1, 0, ((struct aepp_hdr *)aepp_cnf)->aepp_tgtype, ((struct aepp_hdr *)aepp_cnf)->aepp_tgid, AEPP_TYPE_LINKSTATUS, AEPP_HDRSIZE);
+
+#if 0
+        char *cnf, *cnfp;       /* buffers for confirm message */ 
+        char  *next_aepple;               /* aepple pointer */
+        struct aepple_hdr *le_hdr;
+        struct aepp_ifid *ifid;
+        struct aepp_iftype *iftype;
+	struct aepp_iftypeopt *iftypeopt;
+	struct aepp_ifrate *ifrate;
+	struct aepp_security *security;
+	struct aepp_condition *condition;
+	struct aepp_peer *peer;
+
+        /* initiation */
+        le_hdr = (struct aepple_hdr *) aepple;
+        next_aepple = aepple;
+#if defined(linux) && defined(__KERNEL__)
+        cnf = kmalloc(AEPP_HDRSIZE + 
+		     sizeof(struct aepp_ifid) + 
+		     sizeof(struct aepp_iftype) + 
+		     sizeof(struct aepp_iftypeopt) + 
+		     sizeof(struct aepp_ifrate) + 
+		     sizeof(struct aepp_security) + 
+		     sizeof(struct aepp_condition) + 
+		     sizeof(struct aepp_peer), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+        cnf = malloc(AEPP_HDRSIZE + 
+		     sizeof(struct aepp_ifid) + 
+		     sizeof(struct aepp_iftype) + 
+		     sizeof(struct aepp_iftypeopt) + 
+		     sizeof(struct aepp_ifrate) + 
+		     sizeof(struct aepp_security) + 
+		     sizeof(struct aepp_condition) + 
+		     sizeof(struct aepp_peer), M_TEMP, M_NOWAIT);
+#else
+        cnf = malloc(AEPP_HDRSIZE + 
+		     sizeof(struct aepp_ifid) + 
+		     sizeof(struct aepp_iftype) + 
+		     sizeof(struct aepp_iftypeopt) + 
+		     sizeof(struct aepp_ifrate) + 
+		     sizeof(struct aepp_security) + 
+		     sizeof(struct aepp_condition) + 
+		     sizeof(struct aepp_peer));
+#endif
+        memset(cnf, 0, sizeof(cnf));       
+        cnfp = cnf + sizeof(struct aepp_hdr);
+        
+        /* copy ifid to confirm message buffer */
+        if(le_hdr->aepple_type == AEPP_PARAM_TYPE_IFID){
+                ifid = (struct aepp_ifid *) next_aepple;
+        }
+        memcpy(cnfp, ifid, le_hdr->aepple_len);
+        cnfp += le_hdr->aepple_len;
+        next_aepple += le_hdr->aepple_len;
+        le_hdr = (struct aepple_hdr *)next_aepple;
+        
+        /* copy iftype to confirm message buffer */
+        if(le_hdr->aepple_type == AEPP_PARAM_TYPE_IFTYPE){
+                iftype = (struct aepp_iftype *) next_aepple;
+        }
+        memcpy(cnfp, iftype, le_hdr->aepple_len);
+	cnfp += le_hdr->aepple_len;
+	next_aepple += le_hdr->aepple_len;
+	le_hdr = (struct aepple_hdr *)next_aepple;
+
+	/* copy iftypeoptions to confirm message buffer */
+	/* struct aepp_iftypeopt undefined!! */
+        if(le_hdr->aepple_type == AEPP_PARAM_TYPE_IFOPT){
+                iftypeopt = (struct aepp_iftypeopt *) next_aepple;
+        }
+        memcpy(cnfp, iftypeopt, le_hdr->aepple_len);
+	cnfp += le_hdr->aepple_len;
+	next_aepple += le_hdr->aepple_len;
+	le_hdr = (struct aepple_hdr *)next_aepple;
+
+	/* copy ifrate to confirm message buffer */
+        if(le_hdr->aepple_type == AEPP_PARAM_TYPE_IFRATE){
+                ifrate = (struct aepp_ifrate *) next_aepple;
+        }
+        memcpy(cnfp, ifrate, le_hdr->aepple_len);
+	cnfp += le_hdr->aepple_len;
+	next_aepple += le_hdr->aepple_len;
+	le_hdr = (struct aepple_hdr *)next_aepple;
+
+	/* copy security to confirm message buffer */
+	/* struct aepp_security undefined!! */
+        if(le_hdr->aepple_type == AEPP_PARAM_TYPE_SECURITY){
+                security = (struct aepp_security *) next_aepple;
+        }
+        memcpy(cnfp, security, le_hdr->aepple_len);
+	cnfp += le_hdr->aepple_len;
+	next_aepple += le_hdr->aepple_len;
+	le_hdr = (struct aepple_hdr *)next_aepple;
+
+	/* copy condition to confirm message buffer */
+        if(le_hdr->aepple_type == AEPP_PARAM_TYPE_CONDITION){
+                condition = (struct aepp_condition *) next_aepple;
+        }
+        memcpy(cnfp, condition, le_hdr->aepple_len);
+	cnfp += le_hdr->aepple_len;
+	next_aepple += le_hdr->aepple_len;
+	le_hdr = (struct aepple_hdr *)next_aepple;
+
+	/* copy peer to confirm message buffer */
+        if(le_hdr->aepple_type == AEPP_PARAM_TYPE_PEER){
+                peer = (struct aepp_peer *) next_aepple;
+        }
+        memcpy(cnfp, peer, le_hdr->aepple_len);
+
+        
+        lies_aepp_set_hdr(cnf,AEPP_VERSION,AEPP_LAYER2,AEPP_CLASS_CNF,0,0,0,0,0,AEPP_TYPE_LINKSTATUS,0); /* dummy AEPP_CNF_ACK */
+#endif
+
+	return 0;
+}
+
+int 
+lies_l2_aepp_linkconnect_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+        struct aepp_hdr *rhdr = (struct aepp_hdr *)aepp_req;
+        struct aepp_hdr *chdr = (struct aepp_hdr *)aepp_cnf;
+        struct aepp_ifid *rifid, *cifid;
+        struct aepp_iftype *riftype,*ciftype;
+        int count;
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Set aepp ifid  */
+        rifid = (struct aepp_ifid *)(rhdr + 1);
+        cifid = (struct aepp_ifid *)(chdr + 1);
+        lies_aepp_set_ifid(cifid, rifid->aepple_arch, rifid->aepple_ifid);
+        count += cifid->aepple_len;
+
+        /* Set aepp iftype */
+        riftype = (struct aepp_iftype *)(rifid + 1);
+        ciftype = (struct aepp_iftype *)(cifid + 1);
+        lies_aepp_set_iftype(ciftype, riftype->aepple_iftype);
+        count += ciftype->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(chdr, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF
+                          , 0, AEPP_CNF_ACK, 0, rhdr->aepp_tgtype
+                          , rhdr->aepp_tgid, AEPP_TYPE_LINKCONNECT, count);
+
+        return 0;
+}
+
+int 
+lies_l2_aepp_linkdisconnect_confirm(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+        struct aepp_hdr *rhdr = (struct aepp_hdr *)aepp_req;
+        struct aepp_hdr *chdr = (struct aepp_hdr *)aepp_cnf;
+        struct aepp_ifid *rifid, *cifid;
+        struct aepp_iftype *riftype,*ciftype;
+        int count;
+
+        /* aepp payload length */
+        count = 0;
+
+        /* Set aepp ifid  */
+        rifid = (struct aepp_ifid *)(rhdr + 1);
+        cifid = (struct aepp_ifid *)(chdr + 1);
+        lies_aepp_set_ifid(cifid, rifid->aepple_arch, rifid->aepple_ifid);
+        count += cifid->aepple_len;
+
+        /* Set aepp iftype */
+        riftype = (struct aepp_iftype *)(rifid + 1);
+        ciftype = (struct aepp_iftype *)(cifid + 1);
+        lies_aepp_set_iftype(ciftype, riftype->aepple_iftype);
+        count += ciftype->aepple_len;
+
+        /* Set aepp header */
+        lies_aepp_set_hdr(chdr, AEPP_VERSION1, AEPP_LAYER2, AEPP_CLASS_CNF
+                          , 0, AEPP_CNF_ACK, 0, rhdr->aepp_tgtype
+                          , rhdr->aepp_tgid, AEPP_TYPE_LINKDISCONNECT, count);
+
+        return 0;
+}
+
+/* 
+ * AEPP input from device driver
+ * lookup aepp types to send indication
+ */
+int
+lies_l2_aepp_input(aepp)
+	void *aepp;
+{
+	struct aepp_hdr *hdr, *req_hdr, *ind_hdr;
+	struct lies_table_req *req;
+	char *aepp_ind;
+
+#if defined(linux) && defined(__KERNEL__)
+        printk(KERN_INFO "<%s>: AEPP is coming for INDICATON: Type %d.\n", __FUNCTION__, ((struct aepp_hdr *)aepp)->aepp_type);
+#else
+        printf("<%s>: AEPP is coming for INDICATON: Type %d.\n", __FUNCTION__, ((struct aepp_hdr *)aepp)->aepp_type);
+#endif
+
+	hdr = (struct aepp_hdr *)aepp;
+
+	/*
+	 * Search REQUEST table
+	 */
+	LIES_LIST_FOREACH(req, &lies_req_list, req_field) {
+		/*
+		 * Compare type field of each request
+		 */
+		req_hdr = (struct aepp_hdr *)req->req_request;
+		if (hdr->aepp_type != req_hdr->aepp_type)
+			continue;
+
+		/*
+		 * Then, allocate memory for each INDICATION
+		 */
+#if defined(linux) && defined(__KERNEL__)
+		aepp_ind = kmalloc(AEPP_MAXSIZE, GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+		aepp_ind = malloc(AEPP_MAXSIZE, M_TEMP, M_NOWAIT);
+#else
+		aepp_ind = malloc(AEPP_MAXSIZE);
+#endif
+
+		/*
+		 * Copy aepp to each INDICATION
+		 * Append Target Type and Target ID
+		 */
+		ind_hdr = (struct aepp_hdr *)aepp_ind;
+		memcpy(ind_hdr, hdr, hdr->aepp_len + AEPP_HDRSIZE);	/* XXX right? */
+		ind_hdr->aepp_tgtype = req_hdr->aepp_tgtype;
+		ind_hdr->aepp_tgid = req_hdr->aepp_tgid;
+
+		/*
+		 * Call Preparing functions before sending each INDICATION
+		 */
+		switch(hdr->aepp_type){
+		case AEPP_TYPE_PEERFOUND:
+			lies_l2_aepp_peerfound_indication(aepp_ind);
+			break;
+		case AEPP_TYPE_PEERLOST:
+			lies_l2_aepp_peerlost_indication(aepp_ind);
+			break;
+		case AEPP_TYPE_LINKUP:
+			lies_l2_aepp_linkup_indication(aepp_ind);
+			break;
+		case AEPP_TYPE_LINKDOWN:
+			lies_l2_aepp_linkdown_indication(aepp_ind);
+			break;
+		case AEPP_TYPE_LINKTOBEDOWN:
+			lies_l2_aepp_linktobedown_indication(aepp_ind);
+			break;
+		}
+
+		/*
+		 * Free each INDICATION
+		 */
+#if defined(linux) && defined(__KERNEL__)
+		kfree(aepp_ind);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+		/* XXX free aepp_ind in lies_remove_liesbuf() in kqueue_scan().
+		  free(aepp_ind, M_TEMP);
+		*/
+#else
+		free(aepp_ind);
+#endif
+	}
+
+	return 0;
+}
+
+/* Prepare PeerFound Indication */
+int
+lies_l2_aepp_peerfound_indication(aepp_ind)
+	void *aepp_ind;
+{
+	/*
+	 * Send INDICATION
+	 */
+	lies_l2_aepp_indication(aepp_ind);
+
+	return 0;
+}
+
+/* Prepare PeerLost Indication */
+int
+lies_l2_aepp_peerlost_indication(aepp_ind)
+	void *aepp_ind;
+{
+	/*
+	 * Send INDICATION
+	 */
+	lies_l2_aepp_indication(aepp_ind);
+
+	return 0;
+}
+
+/* Prepare LinkUp Indication */
+int
+lies_l2_aepp_linkup_indication(aepp_ind)
+	void *aepp_ind;
+{
+	/*
+	 * Send INDICATION
+	 */
+	lies_l2_aepp_indication(aepp_ind);
+
+	return 0;
+}
+
+/* Prepare LinkDown Indication */
+int
+lies_l2_aepp_linkdown_indication(aepp_ind)
+	void *aepp_ind;
+{
+	/*
+	 * Send INDICATION
+	 */
+	lies_l2_aepp_indication(aepp_ind);
+
+	return 0;
+}
+
+/* Prepare LinkToBeDown Indication */
+int
+lies_l2_aepp_linktobedown_indication(aepp_ind)
+	void *aepp_ind;
+{
+	/*
+	 * Send INDICATION
+	 */
+	lies_l2_aepp_indication(aepp_ind);
+
+	return 0;
+}
+
+/* Send All Types of INDICATIONs to OS dependent code */
+int
+lies_l2_aepp_indication(aepp_ind)
+	void *aepp_ind;
+{
+	struct aepp_hdr *aepp_hdr;
+
+#if defined(linux) && defined(__KERNEL__)
+	printk(KERN_INFO "<%s>: Send INDICATION: Type %d.\n", __FUNCTION__, ((struct aepp_hdr *)aepp_ind)->aepp_type);
+#else
+	printf("<%s>: Send INDICATION: Type %d.\n", __FUNCTION__, ((struct aepp_hdr *)aepp_ind)->aepp_type);
+#endif
+
+	aepp_hdr = (struct aepp_hdr *)aepp_ind;
+	if(aepp_hdr->aepp_tgtype == AEPP_TGTYPE_USERLAND_PROCESS){/* indicate to userland */
+		/*
+		 * Now, call OS dependent functions here!
+		 */
+#if defined(linux) && defined(__KERNEL__)
+		/* XXX */
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+		lies_add_liesbuf(aepp_ind);
+		KNOTE_UNLOCKED(&lies_sel.si_note, NOTE_LIES);
+#else
+		/* XXX */
+#endif
+	}
+	else if(aepp_hdr->aepp_tgtype == AEPP_TGTYPE_KERNEL_FUNCTION){/* indicate to kernel */
+		void (*func)(void *);
+		func = (void *)aepp_hdr->aepp_tgid;
+		(*func)(aepp_ind); /* pass aepp_ind to tgid function in kernel*/
+	}
+
+	return 0;
+}
+
+/* Register request reqtype to each device */
+int
+lies_l2_register_reqtype(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+	struct aepp_hdr *hdr;
+	struct aepp_ifid *ifid;
+	struct aepp_iftype *iftype;
+
+	hdr = (struct aepp_hdr *)aepp_req;
+	
+	ifid = (struct aepp_ifid *)(hdr + 1);
+	iftype = (struct aepp_iftype *)(ifid + 1);
+
+
+	if(iftype->aepple_iftype == AEPP_PARAM_IF_EMULATOR){
+		lies_register_ether_reqtype(hdr);
+	}
+	else if(iftype->aepple_iftype == AEPP_PARAM_IF_ETHER){
+		/* YU-SEN */
+		//lies_register_ether_reqtype(hdr);
+	}
+#ifdef LIES_80211
+	else if(iftype->aepple_iftype == AEPP_PARAM_IF_IEEE80211){
+		/* MU-SEN */	
+		lies_register_80211_reqtype(hdr);
+	}
+#endif
+	return 0;
+}
+
+/* Register reqtype */
+int
+lies_register_ether_reqtype(req)
+	struct aepp_hdr *req;
+{ 
+	/* goto emulator's device and regist reqtype */
+	u_int type;
+	type = req->aepp_type;
+	lies_regist_threshold(type);
+	/* warning: initialize lies_threshold before add to the list! */
+      	return 0;
+}
+
+#ifdef LIES_80211
+int
+lies_register_80211_reqtype(req)
+	struct aepp_hdr *req;
+{
+	lies_80211_register_request(req);
+	return 0;
+}
+#endif
+
+/* Register Request to Request-Table */
+int
+lies_l2_register_request(aepp_req, aepp_cnf)
+	void *aepp_req;
+	void *aepp_cnf;
+{
+	struct lies_table_req *table_req;
+	
+	table_req = lies_make_table_req(aepp_req);
+	LIES_LIST_INSERT_HEAD(&lies_req_list, table_req, req_field);
+
+	return 0;
+}
+
+/* Make 1 Table of Request-Table */
+struct lies_table_req *
+lies_make_table_req(aepp)
+	void *aepp;
+{
+	static u_int reqid;	
+	struct lies_table_req *tablereq;
+
+#if defined(linux) && defined(__KERNEL__)
+	tablereq = (struct lies_table_req *) kmalloc(sizeof(struct lies_table_req), GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+	tablereq = (struct lies_table_req *) malloc(sizeof(struct lies_table_req), M_TEMP, M_NOWAIT);
+#else
+	tablereq = (struct lies_table_req *) malloc(sizeof(struct lies_table_req));
+#endif
+	
+	reqid++;
+	tablereq->req_id = reqid;
+
+#if defined(linux) && defined(__KERNEL__)
+        tablereq->req_request = (char *) kmalloc(AEPP_MAXSIZE, GFP_KERNEL);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+        tablereq->req_request = (char *) malloc(AEPP_MAXSIZE, M_TEMP, M_NOWAIT);
+#else
+        tablereq->req_request = (char *) malloc(AEPP_MAXSIZE);
+#endif
+	
+        memcpy(tablereq->req_request, aepp, AEPP_MAXSIZE);
+	
+	return tablereq;
+}
+
+/* initialize lies_req_list */
+int
+lies_initialize_req_list(void)
+{
+	struct lies_table_req *req_head;
+
+	req_head = LIES_LIST_FIRST(&lies_req_list);
+
+	while(req_head != NULL) {
+		LIES_LIST_REMOVE(req_head, req_field);
+		req_head = LIES_LIST_FIRST(&lies_req_list);
+	}
+
+	LIES_LIST_INIT(&lies_req_list);
+
+	return 0;
+}
+
+
+#endif /* LIES */
diff -u -r -N kame/kame/sys/lies/lies_l2.h kame-lies/kame/sys/lies/lies_l2.h
--- kame/kame/sys/lies/lies_l2.h	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_l2.h	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,96 @@
+#ifndef _LIES_LIES_L2_H_
+#define _LIES_LIES_L2_H_
+
+#ifdef LIESTEST
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include "lies_list.h"
+
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include <lies/lies_list.h>
+
+#elif defined(linux) 
+
+#include "lies_list.h"
+#ifdef __KERNEL__
+#include <linux/param.h>
+#include <linux/time.h>
+#else
+#include <sys/param.h>
+#include <sys/time.h>
+
+#endif /* __KERNEL__ */
+
+#endif
+
+/* definition to initialize each LIES_LIST */
+#define LIST_REQUEST   0x01
+#define LIST_PEER      0x02
+#define LIST_NEW_PEER  0x03
+#define LIST_CHANGE    0x04
+#define LIST_PEERFOUND 0x05
+#define LIST_PEERLOST  0x06
+#define LIST_THRESHOLD 0x07
+
+struct lies_table_req{
+	u_int    req_id;
+	u_char   *req_request;
+	LIES_LIST_ENTRY(lies_table_req)  req_field;
+};
+
+struct lies_table_peer{
+	struct timeval  peer_time;
+	u_int    peer_addr:16;
+	u_int    peer_qual:16; 
+	LIES_LIST_ENTRY(lies_table_peer) peer_field;
+};
+
+struct lies_table_new_peer{
+	struct timeval  peer_time;
+	u_int    peer_addr:16;
+	u_int    peer_qual:16; 
+	LIES_LIST_ENTRY(lies_table_new_peer) new_peer_field;
+};
+
+struct lies_table_peer_change{
+	u_int    peer_addr:16;
+	u_int    peer_qual_before:16;
+	u_int    peer_qual_after:16;
+        LIES_LIST_ENTRY(lies_table_peer_change) peer_change_field;
+}; 
+
+struct lies_table_threshold{
+	/* PeerFound/PeerLost/Linkup/Linkdown/Linktobedown: /
+	/    0x02   /  0x03  / 0x04 /  0x05  /   0x06      */
+	u_int    pri_type:16;
+	//struct aepp_threshold *threshold;
+	LIES_LIST_ENTRY(lies_table_threshold) threshold_field; 
+};
+
+struct lies_table_peerfound{
+	int peer_addr;
+	LIES_LIST_ENTRY(lies_table_peerfound) peerfound_field;
+};
+
+struct lies_table_peerlost{
+	int peer_addr;
+	LIES_LIST_ENTRY(lies_table_peerlost) peerlost_field;
+};
+
+int lies_l2_dispatcher(void *, void *);
+int lies_l2_aepp_input(void *);
+int lies_regist_threshold(u_int type);
+int lies_remove_threshold(u_int type);
+void *lies_emu_pipem_input(void *);
+int lies_emu_send_linkconnect(void *);
+int lies_emu_send_linkdisconnect(void *);
+char *  lies_get_emu_peerlist(void);
+int lies_initialize_lists(int list_type);
+int lies_initialize_req_list(void);
+
+#endif
diff -u -r -N kame/kame/sys/lies/lies_list.h kame-lies/kame/sys/lies/lies_list.h
--- kame/kame/sys/lies/lies_list.h	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_list.h	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,79 @@
+#ifndef _LIES_LIES_LIST_H_
+#define _LIES_LIES_LIST_H_
+
+/*#include <sys/cdefs.h>*/
+#if defined(linux) && defined(__KERNEL__)
+
+#include <linux/types.h>
+#else
+#include <sys/types.h>
+
+#endif
+
+/*
+ * List declarations.
+ */
+#define	LIES_LIST_HEAD(name, type)						\
+struct name {								\
+	struct type *lh_first;	/* first element */			\
+}
+
+#define	LIES_LIST_HEAD_INITIALIZER(head)					\
+	{ NULL }
+
+#define	LIES_LIST_ENTRY(type)						\
+struct {								\
+	struct type *le_next;	/* next element */			\
+	struct type **le_prev;	/* address of previous next element */	\
+}
+
+/*
+ * LIES List functions.
+ */
+
+#define	LIES_LIST_EMPTY(head)	((head)->lh_first == NULL)
+
+#define	LIES_LIST_FIRST(head)	((head)->lh_first)
+
+#define	LIES_LIST_FOREACH(var, head, field)					\
+	for ((var) = LIES_LIST_FIRST((head));				\
+	    (var);							\
+	    (var) = LIES_LIST_NEXT((var), field))
+
+#define	LIES_LIST_INIT(head) do {						\
+	LIES_LIST_FIRST((head)) = NULL;					\
+} while (0)
+
+#define	LIES_LIST_INSERT_AFTER(listelm, elm, field) do {			\
+	if ((LIES_LIST_NEXT((elm), field) = LIES_LIST_NEXT((listelm), field)) != NULL)\
+		LIES_LIST_NEXT((listelm), field)->field.le_prev =		\
+		    &LIES_LIST_NEXT((elm), field);				\
+	LIES_LIST_NEXT((listelm), field) = (elm);				\
+	(elm)->field.le_prev = &LIES_LIST_NEXT((listelm), field);		\
+} while (0)
+
+#define	LIES_LIST_INSERT_BEFORE(listelm, elm, field) do {			\
+	(elm)->field.le_prev = (listelm)->field.le_prev;		\
+	LIES_LIST_NEXT((elm), field) = (listelm);				\
+	*(listelm)->field.le_prev = (elm);				\
+	(listelm)->field.le_prev = &LIES_LIST_NEXT((elm), field);		\
+} while (0)
+
+#define	LIES_LIST_INSERT_HEAD(head, elm, field) do {				\
+	if ((LIES_LIST_NEXT((elm), field) = LIES_LIST_FIRST((head))) != NULL)	\
+		LIES_LIST_FIRST((head))->field.le_prev = &LIES_LIST_NEXT((elm), field);\
+	LIES_LIST_FIRST((head)) = (elm);					\
+	(elm)->field.le_prev = &LIES_LIST_FIRST((head));			\
+} while (0)
+
+#define	LIES_LIST_NEXT(elm, field)	((elm)->field.le_next)
+
+#define	LIES_LIST_REMOVE(elm, field) do {					\
+	if (LIES_LIST_NEXT((elm), field) != NULL)				\
+		LIES_LIST_NEXT((elm), field)->field.le_prev = 		\
+		    (elm)->field.le_prev;				\
+	*(elm)->field.le_prev = LIES_LIST_NEXT((elm), field);		\
+} while (0)
+
+
+#endif
diff -u -r -N kame/kame/sys/lies/lies_pipem.c kame-lies/kame/sys/lies/lies_pipem.c
--- kame/kame/sys/lies/lies_pipem.c	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_pipem.c	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,173 @@
+#ifdef LIESTEST
+
+#include <string.h>
+#include "lies_pipem.h"
+
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+
+#include "opt_lies.h"
+#include <sys/param.h>
+#include <lies/lies_pipem.h>
+
+#elif defined(linux)
+
+#include "lies_pipem.h"
+#ifdef __KERNEL__
+#include <linux/param.h>
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/slab.h>
+#else
+#include <sys/param.h>
+
+#endif /* __KERNEL__ */
+
+#endif
+
+#ifdef LIES
+int
+lies_pipem_set_hdr(pointer, ver, len)
+	void *pointer;
+	u_int ver;
+	u_int16_t len;
+{
+	struct pipem_hdr *p = (struct pipem_hdr *)pointer;
+	if(pointer == NULL) {
+		return -1;
+	}
+
+	p->pipem_ver = ver;
+	p->pipem_len = len;
+
+	return 0;
+}
+
+
+int
+lies_pipem_set_peerinfo(pointer, addr, qual)
+	void *pointer;
+	u_int16_t addr;
+	u_int16_t qual;
+{
+	struct pipem_peerinfo *p = (struct pipem_peerinfo *)pointer;
+	if(pointer == NULL) {
+		return -1;
+	}
+
+	p->pipemle_type = PIPEM_PEERINFO;
+	p->pipemle_len = sizeof(struct pipem_peerinfo);
+	p->pipemle_addr = addr;
+	p->pipemle_qual = qual;
+
+	return 0;
+}
+
+
+int
+lies_pipem_set_connectreq(pointer, addr)
+	void *pointer;
+	u_int16_t addr;
+{
+	struct pipem_connectreq *p = (struct pipem_connectreq *)pointer;
+	if(pointer == NULL) {
+		return -1;
+	}
+
+	p->pipemle_type = PIPEM_CONNECTREQ;
+	p->pipemle_len = sizeof(struct pipem_connectreq);
+	p->pipemle_addr = addr;
+
+	return 0;
+}
+
+
+int
+lies_pipem_set_disconnectreq(pointer, addr)
+	void *pointer;
+	u_int16_t addr;
+{
+	struct pipem_disconnectreq *p = (struct pipem_disconnectreq *)pointer;
+	if(pointer == NULL) {
+		return -1;
+	}
+
+	p->pipemle_type = PIPEM_DISCONNECTREQ;
+	p->pipemle_len = sizeof(struct pipem_disconnectreq);
+	p->pipemle_addr = addr;
+
+	return 0;
+}
+
+
+int
+lies_pipem_set_connectinfo(pointer, addr)
+	void *pointer;
+	u_int16_t addr;
+{
+	struct pipem_connectinfo *p = (struct pipem_connectinfo *)pointer;
+	if(pointer == NULL) {
+		return -1;
+	}
+
+	p->pipemle_type = PIPEM_CONNECTINFO;
+	p->pipemle_len = sizeof(struct pipem_connectinfo);
+	p->pipemle_addr = addr;
+
+	return 0;
+}
+
+
+int
+lies_pipem_set_disconnectinfo(pointer, addr)
+	void *pointer;
+	u_int16_t addr;
+{
+	struct pipem_disconnectinfo *p = (struct pipem_disconnectinfo *)pointer;
+	if(pointer == NULL) {
+		return -1;
+	}
+
+	p->pipemle_type = PIPEM_DISCONNECTINFO;
+	p->pipemle_len = sizeof(struct pipem_disconnectinfo);
+	p->pipemle_addr = addr;
+
+	return 0;
+}
+
+
+int
+lies_pipem_set_syncinfo(pointer, addr)
+	void *pointer;
+	u_int16_t addr;
+{
+	struct pipem_syncinfo *p = (struct pipem_syncinfo *)pointer;
+	if(pointer == NULL) {
+		return -1;
+	}
+
+	p->pipemle_type = PIPEM_SYNCINFO;
+	p->pipemle_len = sizeof(struct pipem_syncinfo);
+	p->pipemle_addr = addr;
+
+	return 0;
+}
+
+
+int
+lies_pipem_set_scanreq(pointer, addr)
+	void *pointer;
+	u_int16_t addr;
+{
+	struct pipem_scanreq *p = (struct pipem_scanreq *)pointer;
+	if(pointer == NULL) {
+		return -1;
+	}
+
+	p->pipemle_type = PIPEM_SCANREQ;
+	p->pipemle_len = sizeof(struct pipem_scanreq);
+	p->pipemle_addr = addr;
+
+	return 0;
+}
+
+#endif /* LIES */
diff -u -r -N kame/kame/sys/lies/lies_pipem.h kame-lies/kame/sys/lies/lies_pipem.h
--- kame/kame/sys/lies/lies_pipem.h	Thu Jan  1 09:00:00 1970
+++ kame-lies/kame/sys/lies/lies_pipem.h	Thu Jul 28 23:16:40 2005
@@ -0,0 +1,112 @@
+#ifndef _LIES_LIES_PIPEM_H_
+#define _LIES_LIES_PIPEM_H_
+
+/*
+ * Physical Information Packet
+ * for Wireless Environment Emulator
+ */
+
+#if defined(linux) && defined(__KERNEL__)
+
+#include <linux/types.h>
+
+#else
+
+#include <sys/types.h>
+
+#endif
+
+#define PIPEM_VERSION		0x2000
+
+#define PIPEM_VERSION1		0x1000
+#define PIPEM_VERSION2		0x2000
+
+#define PIPEM_PEERINFO		0x0001
+#define PIPEM_CONNECTREQ       	0x0002
+#define PIPEM_DISCONNECTREQ	0x0003
+#define PIPEM_CONNECTINFO	0x0004
+#define PIPEM_DISCONNECTINFO	0x0005
+#define PIPEM_SYNCINFO		0x0006
+#define PIPEM_SCANREQ		0x0007
+
+#define PIPEM_HDRSIZE		4
+#define PIPEM_MAXSIZE		1500
+
+#if 0
+struct pipem_hdr{
+	union{
+		u_int pipem_un1_ver:4;
+		u_int pipem_un2_res:16;
+	}pipem_verun;
+	u_int pipem_len:16;
+};
+#define pipem_ver pipem_verun.pipem_un1_ver
+#define pipem_res pipem_verun.pipem_un2_res
+#endif /* union allocates 32bits for version and reserved fields */
+
+struct pipem_hdr{
+	u_int pipem_verres:16;
+	u_int pipem_len:16;
+};
+#define pipem_ver pipem_verres
+#define pipem_res pipem_verres
+
+struct pipemle_hdr{
+	u_int pipemle_type:16;
+	u_int pipemle_len:16;
+};
+
+struct pipem_peerinfo{
+	u_int pipemle_type:16;
+	u_int pipemle_len:16;
+	u_int pipemle_addr:16;
+	u_int pipemle_qual:16;
+};
+
+struct pipem_connectreq{
+	u_int pipemle_type:16;
+	u_int pipemle_len:16;
+	u_int pipemle_addr:16;
+};
+
+struct pipem_disconnectreq{
+	u_int pipemle_type:16;
+	u_int pipemle_len:16;
+	u_int pipemle_addr:16;
+};
+
+struct pipem_connectinfo{
+	u_int pipemle_type:16;
+	u_int pipemle_len:16;
+	u_int pipemle_addr:16;
+};
+
+struct pipem_disconnectinfo{
+	u_int pipemle_type:16;
+	u_int pipemle_len:16;
+	u_int pipemle_addr:16;
+};
+
+struct pipem_syncinfo{
+	u_int pipemle_type:16;
+	u_int pipemle_len:16;
+	u_int pipemle_addr:16;
+};
+
+struct pipem_scanreq{
+	u_int pipemle_type:16;
+	u_int pipemle_len:16;
+	u_int pipemle_addr:16;
+};
+
+
+int lies_pipem_set_hdr(void *, u_int, u_int16_t);
+int 