So what are some possible ways to prevent friendly fire?
There is no substitute for good organization, training and leadership. IFF transponders have existed for decades, and yet "blue on blue" (and its various non-NATO counterparts) incidents persist.
Even where super advanced high-tech cryptographically secured IFF systems exist, the transponders still get turned off in various circumstances, and the interrogation systems may not always be used all the time in all locations.
- Emitting an IFF query reveals your location.
- The nature of the IFF query signal may reveal to an intruder that they have been spotted, which may in turn prevent them from revealing their intentions or from being intercepted.
- Emitting an IFF response signal reveals your location. Perfect pinpoint non-back-scattering tight-beam communications are basically impractical in the real world.
- You cannot guarantee that an IFF signal (query or response) has not been spoofed by an enemy.
- An IFF system, emitter or receiver, may have been damaged and unable to function.
- IFF signals, either queries or responses, may be rendered unintelligible by various kinds of electronic countermeasures or environmental conditions.
And so on.
There are enough reasons why IFF can't or won't be used under various circumstances, that you have to train and plan for the eventuality that it isn't available. Gating all firing decisions behind an IFF challenge-response is very risky, and will likely end up getting people killed when their smart-guns suddenly refuse to fire, or everyone just lights up with a big "shoot here!" radio beacon due to a software exploit.
(also, you're probably all gonna get murdered by automated weapon systems and drones using passive thermal and audio and chemical sensors, because the battlefield is no place for things which move, act and react with the speed of a meat glacier, but that's a different topic)