Skip to content

Commit

Permalink
Merge pull request #1 from LiquidFenrir/fixrestore
Browse files Browse the repository at this point in the history
Huge rewrite, fix restoring
  • Loading branch information
LiquidFenrir authored Jul 6, 2017
2 parents 9812d80 + 4fa4f5b commit 0777811
Show file tree
Hide file tree
Showing 23 changed files with 661 additions and 128 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 LiquidFenrir

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
75 changes: 40 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ endif
TOPDIR ?= $(CURDIR)
include $(DEVKITARM)/3ds_rules

APP_TITLE := WifiManager
APP_DESCRIPTION := wifi slot saving/restore test
APP_AUTHOR := LiquidFenrir
APP_TITLE := WifiManager
APP_DESCRIPTION := Backup and restore your WiFi slots!
APP_AUTHOR := LiquidFenrir

ICON := icon.png
TARGET := $(notdir $(CURDIR))
OUTDIR := out
BUILD := build
SOURCES := source source/filebrowser
INCLUDES := include

PRODUCT_CODE := CTR-P-WIFI
UNIQUE_ID := 0x05DC9
ICON := icon.png
ICON_FLAGS := visible,nosavebackups

BANNER_AUDIO := audio.wav
BANNER_IMAGE := banner.png
BANNER_AUDIO := audio.wav
BANNER_IMAGE := banner.png

TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
#ROMFS := romfs
RSF_PATH := app.rsf
PRODUCT_CODE := CTR-P-WIFI
UNIQUE_ID := 0x05DC9

#---------------------------------------------------------------------------------
# options for code generation
Expand All @@ -37,7 +38,7 @@ CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
-fomit-frame-pointer -ffunction-sections \
$(ARCH)

CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE
CFLAGS += $(INCLUDE) -DARM11 -D_3DS

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11

Expand All @@ -60,7 +61,7 @@ LIBDIRS := $(CTRULIB)
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)
export OUTPUT := $(CURDIR)/$(OUTDIR)/$(TARGET)
export TOPDIR := $(CURDIR)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
Expand Down Expand Up @@ -113,39 +114,48 @@ else
endif

ifeq ($(strip $(NO_SMDH)),)
export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
export _3DSXFLAGS += --smdh=$(OUTPUT).smdh
endif

ifneq ($(ROMFS),)
export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
endif

.PHONY: $(BUILD) clean all 3dsx cia
.PHONY: $(BUILD) clean all

#---------------------------------------------------------------------------------
3dsx: $(BUILD) $(OUTPUT).3dsx

cia : $(BUILD) $(OUTPUT).cia

all: 3dsx cia
3dsx: $(BUILD)
cia : $(OUTPUT).cia

$(BUILD):
@[ -d $@ ] || mkdir -p $@
@mkdir -p $(OUTDIR)
@[ -d "$@" ] || mkdir -p "$@"
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf
@rm -fr $(BUILD) $(OUTDIR)

#---------------------------------------------------------------------------------

MAKEROM ?= makerom
ifeq ($(strip $(NO_SMDH)),)
$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh
else
$(OUTPUT).3dsx : $(OUTPUT).elf
endif

$(OUTPUT).cia: $(OUTPUT).elf $(BUILD)/banner.bnr $(BUILD)/icon.icn
$(MAKEROM) -f cia -o $@ -elf $< -rsf $(CURDIR)/app.rsf -target t -exefslogo -banner $(BUILD)/banner.bnr -icon $(BUILD)/icon.icn -DAPP_TITLE="$(APP_TITLE)" -DPRODUCT_CODE="$(PRODUCT_CODE)" -DUNIQUE_ID="$(UNIQUE_ID)"
MAKEROM ?= makerom

%.cia: $(OUTPUT).elf $(BUILD)/banner.bnr $(BUILD)/icon.icn
$(MAKEROM) -f cia -o "$@" -elf "$(OUTPUT).elf" -rsf "$(RSF_PATH)" -target t -exefslogo -banner "$(BUILD)/banner.bnr" -icon "$(BUILD)/icon.icn" -DAPP_TITLE="$(APP_TITLE)" -DAPP_PRODUCT_CODE="$(PRODUCT_CODE)" -DAPP_UNIQUE_ID="$(UNIQUE_ID)"

# Banner

BANNERTOOL ?= bannertool
BANNERTOOL ?= bannertool

ifeq ($(suffix $(BANNER_IMAGE)),.cgfx)
BANNER_IMAGE_ARG := -ci
Expand All @@ -159,11 +169,11 @@ else
BANNER_AUDIO_ARG := -a
endif

$(BUILD)/%.bnr: $(BANNER_IMAGE) $(BANNER_AUDIO)
$(BANNERTOOL) makebanner $(BANNER_IMAGE_ARG) $(BANNER_IMAGE) $(BANNER_AUDIO_ARG) $(BANNER_AUDIO) -o $@
$(BUILD)/%.bnr : $(BANNER_IMAGE) $(BANNER_AUDIO)
$(BANNERTOOL) makebanner $(BANNER_IMAGE_ARG) "$(BANNER_IMAGE)" $(BANNER_AUDIO_ARG) "$(BANNER_AUDIO)" -o "$@"

