-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Netlink communication for Haskell
--
-- Library to comminicate with Linux kernel via Netlink
@package netlink
@version 1.0.0.4
module System.Linux.Netlink.Helpers
-- | Indent a String by 2 " "s for output
indent :: String -> String
-- | Put Word8
p8 :: Word8 -> Put
-- | Put Word16
p16 :: Word16 -> Put
-- | Put Word32
p32 :: Word32 -> Put
-- | Put Word64
p64 :: Word64 -> Put
-- | Get Word8
g8 :: Get Word8
-- | Get Word16
g16 :: Get Word16
-- | Get Word32
g32 :: Get Word32
-- | Get Word64
g64 :: Get Word64
module System.Linux.Netlink.Route.LinkStat
-- | Data Structure for rtnl link stats
data LinkStat
-- | Get a LinkStat object from a 64bit C struct
getLinkStat64 :: Get LinkStat
-- | Put a LinkStat object into a 64bit C struct
putLinkStat64 :: LinkStat -> Put
-- | Get a LinkStat object from a 32bit C struct
getLinkStat32 :: Get LinkStat
-- | Put a LinkStat object into a 32bit C struct
putLinkStat32 :: LinkStat -> Put
instance GHC.Show.Show System.Linux.Netlink.Route.LinkStat.LinkStat
instance GHC.Classes.Eq System.Linux.Netlink.Route.LinkStat.LinkStat
-- | This is the base module for the netlink package. It contains functions
-- and datatype used by every netlink module. All definitions are
-- (supposed to be) generic enough to be used by implementations of more
-- specific netlink interfaces.
module System.Linux.Netlink
-- | Data type for the netlink header
data Header
Header :: MessageType -> Word16 -> Word32 -> Word32 -> Header
-- | The message type
[messageType] :: Header -> MessageType
-- | The message flags
[messageFlags] :: Header -> Word16
-- | The sequence message number
[messageSeqNum] :: Header -> Word32
-- | The pid of the sending process (0 is from kernel for receiving or "let
-- the kernel set it" for sending)
[messagePID] :: Header -> Word32
-- | Type used for netlink attributes
type Attributes = Map Int ByteString
-- | The generic netlink message type
data Packet a
Packet :: Header -> a -> Attributes -> Packet a
-- | The netlink message header
[packetHeader] :: Packet a -> Header
-- | The datatype for additional static data for the interface
[packetCustom] :: Packet a -> a
-- | The netlink attributes
[packetAttributes] :: Packet a -> Attributes
ErrorMsg :: Header -> CInt -> Packet a -> Packet a
-- | The netlink message header
[packetHeader] :: Packet a -> Header
-- | The error ID for this error message
[packetError] :: Packet a -> CInt
-- | The offending message
[errorPacket] :: Packet a -> Packet a
DoneMsg :: Header -> Packet a
-- | The netlink message header
[packetHeader] :: Packet a -> Header
-- | Typeclase used by the system. Basically Storable for
-- Get and Put
--
-- getGet Returns a Get function for the convertable.
--
-- The MessageType is passed so that the function can parse different
-- data structures based on the message type.
class Convertable a
getGet :: Convertable a => MessageType -> Get a
getPut :: Convertable a => a -> Put
-- | Datatype to be used when there is no additional static header
data NoData
NoData :: NoData
-- | Typesafe wrapper around a CInt (fd)
data NetlinkSocket
-- | Read packets from the buffer
getPacket :: ByteString -> Get a -> Either String [a]
-- | Get Attributes
getAttributes :: Get Attributes
-- | Get the netlink Header
getHeader :: Get (Int, Header)
-- | Put the netlink Header
putHeader :: Int -> Header -> Put
-- | Put a Map of Attributes
putAttributes :: Attributes -> Put
-- | Put a Packet so it can e sent
putPacket :: (Convertable a, Eq a, Show a) => Packet a -> [ByteString]
-- | Read all Packets from a buffer
--
-- The packets may have additional static data defined by the protocol.
getPackets :: (Convertable a, Eq a, Show a) => ByteString -> Either String [Packet a]
-- | Open and return a NetlinkSocket, for legacy reasons this opens
-- a route socket
makeSocket :: IO NetlinkSocket
-- | Open a NetlinkSocket. This is the generic function
makeSocketGeneric :: Int -> IO NetlinkSocket
-- | Get the raw Fd used for netlink communcation (this can be
-- plugged into eventing)
getNetlinkFd :: NetlinkSocket -> Fd
-- | Close a NetlinkSocket when it is no longer used
closeSocket :: NetlinkSocket -> IO ()
-- | Join a netlink multicast group
joinMulticastGroup :: NetlinkSocket -> Word32 -> IO ()
-- | Query data over netlink.
--
-- This sends a Packet over netlink and returns the answer. This
-- blocks in a safe foregin function until the other side replies.
query :: (Convertable a, Eq a, Show a) => NetlinkSocket -> Packet a -> IO [Packet a]
-- | The same as query but requires the answer to be a single
-- message
queryOne :: (Convertable a, Eq a, Show a) => NetlinkSocket -> Packet a -> IO (Packet a)
-- | Calls recvmsg once and returns all received messages
--
-- This should only be used outside of the package when reading multicast
-- messages.
--
-- The prototype of this function is unintuitive, but this cannot be
-- avoided without buffering in userspace with the netlink api.
recvOne :: (Convertable a, Eq a, Show a) => NetlinkSocket -> IO [Packet a]
-- | Convert generic NLAttrs into a string (# and hexdump)
showNLAttrs :: Attributes -> String
-- | Helper function to convert attributes into a string
showAttrs :: (Int -> String) -> Attributes -> String
-- | Helper function to generically show a single attribute
showAttr :: (Int -> String) -> (Int, ByteString) -> String
-- | Helperfunction for show instance of Packet and further
-- specializations
showPacket :: Show a => Packet a -> String
instance GHC.Classes.Eq a => GHC.Classes.Eq (System.Linux.Netlink.Packet a)
instance GHC.Classes.Eq System.Linux.Netlink.Header
instance GHC.Classes.Eq System.Linux.Netlink.NoData
instance GHC.Show.Show System.Linux.Netlink.NoData
instance System.Linux.Netlink.Convertable System.Linux.Netlink.NoData
instance GHC.Show.Show System.Linux.Netlink.Header
instance GHC.Show.Show a => GHC.Show.Show (System.Linux.Netlink.Packet a)
-- | This module provides wrappers for functionality provided by the
-- netlink route family
module System.Linux.Netlink.Route
-- | The generic netlink message type
data Packet a
-- | Typedef for route messages
type RoutePacket = Packet Message
-- | Get a route message or an error
getRoutePackets :: ByteString -> Either String [RoutePacket]
-- | The static data for route messages
data Message
NLinkMsg :: LinkType -> Word32 -> Word32 -> Message
[interfaceType] :: Message -> LinkType
[interfaceIndex] :: Message -> Word32
[interfaceFlags] :: Message -> Word32
NAddrMsg :: AddressFamily -> Word8 -> Word8 -> Word8 -> Word32 -> Message
[addrFamily] :: Message -> AddressFamily
[addrMaskLength] :: Message -> Word8
[addrFlags] :: Message -> Word8
[addrScope] :: Message -> Word8
[addrInterfaceIndex] :: Message -> Word32
-- | get L2 address from netlink attributes
getLinkAddress :: AttributeReader LinkAddress
-- | get L2 broadcast address from netlink attributes
getLinkBroadcast :: AttributeReader LinkAddress
-- | get interface name from netlink attributes
getLinkName :: AttributeReader String
-- | get mtu from netlink attributes
getLinkMTU :: AttributeReader Word32
-- | I actually have no idea what QDisc is
getLinkQDisc :: AttributeReader String
-- | I should look this up
getLinkTXQLen :: AttributeReader Word32
-- | set L2 address on netlink attributes
putLinkAddress :: AttributeWriter LinkAddress
-- | set L2 broadcast address on netlink attributes
putLinkBroadcast :: AttributeWriter LinkAddress
-- | set interface name on netlink attributes
putLinkName :: AttributeWriter String
-- | set mtu on netlink attributes
putLinkMTU :: AttributeWriter Word32
-- | I actually have no idea what QDisc is
putLinkQDisc :: AttributeWriter String
-- | I should look this up
putLinkTXQLen :: AttributeWriter Word32
instance GHC.Classes.Eq System.Linux.Netlink.Route.Message
instance GHC.Show.Show System.Linux.Netlink.Route.Message
instance System.Linux.Netlink.Convertable System.Linux.Netlink.Route.Message
instance GHC.Show.Show System.Linux.Netlink.Route.RoutePacket
-- | GeNetlink is used as multiplexer since netlink only supports 32
-- families.
--
-- This module provides the basic datatypes used by genetlink.
module System.Linux.Netlink.GeNetlink
-- | The static data used by genetlink
--
-- For more information about genetlink look into
-- usrincludelinuxgenetlink.h
data GenlHeader
GenlHeader :: Word8 -> Word8 -> GenlHeader
[genlCmd] :: GenlHeader -> Word8
[genlVersion] :: GenlHeader -> Word8
-- | The Convertable instance for GenlHeader
-- | A wrapper around GenlHeader
--
-- This may be used by actual implementations to handle additional static
-- data placed after the genl header by the protocol they implement.
data GenlData a
GenlData :: GenlHeader -> a -> GenlData a
[genlDataHeader] :: GenlData a -> GenlHeader
[genlDataData] :: GenlData a -> a
-- | The Convertable instance for GenlData
-- | Type declaration for genetlink packets
type GenlPacket a = Packet (GenlData a)
-- | Show isntance of GenlHeader
-- | Show instance of GenlData
-- | Show instance of GenlData for NoData
-- | Show Instance for GenlPacket
-- | Get function for GenlHeader
getGenlHeader :: Get GenlHeader
-- | Put function for GenlHeader
putGeHeader :: GenlHeader -> Put
-- | makeSocketGeneric preapplied for genetlink family
makeSocket :: IO NetlinkSocket
instance GHC.Classes.Eq a => GHC.Classes.Eq (System.Linux.Netlink.GeNetlink.GenlData a)
instance GHC.Classes.Eq System.Linux.Netlink.GeNetlink.GenlHeader
instance System.Linux.Netlink.Convertable System.Linux.Netlink.GeNetlink.GenlHeader
instance System.Linux.Netlink.Convertable a => System.Linux.Netlink.Convertable (System.Linux.Netlink.GeNetlink.GenlData a)
instance GHC.Show.Show System.Linux.Netlink.GeNetlink.GenlHeader
instance GHC.Show.Show a => GHC.Show.Show (System.Linux.Netlink.GeNetlink.GenlData a)
instance GHC.Show.Show (System.Linux.Netlink.GeNetlink.GenlData System.Linux.Netlink.NoData)
instance GHC.Show.Show a => GHC.Show.Show (System.Linux.Netlink.GeNetlink.GenlPacket a)
-- | This module provides utility functions and datatypes for the genetlink
-- control protocol. This has to be used by implementations of netlink
-- families based on genetlink to lookup their current id, since that is
-- determined at runtime.
module System.Linux.Netlink.GeNetlink.Control
-- | Attributes defined by the control family
data CtrlAttribute
CTRL_ATTR_UNSPEC :: ByteString -> CtrlAttribute
CTRL_ATTR_FAMILY_ID :: Word16 -> CtrlAttribute
CTRL_ATTR_FAMILY_NAME :: String -> CtrlAttribute
CTRL_ATTR_VERSION :: Word32 -> CtrlAttribute
CTRL_ATTR_HDRSIZE :: Word32 -> CtrlAttribute
CTRL_ATTR_MAXATTR :: Word32 -> CtrlAttribute
CTRL_ATTR_OPS :: [CtrlAttrOpData] -> CtrlAttribute
CTRL_ATTR_MCAST_GROUPS :: [CtrlAttrMcastGroup] -> CtrlAttribute
CTRL_ATTR_UNKNOWN :: Int -> ByteString -> CtrlAttribute
-- | Datatype for multicast groups as returned by the control protocol
data CtrlAttrMcastGroup
CAMG :: String -> Word32 -> CtrlAttrMcastGroup
[grpName] :: CtrlAttrMcastGroup -> String
[grpId] :: CtrlAttrMcastGroup -> Word32
-- | Typesafe control packet
data CtrlPacket
CtrlPacket :: Header -> GenlHeader -> [CtrlAttribute] -> CtrlPacket
[ctrlHeader] :: CtrlPacket -> Header
[ctrlGeHeader] :: CtrlPacket -> GenlHeader
[ctrlAttributes] :: CtrlPacket -> [CtrlAttribute]
-- | typedef for control messages
type CTRLPacket = GenlPacket NoData
-- | Convert "normal" Packets into typesafe CtrlPackets
ctrlPacketFromGenl :: CTRLPacket -> Maybe CtrlPacket
-- | Datatype for AttrOpData as returned by the control protocol
data CtrlAttrOpData
CAO :: Word32 -> Word32 -> CtrlAttrOpData
[opId] :: CtrlAttrOpData -> Word32
[opFlags] :: CtrlAttrOpData -> Word32
-- | Convert the typesafe CtrPacket into a CTRLPacket so it
-- can be sent
ctrlPackettoGenl :: CtrlPacket -> CTRLPacket
-- | Get the id for a netlink family by name
getFamilyId :: NetlinkSocket -> String -> IO Word16
-- | A safe version of getFamilyId
getFamilyIdS :: NetlinkSocket -> String -> IO (Maybe Word16)
-- | get the id and multicast groups of a netlink family by name
getFamilyWithMulticasts :: NetlinkSocket -> String -> IO (Word16, [CtrlAttrMcastGroup])
-- | A safe version of getFamilyWithMulticasts
getFamilyWithMulticastsS :: NetlinkSocket -> String -> IO (Maybe (Word16, [CtrlAttrMcastGroup]))
-- | get the mutlicast groups of a netlink family by id
getMulticastGroups :: NetlinkSocket -> Word16 -> IO [CtrlAttrMcastGroup]
-- | Get id of multicast group by name
getMulticast :: String -> [CtrlAttrMcastGroup] -> Maybe Word32
-- | Get the CtrlPacket describing a single family
getFamilie :: NetlinkSocket -> String -> IO (Maybe CtrlPacket)
-- | Get CtrlPackets for every currently registered GeNetlink family
getFamilies :: NetlinkSocket -> IO [CtrlPacket]
instance GHC.Classes.Eq System.Linux.Netlink.GeNetlink.Control.CtrlPacket
instance GHC.Show.Show System.Linux.Netlink.GeNetlink.Control.CtrlAttribute
instance GHC.Classes.Eq System.Linux.Netlink.GeNetlink.Control.CtrlAttribute
instance GHC.Show.Show System.Linux.Netlink.GeNetlink.Control.CtrlAttrOpData
instance GHC.Classes.Eq System.Linux.Netlink.GeNetlink.Control.CtrlAttrOpData
instance GHC.Show.Show System.Linux.Netlink.GeNetlink.Control.CtrlAttrMcastGroup
instance GHC.Classes.Eq System.Linux.Netlink.GeNetlink.Control.CtrlAttrMcastGroup
instance GHC.Show.Show System.Linux.Netlink.GeNetlink.Control.CtrlPacket
-- | This module providis utility functions for NL80211 subsystem. For more
-- information see usrincludelinuxnl80211.h
module System.Linux.Netlink.GeNetlink.NL80211
-- | Wrapper for NetlinkSocket we also need the family id for
-- messages we construct
data NL80211Socket
-- | typedef for messages send by this mdoule
type NL80211Packet = GenlPacket NoData80211
-- | Get the EID Attributes from a buffer
getWifiEIDs :: Get Attributes
-- | Create a NL80211Socket this opens a genetlink socket and gets
-- the family id
makeNL80211Socket :: IO NL80211Socket
-- | Join a nl80211 multicast group by name
joinMulticastByName :: NL80211Socket -> String -> IO ()
-- | queryOne for NL80211 (see queryOne)
queryOne :: NL80211Socket -> Word8 -> Bool -> Attributes -> IO NL80211Packet
-- | query for NL80211 (see query)
query :: NL80211Socket -> Word8 -> Bool -> Attributes -> IO [NL80211Packet]
-- | Get the list of interfaces currently managed by NL80211
getInterfaceList :: NL80211Socket -> IO [(String, Word32)]
-- | get scan results
--
-- In testing this could be a big chunk of data when a scan just happened
-- or be pretty much only the currently connected wifi.
--
-- For more information about how this is structured look into kernel
-- source or just try it out.
getScanResults :: NL80211Socket -> Word32 -> IO [NL80211Packet]
-- | Get the information about the currently connected wifi(s).
--
-- This would technically work for multiple connected wifis, but since we
-- only get information about one interface this should only ever be
-- emtpy on a singleton list.
--
-- For more information about how this is structured look into kernel
-- soruce or just try it out.
getConnectedWifi :: NL80211Socket -> Word32 -> IO [NL80211Packet]
-- | Get the EID attributes from a NL80211Packet (for example from
-- getConnectedWifi
getWifiAttributes :: NL80211Packet -> Maybe Attributes
-- | NL80211 version of recvOne
getPacket :: NL80211Socket -> IO [NL80211Packet]
-- | Get the raw fd from a NL80211Socket. This can be used for
-- eventing
getFd :: NL80211Socket -> Fd
-- | Get the names of all multicast groups this nl80211 implementation
-- provides
getMulticastGroups :: NL80211Socket -> IO [String]
instance GHC.Show.Show System.Linux.Netlink.GeNetlink.NL80211.NoData80211
instance GHC.Classes.Eq System.Linux.Netlink.GeNetlink.NL80211.NoData80211
instance System.Linux.Netlink.Convertable System.Linux.Netlink.GeNetlink.NL80211.NoData80211
instance GHC.Show.Show System.Linux.Netlink.GeNetlink.NL80211.NL80211Packet