#include "init.h"
#include "wallabylib.h"

extern char v514_wallaby_ident;
extern char v515_wallaby_ident;
extern char v517_wallaby_ident;
extern char v622_wallaby_ident;
extern char v515b_wallaby_ident;

/* Detect the Wallaby Bootloader version.
 * Currently this function is able to detect Wallaby versions 5.14 and 5.17, 5.15, 6.22
 * and 5.15[b] for t-mobile bootloader
 */
int detect_version() {
    wallaby_version = WALLABY_UNIDENT;
    if ( my_strcmp( &v514_wallaby_ident, REQUIRED_514_WALLABY_IDENT ) == 0 ) wallaby_version = WALLABY_514;
    else if ( my_strcmp( &v515_wallaby_ident, REQUIRED_515_WALLABY_IDENT ) == 0 ) wallaby_version = WALLABY_515;
    else if ( my_strcmp( &v517_wallaby_ident, REQUIRED_517_WALLABY_IDENT ) == 0 ) wallaby_version = WALLABY_517;
    else if ( my_strcmp( &v622_wallaby_ident, REQUIRED_622_WALLABY_IDENT ) == 0 ) wallaby_version = WALLABY_622;
    else if ( my_strcmp( &v515b_wallaby_ident, REQUIRED_515b_WALLABY_IDENT ) == 0 ) wallaby_version = WALLABY_515b;
    return wallaby_version;
}

/* Simple string compare. Compares s1 to s2 up to the length of s2
 * Returns 0 on equal, 1 otherwise.
 */
int my_strcmp( char *s1, char *s2 ) {
    while ( *s2 != 0 ) {
        if ( *s1 != *s2 ) return 1;
        s1++;
        s2++;
    };
    return 0;
}