$(BUILD)/%.icn: $(ICON)
$(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i $(ICON) -f visible,nosavebackups -o $@
$(BUILD)/%.icn : $(ICON)
$(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i "$(ICON)" -f "$(ICON_FLAGS)" -o "$@"

#---------------------------------------------------------------------------------
else
Expand All @@ -173,11 +183,6 @@ DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
ifeq ($(strip $(NO_SMDH)),)
$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh
else
$(OUTPUT).3dsx : $(OUTPUT).elf
endif

$(OUTPUT).elf : $(OFILES)

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# WifiManager

WifiManager is a simple 3ds homebrew meant to help you backup and restore your console's WiFi slots.
It could prove useful if you travel a lot and need to connect to new wifi networks all the time, or if only 3 slots is really too few for you.

## CRC

WifiManager uses `include/checksum.h` and `src/crc16.c` from [libcrc 2.0](https://github.com/lammertb/libcrc/tree/v2.0) by lammertb, licensed under the MIT license, which were modified to remove the functions and data unused by this application.

# License

WifiManager is licensed under the MIT license, a copy of which can be found in the `LICENSE.txt` file.
3 changes: 1 addition & 2 deletions app.rsf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BasicInfo:
Logo : Homebrew

TitleInfo:
Category : $(APP_CATEGORY)
Category : Application
UniqueId : $(APP_UNIQUE_ID)

Option:
Expand Down Expand Up @@ -231,7 +231,6 @@ AccessControlInfo:
- news:s
- nwm::EXT
- nwm::UDS
- nwm::SOC
- ptm:sysm
- ptm:u
- pxi:dev
Expand Down
8 changes: 8 additions & 0 deletions source/basic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <3ds.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
23 changes: 23 additions & 0 deletions source/blocks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "blocks.h"
#include "checksum.h"

Result getWifiSlot(int selected_slot, wifiBlock * slotData)
{
Result ret = CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID+selected_slot, (u8*)slotData);
if (ret) printf("CFG_GetConfigInfoBlk8\nresult: 0x%.8lx\n", ret);
return ret;
}

Result setWifiSlot(int selected_slot, wifiBlock * slotData)
{
Result ret = CFG_SetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID+selected_slot, (u8*)slotData);
if (ret) printf("CFG_GetConfigInfoBlk8\nresult: 0x%.8lx\n", ret);
return ret;
}

void fixSlotCRC(wifiBlock * slotData)
{
printf("Previous CRC-16 checksum: %.4X\n", slotData->checksum);
slotData->checksum = crc_16((u8*)(&(slotData->network)), 0x410);
printf("New CRC-16 checksum: %.4X\n", slotData->checksum);
}
71 changes: 71 additions & 0 deletions source/blocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once

#include "basic.h"

#define CFG_WIFI_BLKID (u32 )0x00080000
#define CFG_WIFI_SLOTS 3
#define CFG_WIFI_SLOT_SIZE (u32 )0xC00

typedef struct {
bool exists;
bool use;
bool second;
u8 padding1;
char SSID[0x20];
u8 SSID_length;
u8 AP_encryption_type;
u16 padding2;
char password[0x40]; //plaintext, blank for a network set up with WPS
u8 passwordPSK[0x20];
} networkStruct;

typedef struct {
bool exists;
u8 padding1;
u16 checksum; //crc-16 of the next 0x410 bytes, with initval 0: https://github.com/lammertb/libcrc/blob/v2.0/src/crc16.c#L43-L76
//if the network is set "normally", 'use' is 1
//if the network is set by WPS, 'use' is 0
//'second' is 0
//if setting multiple networks with WPS in the same session, only the last set will have this. others will have completely 0x00 except for 'exists'
networkStruct network;
u8 padding2[0x20];
//completely 0x00 if the network was set "normally", otherwise (set by WPS) normal but 'use' and 'second' are 1
networkStruct network_WPS;
u8 padding3[0x20C];

bool auto_obtain_IP; //defaults to 1
bool auto_obtain_DNS; //defaults to 1
u16 padding4;

u8 IP_address[4];
u8 gateway_address[4];
u8 subnet_mask[4];

u8 primary_DNS[4];
u8 secondary_DNS[4];

// if setting multiple networks in the same session, only the last set will have these. others will have completely 0x00
u8 unk1[4];
u8 IP_to_use[4];
u8 MAC_address[6];
u8 channel;
u8 padding5;

bool use_proxy; //defaults to 0
bool basic_authentication; //defaults to 0
u16 port_number; //defaults to 1
char proxy_address[0x30]; //including ending nullbyte
u8 padding6[0x34];
char proxy_username[0x20]; //including ending nullbyte
char proxy_password[0x20]; //including ending nullbyte
u16 padding7;
u16 MTU_value; //defaults to 1400, range [576;1500]

//nothing beyond this point (0x414), but each slot is 0xC00 big...
u8 padding8[0x7EC];
} wifiBlock;

Result getWifiSlot(int selected_slot, wifiBlock * slotData);
Result setWifiSlot(int selected_slot, wifiBlock * slotData);

void fixSlotCRC(wifiBlock * slotData);
63 changes: 63 additions & 0 deletions source/checksum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Library: libcrc
* File: include/checksum.h
* Author: Lammert Bies
*
* This file is licensed under the MIT License as stated below
*
* Copyright (c) 1999-2016 Lammert Bies
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Description
* -----------
* The headerfile include/checksum.h contains the definitions and prototypes
* for routines that can be used to calculate several kinds of checksums.
*/

#ifndef DEF_LIBCRC_CHECKSUM_H
#define DEF_LIBCRC_CHECKSUM_H

#include <stdint.h>

/*
* #define CRC_POLY_xxxx
*
* The constants of the form CRC_POLY_xxxx define the polynomials for some well
* known CRC calculations.
*/

#define CRC_POLY_16 0xA001

/*
* #define CRC_START_xxxx
*
* The constants of the form CRC_START_xxxx define the values that are used for
* initialization of a CRC value for common used calculation methods.
*/

#define CRC_START_16 0x0000

/*
* Prototype list of global functions
*/

uint16_t crc_16( const unsigned char *input_str, size_t num_bytes );

#endif // DEF_LIBCRC_CHECKSUM_H
Loading

0 comments on commit 0777811

Please sign in to comment.