[RESEND 2 PATCH 01/13] gprs: factor out common code