Cross-Layer Optimization for Off-Network Public Safety Communications in 4G LTE and 5G NR