gramdparent with temporary custody to expire needs to know what I have to do to get legal custody
See a lawyer who handles this kind of case. It is not something to handle through an internet forum (in any case, much less with zero facts).
I can't tell without looking at the documents and the history if the situation. Consult with a local attorney.