You might want to consider writing a pluggable authentication module (PAM) that you can use with OpenWRT. From the Wikipedia article linked above, you can see:
A pluggable authentication module (PAM) is a mechanism to integrate multiple low-level authentication schemes into a high-level application programming interface (API). It allows programs that rely ...
Can you give me brief idea where do I start
Start with understanding sockets and studying other protocols. Some of the resources I can redirect you to are: