How to correctly create a LoraWan packet

Hi Guys !
I am currently working on a project and I am using the Radiohead library for my end nodes because it provides routing functions so a node can relay a message to the Gateway.
because the Radiohead Library does not create LoraWan packets I would like to know if it is possible to create the packet directly on the gateway ?
I know it is less secure and not LoraWan compliant.
Did anyone know how to build a Lorawan packet like this one in C ?
MacHeader[1] | DevAddr[4] | FCtrl[1] | FCnt[2] | FPort[1] | Payload | MIC[4]
Especially how to generate the MIC.
To keep it simple I would like to use APB for authentification with the Network Server.

refer to developer docs, regarding your endnode controller. in many cases all the controllers has a software development tools with examples.

No. gateways only translate the LoRaWAN radio frames to IP.

You might be able to lift most of the code from one of the many device implementations that are written in C. The tricky part will be working out why the MIC is being rejected if you have made a mistake somewhere.

The spec doesn’t come with any worked examples to verify against. I have a few test inputs you might find useful here.

Thank you guys !
I found what I was looking for to compute MIC here: