#!/usr/bin/python

"""
This script finds the offset that should be patched within the
firmware depending on the device variant:

Variant 1: PCMCIA card inside: the variant offset should be set to 0
           eg. WL215
Variant 2: Single board device: the variant offset should be set to 1
           eg. W200
"""

import sys, struct

fw = file(sys.argv[1]).read()

init_offset = struct.unpack(">H", fw[1:3])[0]
print "init offset: 0x%04X"%init_offset
jump2main_offset = fw.find("\x02\x03\x58", init_offset)
print "jump to main offset: 0x%04X"%jump2main_offset
print "variant offset: 0x%04X"%(jump2main_offset+3)
