Ejemplo n.º 1
0
func (self capture) GenlListen(msg nlgo.GenlMessage) {
	switch msg.Header.Type {
	case syscall.NLMSG_DONE:
		log.Print("Init DONE")
	case syscall.NLMSG_ERROR:
		log.Print(nlgo.NlMsgerr(msg.NetlinkMessage))
	default:
		if attrs, err := nlgo.Nl80211Policy.Parse(msg.Body()); err != nil {
			panic(err)
		} else {
			log.Printf("NL80211_CMD_%s attrs=%s", nlgo.NL80211_CMD_itoa[msg.Genl().Cmd], attrs)
		}
	}
}
Ejemplo n.º 2
0
func (self NamedPort) GenlListen(ev nlgo.GenlMessage) {
	if ev.Family.Name != "nl80211" {
		return
	}
	switch ev.Genl().Cmd {
	case nlgo.NL80211_CMD_FRAME:
		if attrs, err := nlgo.Nl80211Policy.Parse(ev.Body()); err != nil {
			log.Print(err)
		} else if frame, err := FrameFromNlAttr(attrs.(nlgo.AttrMap), self.mac, self.fragmentId); err != nil {
			log.Print(err)
		} else {
			self.ingress <- frame
			self.fragmentId++
		}
	case nlgo.NL80211_CMD_FRAME_TX_STATUS:
		var cookie uint64
		var ack bool

		if attrs, err := nlgo.Nl80211Policy.Parse(ev.Body()); err != nil {
			log.Print(err)
		} else if amap, ok := attrs.(nlgo.AttrMap); !ok {
			log.Print("nl80211 policy did not return attr map")
		} else {
			cookie = uint64(amap.Get(nlgo.NL80211_ATTR_COOKIE).(nlgo.U64))
			if value := amap.Get(nlgo.NL80211_ATTR_ACK); value != nil {
				ack = true
			}
		}
		func() {
			self.lock.Lock()
			defer self.lock.Unlock()

			if status, ok := self.txStatus[cookie]; ok {
				if !ack {
					status <- fmt.Errorf("NL80211_ATTR_ACK missing")
				}
				close(status)
				delete(self.txStatus, cookie)
			} else {
				log.Print("unhandled tx cookie")
			}
		}()
	}
}